Modern Apps git

← Modern-Apps.git

maps: tidy route-owned tabs and test the sheet stack (#nav)

Commit
9ac15c56c204f0fdf2d93958ce22092e9f7135b3
Author
Vayun Mathur <[email protected]>
When
2026-11-16 19:29 UTC (19 days ago)
Parents
1f227d5
M8/M9: the place tab is SheetRoute.Place.section, written back
with setLast (the VM holder is gone; standalone previews of the
VM-backed sheet overloads keep a rememberSaveable section in
the sheet, as the sketch allows). The travel-mode tab is
SheetRoute.RoutePlan.mode: MapChromeState.selectedRouteType
and the SelectedFeatureViewModel.selectedRouteMode mirror are
deleted, the route overlay and RouteSheet read the plan's mode
from the scope, and switching tabs setLast-copies the plan.

Adds SheetRouteStackTest: pure stack-transition tests for
directions-over-place, parked-route append, search pop/pick
replace, replace-in-place taps, the un-poppable Browse root,
route-carried section/mode, and trip-over-board pop.

Verified: :maps:compileDevKotlin green; SheetRouteStackTest
and MapChromeState tests pass; full suite run follows.

Diff

maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.ktindex 106f2bb424..59f226dc60 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt@@ -79,7 +79,7 @@ internal fun MapPageScope.MapContentBox(                     transitViewModel = transitViewModel,                     sheetState = sheetState,                     selectedFeature = selectedFeature,-                    route = route?.get(chrome.selectedRouteType),+                    route = route?.get(selectedRouteType),                     userPosition = userPosition,                     userBearing = userBearing,                     navProgress = navProgress,
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex af143a5a66..19b802d26a 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -155,7 +155,7 @@ fun MapPage(     // The visible route tab is the RoutePlan's mode: switching it writes     // the route back (setLast), and routes plans that mode first.     val activeRoutePlan = sheetStack.backStack.routePlan()-    val selectedRouteType = activeRoutePlan?.mode ?: chrome.selectedRouteType+    val selectedRouteType = activeRoutePlan?.mode ?: RouteService.TravelMode.DRIVE     val route by viewModel.routes.collectAsState(null)     // Collected here (rather than inside the sheet) so the inner place sheet's     // contentKey can name them: the tab switch and the late-arriving reviews@@ -316,9 +316,9 @@ fun MapPage(             (sheetTop as? SheetRoute.Place)?.let { sheetStack.setLast(it.copy(section = section)) }         },         onRouteMode = { mode ->-            val plan = sheetStack.backStack.routePlan()-            if (plan != null && sheetTop is SheetRoute.RoutePlan) sheetStack.setLast(plan.copy(mode = mode))-            else chrome.selectedRouteType = mode+            if (sheetTop is SheetRoute.RoutePlan) {+                sheetStack.setLast((sheetTop as SheetRoute.RoutePlan).copy(mode = mode))+            }         },         selectedRouteType = selectedRouteType,         poiEnrichmentKey = PoiEnrichmentKey.of(currentPoiInfo),
maps/src/main/java/com/vayunmathur/maps/ui/map/MapChromeState.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChromeState.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChromeState.ktindex 858c3e1b6e..b5d381520f 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChromeState.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapChromeState.kt@@ -11,14 +11,13 @@ import androidx.compose.runtime.setValue import com.vayunmathur.library.map.MapBody import com.vayunmathur.maps.data.PostedLimit import com.vayunmathur.maps.ui.MapCategory-import com.vayunmathur.maps.util.RouteService  /**  * Everything the map chrome remembers, and the single place where retain-vs-remember is decided.  *  * The rule, applied once here instead of at ten scattered declarations:  *- *  * **`retain`** for anything the user *chose* — the travel mode, the category filter, which+ *  * **`retain`** for anything the user *chose* — the category filter,  *    whether the camera follows, whether it is north-up. Losing a choice on  *    rotation reads as the app forgetting what you told it, and all but one of these were  *    `remember`, so it did.@@ -34,16 +33,12 @@ import com.vayunmathur.maps.util.RouteService  */ @Stable class MapChromeState internal constructor(-    selectedRouteTypeState: MutableState<RouteService.TravelMode>,     selectedCategoryState: MutableState<MapCategory?>,     autoFollowState: MutableState<Boolean>,     northUpState: MutableState<Boolean>,     postedLimitState: MutableState<PostedLimit?>,     lastProgrammaticMoveMsState: MutableState<Long>, ) {-    /** Which travel mode's route the sheet is showing. */-    var selectedRouteType by selectedRouteTypeState-     /** Active browse-category POI filter, or null for no filter. */     var selectedCategory by selectedCategoryState @@ -82,7 +77,6 @@ class MapChromeState internal constructor( /** The map chrome state for this screen. */ @Composable fun rememberMapChromeState(): MapChromeState {-    val selectedRouteType = retain { mutableStateOf(RouteService.TravelMode.DRIVE) }     val selectedCategory = retain { mutableStateOf<MapCategory?>(null) }     val autoFollow = retain { mutableStateOf(true) }     val northUp = retain { mutableStateOf(false) }@@ -91,7 +85,6 @@ fun rememberMapChromeState(): MapChromeState {      return remember {         MapChromeState(-            selectedRouteTypeState = selectedRouteType,             selectedCategoryState = selectedCategory,             autoFollowState = autoFollow,             northUpState = northUp,
maps/src/test/java/com/vayunmathur/maps/ui/MapsContentBoxC5Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/MapsContentBoxC5Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/MapsContentBoxC5Test.ktindex 0d10f3d2a4..606f879e6a 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/MapsContentBoxC5Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/MapsContentBoxC5Test.kt@@ -72,7 +72,6 @@ class MapsContentBoxC5Test {         val cs = rememberCoroutineScope()         val chrome = remember {             MapChromeState(-                mutableStateOf(RouteService.TravelMode.DRIVE),                 mutableStateOf(null),                 mutableStateOf(true),                 mutableStateOf(false),
maps/src/test/java/com/vayunmathur/maps/ui/SheetRouteStackTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/SheetRouteStackTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/SheetRouteStackTest.ktnew file mode 100644index 0000000000..68b5ab5f70--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/ui/SheetRouteStackTest.kt@@ -0,0 +1,101 @@+package com.vayunmathur.maps.ui++import com.vayunmathur.library.map.GeoPoint+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.maps.SheetRoute+import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.data.google.PoiSection+import com.vayunmathur.maps.directionsTo+import com.vayunmathur.maps.effectiveFeature+import com.vayunmathur.maps.parkedRoutePlan+import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.selectFeature+import com.vayunmathur.maps.util.RouteService+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNull+import kotlin.test.assertTrue++/** Sheet-stack transitions: the navigation the sheet routes replaced. */+class SheetRouteStackTest {++    private fun place(name: String) = SpecificFeature.GenericPlace(+        name, null, null, null, GeoPoint(-122.4, 37.8),+    )++    private fun stack() = NavBackStack<SheetRoute>(arrayOf(SheetRoute.Browse))++    @Test+    fun `directions pushes a plan over the place and back returns to it`() {+        val stack = stack()+        stack.selectFeature(place("Cafe"))+        stack.directionsTo(place("Home"))+        assertTrue(stack.last() is SheetRoute.RoutePlan)+        assertEquals(2, (stack.last() as SheetRoute.RoutePlan).waypoints.size)+        stack.popSheet()+        assertEquals(place("Cafe"), (stack.last() as SheetRoute.Place).feature)+    }++    @Test+    fun `a place tapped over a route parks it and directions appends to it`() {+        val stack = stack()+        stack.selectFeature(place("Cafe"))+        stack.directionsTo(place("Home"))+        stack.selectFeature(place("Park"))+        assertEquals(+            SheetRoute.RoutePlan(listOf(null, place("Home"))),+            stack.backStack.parkedRoutePlan(),+        )+        stack.directionsTo(place("Park"))+        assertEquals(+            listOf(null, place("Home"), place("Park")),+            (stack.last() as SheetRoute.RoutePlan).waypoints,+        )+    }++    @Test+    fun `search pops back to what it covered and a pick replaces the place`() {+        val stack = stack()+        stack.selectFeature(place("Cafe"))+        stack.add(SheetRoute.Search(waypointIndex = null, nearLat = 37.8, nearLon = -122.4))+        stack.popSheet()+        assertEquals(place("Cafe"), (stack.last() as SheetRoute.Place).feature)+        stack.add(SheetRoute.Search())+        stack.selectFeature(place("Bakery"))+        assertEquals(place("Bakery"), (stack.last() as SheetRoute.Place).feature)+        assertEquals(2, stack.backStack.size)+    }++    @Test+    fun `repeated place taps replace in place and the root never pops`() {+        val stack = stack()+        stack.selectFeature(place("A"))+        stack.selectFeature(place("B"))+        assertEquals(2, stack.backStack.size)+        stack.popSheet()+        assertEquals(SheetRoute.Browse, stack.last())+        stack.popSheet()+        assertEquals(SheetRoute.Browse, stack.last())+        assertNull(stack.backStack.effectiveFeature())+    }++    @Test+    fun `route mode and poi section live on their routes`() {+        val stack = stack()+        stack.selectFeature(place("Cafe"))+        stack.setLast((stack.last() as SheetRoute.Place).copy(section = PoiSection.PHOTOS))+        assertEquals(PoiSection.PHOTOS, (stack.last() as SheetRoute.Place).section)+        stack.directionsTo(place("Home"))+        stack.setLast((stack.last() as SheetRoute.RoutePlan).copy(mode = RouteService.TravelMode.WALK))+        assertEquals(RouteService.TravelMode.WALK, (stack.last() as SheetRoute.RoutePlan).mode)+    }++    @Test+    fun `a trip pops back to its departures board`() {+        val stack = stack()+        stack.add(SheetRoute.Departures("s1", "Central", 37.8, -122.4))+        stack.add(SheetRoute.Trip(42L, 37.8, -122.4))+        stack.popSheet()+        assertTrue(stack.last() is SheetRoute.Departures)+    }+}
maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.ktindex e8a0b89487..097ee1b9c1 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt@@ -68,7 +68,6 @@ class Slice3Pass5SheetsTest {             noResultsMessage = "No results",             chrome = remember {                 MapChromeState(-                    mutableStateOf(RouteService.TravelMode.DRIVE),                     mutableStateOf(null),                     mutableStateOf(true),                     mutableStateOf(false),
maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.ktindex 5ba002ca07..1650f9ac97 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt@@ -87,7 +87,6 @@ class WideHostSlice3ExtraTest {             noResultsMessage = "No results",             chrome = remember {                 MapChromeState(-                    mutableStateOf(RouteService.TravelMode.DRIVE),                     mutableStateOf(null),                     mutableStateOf(true),                     mutableStateOf(false),
maps/src/test/java/com/vayunmathur/maps/ui/map/MapChromeStateSlice1Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/map/MapChromeStateSlice1Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/map/MapChromeStateSlice1Test.ktindex 57cc496798..e94a2d404f 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/map/MapChromeStateSlice1Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/map/MapChromeStateSlice1Test.kt@@ -16,7 +16,6 @@ import kotlin.test.assertNull class MapChromeStateSlice1Test {      private fun state() = MapChromeState(-        selectedRouteTypeState = mutableStateOf(RouteService.TravelMode.DRIVE),         selectedCategoryState = mutableStateOf<MapCategory?>(null),         autoFollowState = mutableStateOf(true),         northUpState = mutableStateOf(false),@@ -57,17 +56,14 @@ class MapChromeStateSlice1Test {     @Test     fun `chrome choices start at their documented defaults`() {         val s = state()-        assertEquals(RouteService.TravelMode.DRIVE, s.selectedRouteType)         assertEquals(true, s.autoFollow)         assertEquals(false, s.northUp)         assertNull(s.postedLimit)         assertEquals(0L, s.lastProgrammaticMoveMs)-        s.selectedRouteType = RouteService.TravelMode.TRANSIT         s.autoFollow = false         s.northUp = true         s.postedLimit = PostedLimit(kmh = 50, mph = 30, displayIsMph = false)         s.lastProgrammaticMoveMs = 123L-        assertEquals(RouteService.TravelMode.TRANSIT, s.selectedRouteType)         assertEquals(50, s.postedLimit?.kmh)         assertEquals(123L, s.lastProgrammaticMoveMs)     }
maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2EffectsComposeTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2EffectsComposeTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2EffectsComposeTest.ktindex 8981b88f49..0ea1a12e65 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2EffectsComposeTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2EffectsComposeTest.kt@@ -42,7 +42,6 @@ class Slice1Pass2EffectsComposeTest {     )      private fun chrome(autoFollow: Boolean = true, northUp: Boolean = false) = MapChromeState(-        selectedRouteTypeState = mutableStateOf(com.vayunmathur.maps.util.RouteService.TravelMode.DRIVE),         selectedCategoryState = mutableStateOf(null),         autoFollowState = mutableStateOf(autoFollow),         northUpState = mutableStateOf(northUp),
maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.ktindex 448adb54be..8407146ae4 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/map/Slice1Pass2MapSurfaceProbeTest.kt@@ -37,7 +37,6 @@ class Slice1Pass2MapSurfaceProbeTest {     private val app: Application get() = ApplicationProvider.getApplicationContext()      private fun chrome() = MapChromeState(-        selectedRouteTypeState = mutableStateOf(RouteService.TravelMode.DRIVE),         selectedCategoryState = mutableStateOf(null),         autoFollowState = mutableStateOf(true),         northUpState = mutableStateOf(false),