fix(#530): arm the exit only for a widget's day, skip it on replay

This commit is contained in:
makiolaj committed 2026-11-25 12:17:45 +01:00
1 parent 3039d48aa4
commit ed4129580b
3 files changed
+21 -15

No files matched your search

@@ -150,7 +150,9 @@ class MainActivity : AppCompatActivity() {
// specific event is what made a single reminder or widget tap re-open
// 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.
// 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.
//
// 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
@@ -163,7 +165,7 @@ class MainActivity : AppCompatActivity() {
requests.editKey = intent.editEventKeyOrNull()
}
requests.nav = intent.navRequestOrNull()
?.takeUnless { replaying && it is WidgetNavRequest.OpenEvent }
?.takeUnless { replaying && (it is WidgetNavRequest.OpenEvent || it is WidgetNavRequest.OpenDate) }
requests.importUri = intent.importUriOrNull()
val insertOpenBefore = savedInstanceState?.getBoolean(KEY_INSERT_FORM_OPEN) == true
requests.insert = intent.createRequestOrNull()?.takeIf { !replaying || insertOpenBefore }
@@ -602,8 +604,9 @@ class MainActivity : AppCompatActivity() {
}
/**
* Open the day view anchored on [date] from a home-screen widget of kind
* [source]. Backing out of the day returns to the home screen (#530).
* 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.
*/
fun openDateIntent(context: Context, date: LocalDate, source: CalendarView): Intent =
Intent(context, MainActivity::class.java).apply {
@@ -126,10 +126,10 @@ import kotlin.time.Instant
*
* The stack's bottom is the user's [CalendarHostViewModel.defaultView] home view.
* A lateral switch (pill / drawer) builds a visit history so back retraces it
* (see [selectView]); a widget launch resets the stack to its own view; a date
* tap drills the day view on top. Pressing back pops one level, and the
* base-level [BackHandler] hands off to the system to exit once only the home
* view remains. So back from a widget-opened event returns to that widget's
* (see [selectView]); a widget event or header launch resets the stack to the
* widget's view; a date tap or date launch drills the day view on top. Pressing
* back pops one level, and the base-level [BackHandler] hands off to the system
* to exit once only the home view remains. So back from a widget-opened event returns to that widget's
* view, then home; back from a widget-opened day leaves the app at once (#530),
* until the user navigates on from it; and back through pill switches walks the
* views in reverse.
@@ -187,8 +187,9 @@ fun CalendarHost(
val switchTo: ((List<CalendarView>) -> List<CalendarView>) -> Unit = { move ->
navigationVersion++
returnedFromDay = false
exitOnBack = false
viewStack = move(viewStack)
val moved = move(viewStack)
if (moved != viewStack) exitOnBack = false
viewStack = moved
}
val onSelectView: (CalendarView) -> Unit = { target -> switchTo { it.selectView(target) } }
val onOpenDay: (LocalDate) -> Unit = { date ->
@@ -416,7 +417,6 @@ fun CalendarHost(
if (widgetNavRequest != null) {
navigationVersion++
returnedFromDay = false
exitOnBack = false
}
when (val req = widgetNavRequest) {
is WidgetNavRequest.OpenDate -> {
@@ -433,6 +433,7 @@ fun CalendarHost(
// detail over it (same key shape as a tapped event / reminder).
dismissCoveringOverlays()
viewStack = viewBaseStack(defaultView, req.source)
exitOnBack = false
detailKey = longArrayOf(req.eventId, req.beginMillis, req.endMillis)
requests.nav = null
}
@@ -444,6 +445,7 @@ fun CalendarHost(
dismissCoveringOverlays()
focus.navigateTo(currentDate())
viewStack = viewBaseStack(defaultView, req.view ?: defaultView)
exitOnBack = false
requests.nav = null
}
is WidgetNavRequest.Create -> {
@@ -540,10 +542,11 @@ fun CalendarHost(
val viewTransition = remember { SeekableTransitionState(view) }
LaunchedEffect(view) { viewTransition.animateTo(view) }
val reduceMotion = rememberReduceMotion()
val viewBackEnabled = !anyOverlayVisible && viewStack.size > 1 && !exitOnBack
// Finished rather than sent to the background, so the next launch opens on the home view.
val activity = LocalActivity.current
BackHandler(enabled = !anyOverlayVisible && exitOnBack) { activity?.finish() }
val leaveOnBack = !anyOverlayVisible && exitOnBack && activity != null
val viewBackEnabled = !anyOverlayVisible && viewStack.size > 1 && !leaveOnBack
// Finished rather than sent to the background, so the next launch opens on the home view.
BackHandler(enabled = leaveOnBack) { activity?.finish() }
if (reduceMotion) {
BackHandler(enabled = viewBackEnabled) {
navigationVersion++
@@ -112,7 +112,7 @@ data class QuickSwitchConfig(
* top; switching to one already in the stack pops back to it (collapsing the
* loop, so the depth stays bounded by the number of distinct views). Selecting
* the home view collapses to just `[default]`.
* - [viewBaseStack] — the stack a widget launch resets to: just `[default]` when
* - [viewBaseStack] — the stack a widget event or header launch resets to: just `[default]` when
* the widget's view is the home view, else `[default, source]`. A widget entry
* starts a fresh context rather than extending in-app history.
* - [drillToDay] — pushes the day view on top (a date tap from the month grid, a