fix(#530): open a widget's day on its own so back returns home
This commit is contained in:
1 parent
a24420edfb
commit
0e859622c6
5 files changed
+51
-37
No files matched your search
@@ -602,9 +602,8 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the day view anchored on [date], drilled in over the launching
|
||||
* widget's [source] view (home-screen widgets). Backing out of the day
|
||||
* returns to [source], then to the default home view.
|
||||
* 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).
|
||||
*/
|
||||
fun openDateIntent(context: Context, date: LocalDate, source: CalendarView): Intent =
|
||||
Intent(context, MainActivity::class.java).apply {
|
||||
|
||||
@@ -92,6 +92,7 @@ import de.jeanlucmakiola.calendula.ui.common.LocalTimelineZoom
|
||||
import de.jeanlucmakiola.calendula.ui.common.ViewMorphScope
|
||||
import de.jeanlucmakiola.calendula.ui.common.rememberCalendarFadeSpec
|
||||
import de.jeanlucmakiola.calendula.ui.common.rememberViewMorphBoundsTransform
|
||||
import de.jeanlucmakiola.calendula.ui.common.dateLaunchStack
|
||||
import de.jeanlucmakiola.calendula.ui.common.drillToDay
|
||||
import de.jeanlucmakiola.calendula.ui.common.drillToWeek
|
||||
import de.jeanlucmakiola.calendula.ui.common.rememberCalendarSlideSpec
|
||||
@@ -128,8 +129,9 @@ import kotlin.time.Instant
|
||||
* (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 screen returns to that widget's
|
||||
* view, then home; and back through pill switches walks the views in reverse.
|
||||
* 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; 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
|
||||
@@ -403,8 +405,8 @@ 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. Date/event opens root the stack in the widget's own
|
||||
// view so backing out returns there (then home), not to the default.
|
||||
// the detail request. An event open roots the stack in the widget's own
|
||||
// view; a date open shows the day alone, so back leaves the app (#530).
|
||||
val widgetNavRequest = requests.nav
|
||||
LaunchedEffect(widgetNavRequest) {
|
||||
if (widgetNavRequest != null) {
|
||||
@@ -413,13 +415,11 @@ fun CalendarHost(
|
||||
}
|
||||
when (val req = widgetNavRequest) {
|
||||
is WidgetNavRequest.OpenDate -> {
|
||||
// Drill the day view in over the widget's view: drop any overlay
|
||||
// that would cover it, so the open doesn't land under Settings/form.
|
||||
// Drop any overlay that would cover the day, so the open doesn't
|
||||
// land under Settings/form.
|
||||
dismissCoveringOverlays()
|
||||
focus.navigateTo(LocalDate.parse(req.dateIso))
|
||||
// No widget source (an external date tap) roots over the default
|
||||
// home view, so backing out of the day returns home then exits.
|
||||
viewStack = viewBaseStack(defaultView, req.source ?: defaultView).drillToDay()
|
||||
viewStack = dateLaunchStack(defaultView, req.source)
|
||||
requests.nav = null
|
||||
}
|
||||
is WidgetNavRequest.OpenEvent -> {
|
||||
|
||||
@@ -7,17 +7,16 @@ import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
* Parsed from the launch intent in MainActivity and consumed once by
|
||||
* [CalendarHost]. Every request carries the [source] view of the widget it came
|
||||
* from (the agenda widget → [CalendarView.Agenda], the month widget →
|
||||
* [CalendarView.Month]) so the in-app back stack roots itself in that view:
|
||||
* backing out of the opened date/event returns to the widget's own view, not the
|
||||
* default home. (Reminder notifications are not widgets — they keep the separate
|
||||
* [CalendarView.Month]); an opened event roots the in-app back stack in that
|
||||
* view, so backing out returns there rather than to the default home. (Reminder notifications are not widgets — they keep the separate
|
||||
* detail-key channel and leave the base view untouched.)
|
||||
*/
|
||||
sealed interface WidgetNavRequest {
|
||||
/**
|
||||
* Open the day view anchored on [dateIso] (an ISO `yyyy-MM-dd` date), over
|
||||
* [source]. A null [source] means the request came from outside the app (a
|
||||
* launcher/clock date tap, issue #9) rather than a widget, so it roots over
|
||||
* the default home view instead of a widget's view.
|
||||
* Open the day view anchored on [dateIso] (an ISO `yyyy-MM-dd` date). From a
|
||||
* widget ([source] non-null) the day stands alone, so back returns to the home
|
||||
* screen (#530). A null [source] means a launcher/clock date tap (issue #9) or
|
||||
* the daily summary, which root it over the default home view.
|
||||
*/
|
||||
data class OpenDate(val dateIso: String, val source: CalendarView?) : WidgetNavRequest
|
||||
|
||||
|
||||
@@ -103,8 +103,8 @@ data class QuickSwitchConfig(
|
||||
}
|
||||
|
||||
/**
|
||||
* The top-level view back stack (bottom → top): the [default] home view always
|
||||
* sits at the bottom. Pressing back pops one level until only the home view
|
||||
* The top-level view back stack (bottom → top): the [default] home view sits at
|
||||
* the bottom, except for a day opened from a widget (see [dateLaunchStack]). Pressing back pops one level until only the home view
|
||||
* remains, then the system exits the app. Three operations move it:
|
||||
*
|
||||
* - [selectView] — a lateral switch (the pill or the drawer). It keeps a visit
|
||||
@@ -126,6 +126,14 @@ fun List<CalendarView>.selectView(target: CalendarView): List<CalendarView> {
|
||||
fun viewBaseStack(default: CalendarView, source: CalendarView): List<CalendarView> =
|
||||
if (source == default) listOf(default) else listOf(default, source)
|
||||
|
||||
/**
|
||||
* The stack an outside date open resets to. From a widget ([source] non-null)
|
||||
* the day view stands alone, so back returns to the home screen (#530); a
|
||||
* launcher/clock or daily-summary tap drills it in over the [default] home view.
|
||||
*/
|
||||
fun dateLaunchStack(default: CalendarView, source: CalendarView?): List<CalendarView> =
|
||||
if (source != null) listOf(CalendarView.Day) else listOf(default).drillToDay()
|
||||
|
||||
/** Push the day view as a drill-in over the current stack (no-op if already on it). */
|
||||
fun List<CalendarView>.drillToDay(): List<CalendarView> =
|
||||
if (lastOrNull() == CalendarView.Day) this else this + CalendarView.Day
|
||||
|
||||
@@ -6,8 +6,8 @@ import org.junit.jupiter.api.Test
|
||||
/**
|
||||
* The pure back-stack rules behind [CalendarHost]'s top-level navigation:
|
||||
* the home view is always the bottom, a lateral move keeps the stack one deep,
|
||||
* and a date tap drills the day view on top. Verifies the back sequences the
|
||||
* widget-UX fix promises (e.g. agenda widget → day → back → agenda → back → home).
|
||||
* and a date tap drills the day view on top, except a widget's, which opens the
|
||||
* day alone so back returns to the home screen (#530).
|
||||
*/
|
||||
class ViewBackStackTest {
|
||||
|
||||
@@ -74,23 +74,31 @@ class ViewBackStackTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `agenda widget date tap backs out agenda then home`() {
|
||||
// openDate(source = Agenda): root in Agenda over the Week home, then drill.
|
||||
val stack = viewBaseStack(CalendarView.Week, CalendarView.Agenda).drillToDay()
|
||||
assertThat(stack)
|
||||
.containsExactly(CalendarView.Week, CalendarView.Agenda, CalendarView.Day)
|
||||
.inOrder()
|
||||
// Pressing back pops one level at a time down to the home view.
|
||||
assertThat(stack.dropLast(1)).containsExactly(CalendarView.Week, CalendarView.Agenda).inOrder()
|
||||
assertThat(stack.dropLast(2)).containsExactly(CalendarView.Week)
|
||||
fun `a widget date tap opens the day alone so back leaves the app`() {
|
||||
// #530: from any widget, the day is the whole stack.
|
||||
assertThat(dateLaunchStack(CalendarView.Week, CalendarView.Month))
|
||||
.containsExactly(CalendarView.Day)
|
||||
assertThat(dateLaunchStack(CalendarView.Week, CalendarView.Agenda))
|
||||
.containsExactly(CalendarView.Day)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `month widget date tap backs out month then home`() {
|
||||
val stack = viewBaseStack(CalendarView.Week, CalendarView.Month).drillToDay()
|
||||
assertThat(stack.last()).isEqualTo(CalendarView.Day)
|
||||
assertThat(stack.dropLast(1).last()).isEqualTo(CalendarView.Month)
|
||||
assertThat(stack.first()).isEqualTo(CalendarView.Week)
|
||||
fun `an outside date tap drills the day over the home view`() {
|
||||
assertThat(dateLaunchStack(CalendarView.Week, null))
|
||||
.containsExactly(CalendarView.Week, CalendarView.Day)
|
||||
.inOrder()
|
||||
assertThat(dateLaunchStack(CalendarView.Day, null)).containsExactly(CalendarView.Day)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `switching views from a widget-opened day retraces back to it, then out`() {
|
||||
val stack = dateLaunchStack(CalendarView.Week, CalendarView.Month)
|
||||
.selectView(CalendarView.Month)
|
||||
.selectView(CalendarView.Week)
|
||||
assertThat(stack)
|
||||
.containsExactly(CalendarView.Day, CalendarView.Month, CalendarView.Week)
|
||||
.inOrder()
|
||||
assertThat(stack.selectView(CalendarView.Day)).containsExactly(CalendarView.Day)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user