Merge pull request #1608 from Aga-C/fix-widget-date-open

Fixed going to date from event list widget (#1607)
This commit is contained in:
Tibor Kaputa 2022-01-14 10:19:23 +01:00 committed by GitHub
commit 276f9aabd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -849,12 +849,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
currentFragments.clear()
currentFragments.add(fragment)
val bundle = Bundle()
val fixedDayCode = fixDayCode(dayCode)
when (config.storedView) {
DAILY_VIEW -> bundle.putString(DAY_CODE, dayCode ?: Formatter.getTodayCode())
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, dayCode ?: getDatesWeekDateTime(DateTime()))
MONTHLY_VIEW, MONTHLY_DAILY_VIEW -> bundle.putString(DAY_CODE, dayCode ?: Formatter.getTodayCode())
YEARLY_VIEW -> bundle.putString(YEAR_TO_OPEN, dayCode)
DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
WEEKLY_VIEW -> bundle.putString(WEEK_START_DATE_TIME, fixedDayCode ?: getDatesWeekDateTime(DateTime()))
MONTHLY_VIEW, MONTHLY_DAILY_VIEW -> bundle.putString(DAY_CODE, fixedDayCode ?: Formatter.getTodayCode())
YEARLY_VIEW -> bundle.putString(YEAR_TO_OPEN, fixedDayCode)
}
fragment.arguments = bundle
@ -862,6 +863,12 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
supportActionBar?.setDisplayHomeAsUpEnabled(false)
}
private fun fixDayCode(dayCode: String? = null): String? = when {
config.storedView == WEEKLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> getDatesWeekDateTime(Formatter.getDateTimeFromCode(dayCode))
config.storedView == YEARLY_VIEW && (dayCode?.length == Formatter.DAYCODE_PATTERN.length) -> Formatter.getYearFromDayCode(dayCode)
else -> dayCode
}
fun openMonthFromYearly(dateTime: DateTime) {
if (currentFragments.last() is MonthFragmentsHolder) {
return

View File

@ -136,4 +136,6 @@ object Formatter {
fun getUTCDayCodeFromTS(ts: Long) = getUTCDateTimeFromTS(ts).toString(DAYCODE_PATTERN)
fun getShiftedImportTimestamp(ts: Long) = getUTCDateTimeFromTS(ts).withTime(13, 0, 0, 0).withZoneRetainFields(DateTimeZone.getDefault()).seconds()
fun getYearFromDayCode(dayCode: String) = getDateTimeFromCode(dayCode).toString(YEAR_PATTERN)
}