Fixed going to date from event list widget (#1607)

This commit is contained in:
Agnieszka C 2022-01-08 10:44:41 +01:00
parent 2090d81be2
commit 977e9aa7f6
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)
}