From 2970ca08d0caa313cd1744d7979fa914e85c89c7 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Wed, 25 Nov 2026 12:30:48 +0100 Subject: [PATCH] fix(#530): replay a date open that was never handled --- .../de/jeanlucmakiola/calendula/MainActivity.kt | 17 +++++++++++------ .../calendula/ui/common/ViewBackStackTest.kt | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt b/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt index 21db94a9..df6c0b2a 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/MainActivity.kt @@ -151,8 +151,8 @@ class MainActivity : AppCompatActivity() { // that event on every later launch, an error screen once the event had // been deleted (#309); the user left it long ago, and the activity // restores where they actually were along with its saved state. A date - // open is held back the same way, so a finished widget day (#530) comes - // back from Recents on the home view. + // open is held back the same way once handled, so a finished widget day + // (#530) comes back from Recents on the home view. // // Only those channels are held back. An .ics import or a prefilled // create form keeps no saved state of its own, so re-reading the intent @@ -164,8 +164,10 @@ class MainActivity : AppCompatActivity() { requests.detailKey = intent.detailKeyOrNull() ?: intent.viewEventKeyOrNull() requests.editKey = intent.editEventKeyOrNull() } - requests.nav = intent.navRequestOrNull() - ?.takeUnless { replaying && (it is WidgetNavRequest.OpenEvent || it is WidgetNavRequest.OpenDate) } + val navPendingBefore = savedInstanceState?.getBoolean(KEY_NAV_PENDING) == true + requests.nav = intent.navRequestOrNull()?.takeUnless { + replaying && (it is WidgetNavRequest.OpenEvent || (it is WidgetNavRequest.OpenDate && !navPendingBefore)) + } requests.importUri = intent.importUriOrNull() val insertOpenBefore = savedInstanceState?.getBoolean(KEY_INSERT_FORM_OPEN) == true requests.insert = intent.createRequestOrNull()?.takeIf { !replaying || insertOpenBefore } @@ -291,6 +293,7 @@ class MainActivity : AppCompatActivity() { super.onSaveInstanceState(outState) outState.putBoolean(KEY_INSERT_FORM_OPEN, insertFormOpen) outState.putBoolean(KEY_LAUNCHED_FOR_INSERT, launchedForInsert) + outState.putBoolean(KEY_NAV_PENDING, requests.nav != null) } override fun onNewIntent(intent: Intent) { @@ -566,6 +569,7 @@ class MainActivity : AppCompatActivity() { private val CALENDAR_EXTENSIONS = listOf(".ics", ".vcs") private const val KEY_INSERT_FORM_OPEN = "insert_form_open" private const val KEY_LAUNCHED_FOR_INSERT = "launched_for_insert" + private const val KEY_NAV_PENDING = "nav_pending" private const val EXTRA_EVENT_ID = "de.jeanlucmakiola.calendula.extra.EVENT_ID" private const val EXTRA_BEGIN_MILLIS = "de.jeanlucmakiola.calendula.extra.BEGIN" @@ -605,8 +609,9 @@ class MainActivity : AppCompatActivity() { /** * Open the day view anchored on [date] from a home-screen widget; backing - * out of the day returns to the home screen (#530). [source] only keeps - * the PendingIntents of different widget kinds apart. + * out of the day returns to the home screen (#530). [source] marks the + * launch as a widget's and keeps different widget kinds' PendingIntents + * apart; its value doesn't change where back goes. */ fun openDateIntent(context: Context, date: LocalDate, source: CalendarView): Intent = Intent(context, MainActivity::class.java).apply { diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ViewBackStackTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ViewBackStackTest.kt index 36d02d2a..6558671f 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ViewBackStackTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ViewBackStackTest.kt @@ -92,6 +92,14 @@ class ViewBackStackTest { assertThat(stack.first()).isEqualTo(CalendarView.Week) } + @Test + fun `a date launch drills the day over the home view only`() { + assertThat(listOf(CalendarView.Week).drillToDay()) + .containsExactly(CalendarView.Week, CalendarView.Day) + .inOrder() + assertThat(listOf(CalendarView.Day).drillToDay()).containsExactly(CalendarView.Day) + } + @Test fun `a widget whose view is the home view does not duplicate the home`() { // Default = Agenda, agenda widget event tap → just the home, no extra layer.