From f97d59b14a574231f7833744ed97a6634378fc66 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 22 Feb 2021 21:37:41 +0100 Subject: [PATCH] show whole months events by default at month/day view --- .../pro/fragments/MonthDayFragment.kt | 27 ++++++++++++++++--- .../main/res/layout/fragment_month_day.xml | 6 ++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragment.kt index 6b5777bd3..39d4ddd26 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/fragments/MonthDayFragment.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.calendar.pro.extensions.* import com.simplemobiletools.calendar.pro.helpers.Config import com.simplemobiletools.calendar.pro.helpers.DAY_CODE import com.simplemobiletools.calendar.pro.helpers.Formatter +import com.simplemobiletools.calendar.pro.helpers.Formatter.YEAR_PATTERN import com.simplemobiletools.calendar.pro.helpers.MonthlyCalendarImpl import com.simplemobiletools.calendar.pro.interfaces.MonthlyCalendar import com.simplemobiletools.calendar.pro.interfaces.NavigationListener @@ -55,7 +56,8 @@ class MonthDayFragment : Fragment(), MonthlyCalendar { mSelectedDayCode = if (todayDateTime.year == shownMonthDateTime.year && todayDateTime.monthOfYear == shownMonthDateTime.monthOfYear) { todayCode } else { - mDayCode + mHolder.month_day_selected_day_label.text = getMonthLabel(shownMonthDateTime) + "" } mConfig = context!!.config @@ -127,11 +129,19 @@ class MonthDayFragment : Fragment(), MonthlyCalendar { } val filtered = mListEvents.filter { - Formatter.getDayCodeFromTS(it.startTS) == mSelectedDayCode + if (mSelectedDayCode.isEmpty()) { + val shownMonthDateTime = Formatter.getDateTimeFromCode(mDayCode) + val startDateTime = Formatter.getDateTimeFromTS(it.startTS) + shownMonthDateTime.year == startDateTime.year && shownMonthDateTime.monthOfYear == startDateTime.monthOfYear + } else { + Formatter.getDayCodeFromTS(it.startTS) == mSelectedDayCode + } } val listItems = activity!!.getEventListItems(filtered, false) - month_day_selected_day_label.text = Formatter.getDateFromCode(activity!!, mSelectedDayCode, false) + if (mSelectedDayCode.isNotEmpty()) { + mHolder.month_day_selected_day_label.text = Formatter.getDateFromCode(activity!!, mSelectedDayCode, false) + } activity?.runOnUiThread { if (activity != null) { @@ -152,5 +162,14 @@ class MonthDayFragment : Fragment(), MonthlyCalendar { fun printCurrentView() {} - fun getNewEventDayCode() = mSelectedDayCode + fun getNewEventDayCode() = if (mSelectedDayCode.isEmpty()) mDayCode else mSelectedDayCode + + private fun getMonthLabel(shownMonthDateTime: DateTime): String { + var month = Formatter.getMonthName(activity!!, shownMonthDateTime.monthOfYear) + val targetYear = shownMonthDateTime.toString(YEAR_PATTERN) + if (targetYear != DateTime().toString(YEAR_PATTERN)) { + month += " $targetYear" + } + return month + } } diff --git a/app/src/main/res/layout/fragment_month_day.xml b/app/src/main/res/layout/fragment_month_day.xml index 79631e804..3d48a9d06 100644 --- a/app/src/main/res/layout/fragment_month_day.xml +++ b/app/src/main/res/layout/fragment_month_day.xml @@ -11,7 +11,7 @@ android:id="@+id/month_day_view_wrapper" android:layout_width="match_parent" android:layout_height="0dp" - app:layout_constraintBottom_toTopOf="@+id/month_day_events_list" + app:layout_constraintBottom_toTopOf="@+id/month_day_list_holder" app:layout_constraintHeight_percent="0.3" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -37,8 +37,8 @@ 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" + android:paddingTop="@dimen/normal_margin" + android:textSize="@dimen/actionbar_text_size" tools:text="8/5/2021" />