always show the proper events at the list of month/day view

This commit is contained in:
tibbi 2021-02-22 20:43:01 +01:00
parent 2051287365
commit 88a4ccfec5
2 changed files with 49 additions and 20 deletions

View File

@ -30,7 +30,7 @@ class MonthDayFragment : Fragment(), MonthlyCalendar {
private var mSundayFirst = false
private var mShowWeekNumbers = false
private var mDayCode = ""
private var mCurrentDayCode = ""
private var mSelectedDayCode = ""
private var mPackageName = ""
private var mLastHash = 0L
private var mCalendar: MonthlyCalendarImpl? = null
@ -52,8 +52,10 @@ class MonthDayFragment : Fragment(), MonthlyCalendar {
val shownMonthDateTime = Formatter.getDateTimeFromCode(mDayCode)
val todayCode = Formatter.getTodayCode()
val todayDateTime = Formatter.getDateTimeFromCode(todayCode)
if (todayDateTime.year == shownMonthDateTime.year && todayDateTime.monthOfYear == shownMonthDateTime.monthOfYear) {
mCurrentDayCode = todayCode
mSelectedDayCode = if (todayDateTime.year == shownMonthDateTime.year && todayDateTime.monthOfYear == shownMonthDateTime.monthOfYear) {
todayCode
} else {
mDayCode
}
mConfig = context!!.config
@ -104,7 +106,7 @@ class MonthDayFragment : Fragment(), MonthlyCalendar {
activity?.runOnUiThread {
mHolder.month_day_view_wrapper.updateDays(days, false) {
mCurrentDayCode = it.code
mSelectedDayCode = it.code
updateVisibleEvents()
}
}
@ -113,23 +115,33 @@ class MonthDayFragment : Fragment(), MonthlyCalendar {
val endDateTime = startDateTime.plusWeeks(6)
context.eventsHelper.getEvents(startDateTime.seconds(), endDateTime.seconds()) { events ->
mListEvents = events
updateVisibleEvents()
activity?.runOnUiThread {
updateVisibleEvents()
}
}
}
private fun updateVisibleEvents() {
val filtered = mListEvents.filter {
Formatter.getDayCodeFromTS(it.startTS) == mCurrentDayCode
if (activity == null) {
return
}
val listItems = context!!.getEventListItems(filtered, false)
val filtered = mListEvents.filter {
Formatter.getDayCodeFromTS(it.startTS) == mSelectedDayCode
}
val listItems = activity!!.getEventListItems(filtered, false)
month_day_selected_day_label.text = Formatter.getDateFromCode(activity!!, mSelectedDayCode, false)
activity?.runOnUiThread {
EventListAdapter(activity as SimpleActivity, listItems, true, null, month_day_events_list, false) {
if (it is ListEvent) {
activity?.editEvent(it)
if (activity != null) {
EventListAdapter(activity as SimpleActivity, listItems, true, null, month_day_events_list, false) {
if (it is ListEvent) {
activity?.editEvent(it)
}
}.apply {
month_day_events_list.adapter = this
}
}.apply {
month_day_events_list.adapter = this
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/month_day_calendar_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -24,15 +25,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/month_day_view_wrapper" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/month_day_events_list"
<RelativeLayout
android:id="@+id/month_day_list_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:scrollbars="vertical"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager"
app:layout_constraintHeight_percent="0.7"
app:layout_constraintTop_toBottomOf="@+id/month_day_view_wrapper" />
app:layout_constraintTop_toBottomOf="@+id/month_day_view_divider">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/month_day_selected_day_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:paddingTop="@dimen/medium_margin"
android:textSize="@dimen/bigger_text_size"
tools:text="8/5/2021" />
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/month_day_events_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/month_day_selected_day_label"
android:clipToPadding="false"
android:overScrollMode="never"
android:scrollbars="vertical"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>