mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
create weekly view programmatically, do not hardcode 7
This commit is contained in:
parent
507719af7c
commit
888595b2ed
@ -61,6 +61,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private var allDayHolders = ArrayList<RelativeLayout>()
|
||||
private var allDayRows = ArrayList<HashSet<Int>>()
|
||||
private var currEvents = ArrayList<Event>()
|
||||
private var dayColumns = ArrayList<RelativeLayout>()
|
||||
private var eventTypeColors = LongSparseArray<Int>()
|
||||
private var eventTimeRanges = LinkedHashMap<String, ArrayList<EventWeeklyView>>()
|
||||
|
||||
@ -105,6 +106,13 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
}
|
||||
}
|
||||
|
||||
mView.week_events_columns_holder.removeAllViews()
|
||||
(0..context!!.config.weeklyViewDays).forEach {
|
||||
val column = inflater.inflate(R.layout.weekly_view_day_column, mView.week_events_columns_holder, false) as RelativeLayout
|
||||
mView.week_events_columns_holder.addView(column)
|
||||
dayColumns.add(column)
|
||||
}
|
||||
|
||||
scrollView.setOnScrollviewListener(object : MyScrollView.ScrollViewListener {
|
||||
override fun onScrollChanged(scrollView: MyScrollView, x: Int, y: Int, oldx: Int, oldy: Int) {
|
||||
checkScrollLimits(y)
|
||||
@ -203,7 +211,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
}
|
||||
|
||||
private fun initGrid() {
|
||||
(0..6).map { getColumnWithId(it) }
|
||||
(0..context!!.config.weeklyViewDays).map { dayColumns[it] }
|
||||
.forEachIndexed { index, layout ->
|
||||
layout.removeAllViews()
|
||||
val gestureDetector = getViewGestureDetector(layout, index)
|
||||
@ -365,7 +373,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
addAllDayEvent(event)
|
||||
} else {
|
||||
val dayOfWeek = startDateTime.plusDays(if (config.isSundayFirst) 1 else 0).dayOfWeek - 1
|
||||
val layout = getColumnWithId(dayOfWeek)
|
||||
val layout = dayColumns[dayOfWeek]
|
||||
|
||||
val startMinutes = startDateTime.minuteOfDay
|
||||
val duration = endDateTime.minuteOfDay - startMinutes
|
||||
@ -454,7 +462,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
private fun addCurrentTimeIndicator(minuteHeight: Float) {
|
||||
if (todayColumnIndex != -1) {
|
||||
val minutes = DateTime().minuteOfDay
|
||||
val todayColumn = getColumnWithId(todayColumnIndex)
|
||||
val todayColumn = dayColumns[todayColumnIndex]
|
||||
if (currentTimeView != null) {
|
||||
mView.week_events_holder.removeView(currentTimeView)
|
||||
}
|
||||
@ -548,9 +556,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
|
||||
allDayHolders[drawAtLine].addView(this)
|
||||
(layoutParams as RelativeLayout.LayoutParams).apply {
|
||||
leftMargin = getColumnWithId(firstDayIndex).x.toInt()
|
||||
leftMargin = dayColumns[firstDayIndex].x.toInt()
|
||||
bottomMargin = 1
|
||||
width = getColumnWithId(Math.min(firstDayIndex + daysCnt, 6)).right - leftMargin - 1
|
||||
width = dayColumns[Math.min(firstDayIndex + daysCnt, 6)].right - leftMargin - 1
|
||||
}
|
||||
|
||||
calculateExtraHeight()
|
||||
@ -579,8 +587,6 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getColumnWithId(id: Int) = mView.findViewById<ViewGroup>(res.getIdentifier("week_column_$id", "id", context!!.packageName))
|
||||
|
||||
fun updateScrollY(y: Int) {
|
||||
if (wasFragmentInit) {
|
||||
scrollView.scrollY = y
|
||||
|
@ -6,12 +6,13 @@ import android.graphics.Paint
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.getWeeklyViewItemHeight
|
||||
|
||||
class WeeklyViewGrid(context: Context, attrs: AttributeSet, defStyle: Int) : View(context, attrs, defStyle) {
|
||||
private val ROWS_CNT = 24
|
||||
private var paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
var daysCount = 7
|
||||
var daysCount = context.config.weeklyViewDays
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0)
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/week_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
@ -22,7 +21,7 @@
|
||||
<com.simplemobiletools.calendar.pro.views.WeeklyViewGrid
|
||||
android:id="@+id/week_horizontal_grid_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/week_events_columns_holder"
|
||||
@ -31,48 +30,6 @@
|
||||
android:background="@android:color/transparent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_0"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/week_column_6"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
</com.simplemobiletools.calendar.pro.views.MyScrollView>
|
||||
@ -100,7 +57,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/monday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_1"
|
||||
@ -109,7 +66,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/tuesday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_2"
|
||||
@ -118,7 +75,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/wednesday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_3"
|
||||
@ -127,7 +84,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/thursday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_4"
|
||||
@ -136,7 +93,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/friday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_5"
|
||||
@ -145,7 +102,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/saturday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/week_day_label_6"
|
||||
@ -154,7 +111,7 @@
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/sunday_letter"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
android:textSize="@dimen/normal_text_size" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
6
app/src/main/res/layout/weekly_view_day_column.xml
Normal file
6
app/src/main/res/layout/weekly_view_day_column.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/week_column"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1" />
|
Loading…
x
Reference in New Issue
Block a user