create weekly view programmatically, do not hardcode 7

This commit is contained in:
tibbi
2020-06-08 16:28:36 +02:00
parent 507719af7c
commit 888595b2ed
4 changed files with 30 additions and 60 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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">
@@ -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>

View 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" />