fix(#530): review round 5 - a widget's event detail also leaves on back

This commit is contained in:
makiolaj committed 2026-11-25 15:51:36 +01:00
1 parent 8bdc886226
commit 8306e8c636
3 files changed
+39 -17

No files matched your search

@@ -128,10 +128,9 @@ import kotlin.time.Instant
* (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.
* to exit once only the home view remains. Back from a widget-opened day or
* event leaves the app at once (#530), until the user navigates on from it; and
* back through pill switches walks the views in reverse.
*
* [requests] carries what notifications, widgets and other apps asked to
* open. A tapped reminder's occurrence opens the detail overlay exactly like an
@@ -205,6 +204,8 @@ fun CalendarHost(
// Like every overlay below, it draws its last key through the slide-out
// ([rememberHeld]) rather than a placeholder.
var detailKey by rememberSaveable { mutableStateOf<LongArray?>(null) }
// The detail a widget opened; back from it leaves the app (#530).
var widgetDetailKey by rememberSaveable { mutableStateOf<LongArray?>(null) }
val onOpenDetail: (EventInstance) -> Unit = { event -> detailKey = event.occurrenceKey() }
// The drawer's "Hide in this view" picker (#517). It is its own window over
@@ -407,8 +408,7 @@ fun CalendarHost(
// A home-screen widget launch asks to open a date (→ day view), open an
// event's detail, or start a create. Handled once and cleared, mirroring
// the detail request. An event open roots the stack in the widget's own view
// so backing out returns there (then home); a widget's day leaves on back.
// the detail request. A widget's day or event leaves the app on back (#530).
val widgetNavRequest = requests.nav
LaunchedEffect(widgetNavRequest) {
if (widgetNavRequest != null) {
@@ -430,8 +430,9 @@ fun CalendarHost(
// detail over it (same key shape as a tapped event / reminder).
dismissCoveringOverlays()
viewStack = viewBaseStack(defaultView, req.source)
requests.leaveOnBack = false
requests.leaveOnBack = req.leavesOnBack
detailKey = longArrayOf(req.eventId, req.beginMillis, req.endMillis)
widgetDetailKey = detailKey
requests.nav = null
}
is WidgetNavRequest.OpenView -> {
@@ -785,7 +786,14 @@ fun CalendarHost(
eventId = key[0],
beginMillis = key[1],
endMillis = key[2],
onBack = { detailKey = null },
onBack = {
if (leavesFromDetail(requests.leaveOnBack, detailKey, widgetDetailKey)) {
requests.leaveOnBack = false
requests.onLeave()
} else {
detailKey = null
}
},
onEdit = { editKey = key },
onDuplicate = { form ->
// Reuse the prefilled-create overlay: a duplicate is a
@@ -7,10 +7,9 @@ import java.io.Serializable
* A navigation a home-screen widget asked the app to perform when launched.
* Parsed from the launch intent in MainActivity and consumed once by
* [CalendarHost]. An event open carries the [OpenEvent.source] view of the
* widget it came from (the agenda widget → [CalendarView.Agenda]) so backing out
* returns to that view, not the default home. (Reminder notifications are not
* widgets — they keep the separate detail-key channel and leave the base view
* untouched.)
* widget it came from (the agenda widget → [CalendarView.Agenda]) as the view
* under its detail. (Reminder notifications are not widgets — they keep the
* separate detail-key channel and leave the base view untouched.)
*/
sealed interface WidgetNavRequest : Serializable {
/**
@@ -20,7 +19,7 @@ sealed interface WidgetNavRequest : Serializable {
*/
data class OpenDate(val dateIso: String, val fromWidget: Boolean) : WidgetNavRequest
/** Open one occurrence's detail (an agenda-widget event tap), over [source]. */
/** Open one occurrence's detail (a widget event tap), over [source]; back leaves the app (#530). */
data class OpenEvent(
val eventId: Long,
val beginMillis: Long,
@@ -41,9 +40,13 @@ sealed interface WidgetNavRequest : Serializable {
data class OpenView(val view: CalendarView?) : WidgetNavRequest
}
/** Whether back leaves the app straight from what this request opens (a widget's day, #530). */
/** Whether back leaves the app straight from what this request opens: a widget's day or event (#530). */
val WidgetNavRequest.leavesOnBack: Boolean
get() = this is WidgetNavRequest.OpenDate && fromWidget
get() = (this is WidgetNavRequest.OpenDate && fromWidget) || this is WidgetNavRequest.OpenEvent
/** Whether back on the detail showing [shown] leaves the app: it's still the widget's event, [opened]. */
fun leavesFromDetail(armed: Boolean, shown: LongArray?, opened: LongArray?): Boolean =
armed && shown != null && opened != null && shown.contentEquals(opened)
/**
* Whether a widget day's leave-on-back stays armed across a move from [before] to
@@ -7,10 +7,11 @@ import org.junit.jupiter.api.Test
class WidgetNavRequestTest {
@Test
fun `only a widget's day leaves on back`() {
fun `a widget's day or event leaves on back`() {
assertThat(WidgetNavRequest.OpenDate("2026-11-25", fromWidget = true).leavesOnBack).isTrue()
assertThat(WidgetNavRequest.OpenDate("2026-11-25", fromWidget = false).leavesOnBack).isFalse()
assertThat(WidgetNavRequest.OpenEvent(1, 2, 3, CalendarView.Agenda).leavesOnBack).isFalse()
assertThat(WidgetNavRequest.OpenEvent(1, 2, 3, CalendarView.Agenda).leavesOnBack).isTrue()
assertThat(WidgetNavRequest.OpenEvent(1, 2, 3, CalendarView.Day).leavesOnBack).isTrue()
assertThat(WidgetNavRequest.OpenView(CalendarView.Month).leavesOnBack).isFalse()
assertThat(WidgetNavRequest.Create(null).leavesOnBack).isFalse()
}
@@ -23,4 +24,14 @@ class WidgetNavRequestTest {
assertThat(keepsLeaveOnBack(true, day, day + CalendarView.Month)).isFalse()
assertThat(keepsLeaveOnBack(false, day, day)).isFalse()
}
@Test
fun `only the widget's own detail leaves on back`() {
val opened = longArrayOf(1, 2, 3)
assertThat(leavesFromDetail(true, longArrayOf(1, 2, 3), opened)).isTrue()
assertThat(leavesFromDetail(true, longArrayOf(4, 5, 6), opened)).isFalse()
assertThat(leavesFromDetail(false, opened, opened)).isFalse()
assertThat(leavesFromDetail(true, null, opened)).isFalse()
assertThat(leavesFromDetail(true, opened, null)).isFalse()
}
}