maps: move place and route selection onto the sheet stack (#nav)
- Commit
09c17308cdd5b4e1008d9364172c4b74fae2acd0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 19:27 UTC (19 days ago)
- Parents
9b8a2a9
M1+M2, the core: _selectedFeature, _inactiveNavigation and stashRouteSelection are deleted from SelectedFeatureViewModel. What is showing is now the top of the SheetRoute stack in MapPage (Place / AdminLabel / RoutePlan over a Browse root), read through effectiveFeature()/parkedRoutePlan() helpers. - Directions pushes RoutePlan over Place; a place tapped while a route is up pushes Place over RoutePlan, and popping returns to the route (the parked route is stack depth). Directions over a parked route appends to it via directionsTo(). - The three stacked BackHandlers (selection, parked route, search, in registration order) become one BackHandler that pops the sheet stack. - currentPoiInfo/routes re-key off the top sheet route, synced into the VM as an engine input (setSheetRoute); routes plans the RoutePlan mode carried in the route. Deep links and the contact shortcut record a pendingPlace on the VM, which MapSheetEffects pushes (and flies to) when composed, and a GenericPlace enrichment is written back onto its stack entry with replaceFeature; the admin-label upgrade replaces the entry in place the same way. - Map taps, waypoint reorder/edit, parking directions, search picks (a waypoint pick rewrites that leg of the plan under the search and pops back to it) and both hosts (compact sheets and the wide side panel now share one onSelectFeature stack interpretation) all transition the stack. The wide and compact layouts render the same stack top through stateless header/content overloads. Tests that drove the VM selection surface now drive the sheet route / stack (toSheetRoute/toFeature, section on the Place route, parked route as RoutePlan under a Place). Verified: :maps:compileDevKotlin and unit-test compilation green; filtered SelectedFeature/ViewModels/SearchActions/ BottomSheetWiring/MapsSelectedFeature test classes pass.
Diff
maps/src/main/java/com/vayunmathur/maps/SheetRoute.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/SheetRoute.kt b/maps/src/main/java/com/vayunmathur/maps/SheetRoute.ktindex 51049baf94..4b263f27b6 100644--- a/maps/src/main/java/com/vayunmathur/maps/SheetRoute.kt+++ b/maps/src/main/java/com/vayunmathur/maps/SheetRoute.kt@@ -149,3 +149,41 @@ fun NavBackStack<SheetRoute>.directionsTo(destination: SpecificFeature.RoutableF fun NavBackStack<SheetRoute>.popSheet() { if (backStack.size > 1) pop() }++/** The destination the VM flows key off: topmost Place/AdminLabel/RoutePlan. */+fun List<SheetRoute>.engineRoute(): SheetRoute? = reversed().firstOrNull {+ it is SheetRoute.Place || it is SheetRoute.AdminLabel || it is SheetRoute.RoutePlan+}++/** Replace the stack entry holding [old] with [replacement], keeping its slot. */+fun NavBackStack<SheetRoute>.replaceFeature(old: SpecificFeature, replacement: SpecificFeature) {+ val index = backStack.indexOfFirst { route ->+ (route is SheetRoute.Place && route.feature === old) ||+ (route is SheetRoute.AdminLabel && route.feature === old)+ }+ if (index < 0) return+ val current = backStack[index]+ set(+ index,+ when (current) {+ is SheetRoute.Place -> SheetRoute.Place(replacement, current.section)+ else -> SheetRoute.AdminLabel(replacement)+ },+ )+}++/** The feature a single route shows, or null for Browse/dialog/search. */+fun SheetRoute?.toFeature(): SpecificFeature? = when (this) {+ is SheetRoute.Place -> feature+ is SheetRoute.AdminLabel -> feature+ is SheetRoute.RoutePlan -> SpecificFeature.Route(waypoints)+ else -> null+}++/** The sheet route that shows [this] feature. */+fun SpecificFeature.toSheetRoute(): SheetRoute = when (this) {+ is SpecificFeature.Route -> SheetRoute.RoutePlan(waypoints)+ is SpecificFeature.Admin0Label, is SpecificFeature.Admin1Label, is SpecificFeature.Admin2Label ->+ SheetRoute.AdminLabel(this)+ else -> SheetRoute.Place(this)+}
maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.ktindex c1a41005dc..058ceea1e1 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/BottomSheetContent.kt@@ -4,6 +4,8 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier@@ -49,11 +51,12 @@ fun BottomSheetContent( navState: NavigationSessionManager.NavState = NavigationSessionManager.NavState.Idle, openDepartures: ((Double, Double) -> Unit)? = null, ) {- val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel)+ var section by androidx.compose.runtime.saveable.rememberSaveable { androidx.compose.runtime.mutableStateOf(PoiSection.DETAILS) }+ val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel, section) val panelActions = remember(selectedFeature) { object : PlacePanelActions {- override fun setPoiSection(section: PoiSection) {- viewModel.setPoiSection(section)+ override fun setPoiSection(s: PoiSection) {+ section = s } override fun addSaved() { (selectedFeature as? SpecificFeature.RoutableFeature)?.let {
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 ae48216f1f..b3df8b1d8d 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapContentBox.kt@@ -33,6 +33,8 @@ import com.vayunmathur.maps.ui.map.MapChromeState import com.vayunmathur.maps.ui.map.MapFabStack import com.vayunmathur.maps.SheetRoute import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.selectFeature+import com.vayunmathur.maps.directionsTo import com.vayunmathur.maps.ui.map.MapOverlays import com.vayunmathur.maps.ui.map.MapSurface import com.vayunmathur.maps.ui.map.NavigationCameraFollow@@ -168,7 +170,7 @@ internal fun MapPageScope.MapContentBox( if (routeFeature != null) { WaypointList( route = routeFeature,- onReorder = { viewModel.set(it) },+ onReorder = { sheetStack.selectFeature(it) }, onEditWaypoint = { index -> openSearch(null, index) }, ) } else {@@ -296,8 +298,7 @@ internal fun MapPageScope.MapContentBox( if (spot != null) { val feature = spot.toFeature(context.getString(MapsR.string.parking_title)) sheetStack.popSheet()- viewModel.stashRouteSelection()- viewModel.set(SpecificFeature.Route(listOf(null, feature)))+ sheetStack.selectFeature(SpecificFeature.Route(listOf(null, feature))) } }, onParkingNoteChange = { parkingViewModel.updateNote(it) },
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 836e872068..4be6b15900 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -46,6 +46,10 @@ import com.vayunmathur.maps.ui.map.rememberInitialCamera import com.vayunmathur.maps.Route import com.vayunmathur.maps.SheetRoute import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.effectiveFeature+import com.vayunmathur.maps.engineRoute+import com.vayunmathur.maps.parkedRoutePlan+import com.vayunmathur.maps.routePlan import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.maps.data.ParkingSpot import com.vayunmathur.maps.data.SpecificFeature@@ -138,22 +142,24 @@ fun MapPage( } } - val selectedFeature by viewModel.selectedFeature.collectAsState()- // Keep the router's plan order on the visible tab: routes plans the- // selected mode first, so a tab switch made before the flow restarts must- // still reach it. A plain assignment (not a flow input) so switching tabs- // never re-plans every mode — the flow restarts on selection change only.- val selectedRouteType = chrome.selectedRouteType- LaunchedEffect(selectedRouteType) {- viewModel.selectedRouteMode = selectedRouteType+ // What is showing is the top of the sheet stack; the VM only mirrors+ // the engine route (place to enrich / waypoints to plan) from it.+ val selectedFeature = sheetStack.backStack.effectiveFeature()+ val parkedRoutePlan = sheetStack.backStack.parkedRoutePlan()+ val inactiveNavigation = parkedRoutePlan?.let { SpecificFeature.Route(it.waypoints) }+ LaunchedEffect(sheetStack.backStack.toList()) {+ viewModel.setSheetRoute(sheetStack.backStack.engineRoute()) }- val inactiveNavigation by viewModel.inactiveNavigation.collectAsState()+ // 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 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 // each change the sheet's content height, and without them in the key the // learned ceiling from Details traps the taller Reviews list.- val poiSection by viewModel.poiSection.collectAsState()+ val poiSection = (sheetTop as? SheetRoute.Place)?.section ?: PoiSection.DETAILS val currentPoiInfo by viewModel.currentPoiInfo.collectAsState() val userPosition by viewModel.userPosition.collectAsState() val userBearing by viewModel.userBearing.collectAsState()@@ -249,15 +255,14 @@ fun MapPage( recents = searchRecents, searching = searching, )- val browsing = selectedFeature == null && inactiveNavigation == null && !isNavigating+ val browsing = selectedFeature == null && !isNavigating // The bar is chrome, not a sheet, so it is composed away rather than animated out. Its // measured height therefore has to be discounted explicitly — a stale one would leave the // FAB stack floating above a bar that is no longer there. val searchBarVisible = browsing && searchRoute == null // Expanded widths show this content in the side panel instead of a sheet. val panelSearch = wide && searchRoute != null- val panelPlace = wide && searchRoute == null &&- (selectedFeature != null || route != null || inactiveNavigation != null)+ val panelPlace = wide && searchRoute == null && selectedFeature != null fun openSearch(query: String? = null, waypointIndex: Int? = null) { val near = com.vayunmathur.maps.util.searchBiasPoint(camera.visibleBoundsOrWorld(), userPosition) if (!query.isNullOrBlank()) searchViewModel.setQuery(query, near.latitude, near.longitude)@@ -282,6 +287,7 @@ fun MapPage( searchRequest = searchRoute, searchViewModel = searchViewModel, viewModel = viewModel,+ sheetStack = sheetStack, coroutineScope = coroutineScope, onCloseSearch = { sheetStack.popSheet() }, )@@ -304,6 +310,15 @@ fun MapPage( inactiveNavigation = inactiveNavigation, route = route, poiSection = poiSection,+ onPoiSection = { section ->+ (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+ },+ selectedRouteType = selectedRouteType, poiEnrichmentKey = PoiEnrichmentKey.of(currentPoiInfo), userPosition = userPosition, userBearing = userBearing,
maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.ktindex 07adf91157..b00635be4a 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPageScope.kt@@ -94,6 +94,9 @@ internal class MapPageScope( * a sheet opened on Details keeps its low learned ceiling on Reviews. */ val poiSection: PoiSection,+ val onPoiSection: (PoiSection) -> Unit = {},+ val onRouteMode: (RouteService.TravelMode) -> Unit = {},+ val selectedRouteType: RouteService.TravelMode = RouteService.TravelMode.DRIVE, /** * Coarse enrichment signature for the inner place sheet's contentKey. * Late-arriving reviews/photos grow the content after measurement, which
maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.ktindex ed01f9f817..f772d8d144 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchActions.kt@@ -3,6 +3,7 @@ package com.vayunmathur.maps.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.selectFeature import com.vayunmathur.maps.util.MapsSearchViewModel import com.vayunmathur.maps.util.SearchActions import com.vayunmathur.maps.util.SearchResult@@ -21,6 +22,7 @@ internal fun rememberSearchActions( searchViewModel: MapsSearchViewModel, viewModel: SelectedFeatureViewModel, coroutineScope: CoroutineScope,+ sheetStack: com.vayunmathur.library.util.NavBackStack<com.vayunmathur.maps.SheetRoute>? = null, onCloseSearch: () -> Unit, ): SearchActions? { val openRequest = searchRequest ?: return null@@ -42,25 +44,37 @@ internal fun rememberSearchActions( coroutineScope.launch { val feature = searchViewModel.toFeature(result) val index = openRequest.waypointIndex- // The selection can have changed under the sheet — the map is live —- // so tolerate a non-Route current selection rather than crashing.- val current = viewModel.selectedFeature.value- if (index != null && current is SpecificFeature.Route) {- viewModel.set(- current.copy(- waypoints = current.waypoints.mapIndexed { i, waypoint ->- if (i == index) feature else waypoint+ // Editing a waypoint: rewrite that leg of the plan under+ // the search sheet, then pop back to it.+ val planIndex = sheetStack?.backStack?.indexOfLast {+ it is com.vayunmathur.maps.SheetRoute.RoutePlan+ } ?: -1+ val plan = sheetStack?.backStack?.getOrNull(planIndex)+ as? com.vayunmathur.maps.SheetRoute.RoutePlan+ if (index != null && plan != null && sheetStack != null) {+ sheetStack.set(+ planIndex,+ plan.copy(+ waypoints = plan.waypoints.mapIndexed { i, waypoint ->+ if (i == index) feature as SpecificFeature.RoutableFeature else waypoint }, ), )+ onCloseSearch() } else { // Focus as well as select: without the camera move a // distant result opened its card over a map still // showing somewhere else (and any region mask with // it off-screen). selectAndFocus is the same path // deep links use.- viewModel.selectAndFocus(feature)- onCloseSearch()+ if (sheetStack != null) {+ onCloseSearch()+ sheetStack.selectFeature(feature)+ viewModel.focusFeature(feature)+ } else {+ viewModel.selectAndFocus(feature)+ onCloseSearch()+ } } } }
maps/src/main/java/com/vayunmathur/maps/ui/MapSearchBarSection.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchBarSection.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchBarSection.ktindex 0e18971144..1197dce731 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchBarSection.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSearchBarSection.kt@@ -31,9 +31,9 @@ internal fun MapPageScope.MapSearchBarSection( val near = searchBiasPoint(camera.visibleBoundsOrWorld(), userPosition) searchViewModel.resolveAndSelect(address, near.latitude, near.longitude) { place -> if (place != null) {- viewModel.stashRouteSelection() // Fly there and open the peek pane, the same direct-open- // path a geo:/maps deep link takes.+ // path a geo:/maps deep link takes (pendingPlace is+ // pushed on the sheet stack by MapSheetEffects). viewModel.selectAndFocus( place, zoom = (camera.position.zoom).coerceAtLeast(14.0),
maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.ktindex 751eea1524..f85e42414f 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheetEffects.kt@@ -18,6 +18,10 @@ import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.library.ui.R as UiR import com.vayunmathur.maps.Route import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.effectiveFeature+import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.replaceFeature+import com.vayunmathur.maps.selectFeature import com.vayunmathur.maps.util.MapsSearchViewModel import com.vayunmathur.maps.util.SelectedFeatureViewModel import kotlinx.coroutines.launch@@ -54,6 +58,25 @@ internal fun MapSheetEffects( } } + // A place requested by a non-composition caller (deep link, contact+ // shortcut) is pushed on the stack here; the focus effect below flies.+ val pendingPlace by viewModel.pendingPlace.collectAsState()+ LaunchedEffect(pendingPlace) {+ val feature = pendingPlace ?: return@LaunchedEffect+ sheetStack.selectFeature(feature)+ viewModel.consumePendingPlace()+ }++ // Offline enrichment of a bare GenericPlace, written back onto its+ // stack entry (the choke point the ViewModel selection used to be).+ LaunchedEffect(selectedFeature) {+ val place = selectedFeature as? SpecificFeature.GenericPlace ?: return@LaunchedEffect+ val enriched = viewModel.enrichedOrNull(place) ?: return@LaunchedEffect+ if (sheetStack.backStack.effectiveFeature() === place) {+ sheetStack.replaceFeature(place, enriched)+ }+ }+ // Contact-address auto-select and external geo:/maps deep links land here. A StateFlow-backed // request survives a cold start, so a link that selected a place before the map composed // still animates and peeks once it is ready.@@ -74,7 +97,7 @@ internal fun MapSheetEffects( // admin label of the same name at this spot when one is linked — // the mask and admin card follow from the selection as they do // for a tapped label. No name match, no upgrade.- val place = viewModel.selectedFeature.value as? SpecificFeature.GenericPlace+ val place = sheetStack.backStack.effectiveFeature() as? SpecificFeature.GenericPlace ?: return@LaunchedEffect val projection = camera.projection ?: return@LaunchedEffect val centre = runCatching {@@ -101,8 +124,8 @@ internal fun MapSheetEffects( val upgrade = com.vayunmathur.maps.ui.map.adminUpgradeFor(place, parsed) // The selection may have moved on while parsing; only upgrade the // exact selection this focus was for.- if (upgrade != null && viewModel.selectedFeature.value === place) {- viewModel.set(upgrade)+ if (upgrade != null && sheetStack.backStack.effectiveFeature() === place) {+ sheetStack.replaceFeature(place, upgrade) } } @@ -134,7 +157,7 @@ internal fun MapSheetEffects( } else if (searchWasOpen) { searchWasOpen = false launch { searchSheetState?.hide() }- if (viewModel.selectedFeature.value != null) sheetState?.partialExpand()+ if (sheetStack.backStack.effectiveFeature() != null) sheetState?.partialExpand() } } @@ -147,21 +170,13 @@ internal fun MapSheetEffects( } } - // Clearing the selection is enough: the `LaunchedEffect(selectedFeature)` above is the single- // dismissal path for every sheet state, so back does not hide the sheet itself. Doing both- // raced two `hide()` coroutines against each other for no benefit.- BackHandler(selectedFeature != null) {- viewModel.set(null)- }-- BackHandler(selectedFeature == null && inactiveNavigation != null) {- viewModel.setInactiveNavigation(null)- }-- // Registered last so it wins: back out of search before back does anything to the selection- // the search sheet is currently covering.- BackHandler(searchRequest != null) {- sheetStack.pop()+ // One back handler for the whole sheet stack: search pops back to the+ // place/route it covered, a place over a parked route pops back to the+ // route, a route pops back to its place, and Browse lets the outer+ // graph handle back. The old three stacked handlers were this stack+ // spelled out in registration order.+ BackHandler(sheetStack.backStack.size > 1) {+ sheetStack.popSheet() } }
maps/src/main/java/com/vayunmathur/maps/ui/MapSheets.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheets.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheets.ktindex 3dda7a21f2..e6ef810293 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapSheets.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapSheets.kt@@ -10,7 +10,14 @@ import com.vayunmathur.library.ui.FreeHeightBottomSheetScaffold import com.vayunmathur.library.ui.Spacing import com.vayunmathur.maps.ui.theme.MapChromeMetrics import com.vayunmathur.maps.util.SearchActions+import com.vayunmathur.maps.directionsTo+import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.selectFeature+import com.vayunmathur.maps.util.PlacePanelActions+import com.vayunmathur.maps.util.rememberPlacePanelState+import androidx.compose.runtime.remember import com.vayunmathur.maps.util.SearchUiState+import com.vayunmathur.maps.data.SpecificFeature /** * The compact bottom sheets: search over place, both wrapping the shared map@@ -73,18 +80,18 @@ internal fun MapPageScope.MapSheets( // Padding only when there is something to pad. An unconditional wrapper measures its // own padding even with no content, which defeats the scaffold's "don't place a sheet // that measured to nothing" guard and leaves a bare handle on screen.- if (selectedFeature != null || route != null || inactiveNavigation != null) {+ if (selectedFeature != null) {+ val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel, poiSection)+ val panelActions = rememberPanelActions() Column(Modifier.padding(horizontal = Spacing.lg).padding(top = Spacing.sm)) { BottomSheetContent(- viewModel,- selectedFeature,- route,- chrome.selectedRouteType,- { chrome.selectedRouteType = it },- savedPlacesViewModel,- transitViewModel,- navState,- openDepartures = { lat, lon -> pushDepartures(lat, lon, null) },+ panelState = panelState,+ panelActions = panelActions,+ selectedFeature = selectedFeature,+ route = route,+ selectedRouteType = selectedRouteType,+ setSelectedRouteType = onRouteMode,+ navState = navState, ) } }@@ -96,13 +103,15 @@ internal fun MapPageScope.MapSheets( // peeks at exactly its title through its action row whatever the font scale. A // selection with no header falls back to the fixed height. sheetHeader = {+ val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel, poiSection)+ val panelActions = rememberPanelActions() BottomSheetHeader(- viewModel,- selectedFeature,- { viewModel.set(it) },- inactiveNavigation,- savedPlacesViewModel,- Modifier.padding(horizontal = Spacing.lg).padding(top = Spacing.sm),+ panelState = panelState,+ panelActions = panelActions,+ selectedFeature = selectedFeature,+ setSelectedFeature = onSelectFeature(),+ inactiveNavigation = inactiveNavigation,+ modifier = Modifier.padding(horizontal = Spacing.lg).padding(top = Spacing.sm), ) }, // The selection, the route-type, the POI tab AND the enrichment@@ -113,9 +122,43 @@ internal fun MapPageScope.MapSheets( // Coarse (counts/presence, not the lists) so progressive streaming // settles the key instead of resetting it on every partial. Wide // layout has no sheet (MapSidePanel) and needs no key.- contentKey = listOf(selectedFeature, chrome.selectedRouteType, poiSection, poiEnrichmentKey),+ contentKey = listOf(selectedFeature, selectedRouteType, poiSection, poiEnrichmentKey), ) { _ -> MapContentBox(Modifier.fillMaxSize()) } } }++/** Panel actions binding the sheet-stack setters for this host. */[email protected]+internal fun MapPageScope.rememberPanelActions(): PlacePanelActions {+ val feature = selectedFeature+ return remember(feature, sheetStack) {+ object : PlacePanelActions {+ override fun setPoiSection(section: com.vayunmathur.maps.data.google.PoiSection) {+ onPoiSection(section)+ }+ override fun addSaved() {+ (feature as? SpecificFeature.RoutableFeature)?.let { savedPlacesViewModel.addSaved(it) }+ }+ override fun removeSaved(place: com.vayunmathur.maps.data.SavedPlace) {+ savedPlacesViewModel.removeSaved(place)+ }+ override fun openNearestStop(lat: Double, lon: Double) {+ pushDepartures(lat, lon, null)+ }+ }+ }+}++/** Interpret a header/content selection callback as a stack transition. */+internal fun MapPageScope.onSelectFeature(): (SpecificFeature?) -> Unit = { feature ->+ when {+ feature == null -> sheetStack.popSheet()+ feature is SpecificFeature.Route -> {+ val dest = feature.waypoints.lastOrNull()+ if (dest != null) sheetStack.directionsTo(dest) else sheetStack.selectFeature(feature)+ }+ else -> sheetStack.selectFeature(feature)+ }+}
maps/src/main/java/com/vayunmathur/maps/ui/MapWideHost.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapWideHost.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapWideHost.ktindex 6ffb792a1c..acfc38fdd4 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapWideHost.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapWideHost.kt@@ -25,6 +25,8 @@ import com.vayunmathur.maps.R as MapsR import com.vayunmathur.maps.data.ParkingSpot import com.vayunmathur.maps.data.SavedPlace import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.SheetRoute+import com.vayunmathur.maps.popSheet import com.vayunmathur.maps.data.google.PoiSection import com.vayunmathur.maps.ui.map.LayerToggles import com.vayunmathur.maps.ui.map.MapChromeState@@ -70,25 +72,8 @@ internal fun MapPageScope.MapWideHost( panelSearch: Boolean, panelPlace: Boolean, ) {- val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel)- val panelActions: PlacePanelActions = remember(selectedFeature) {- object : PlacePanelActions {- override fun setPoiSection(section: PoiSection) {- viewModel.setPoiSection(section)- }- override fun addSaved() {- (selectedFeature as? SpecificFeature.RoutableFeature)?.let {- savedPlacesViewModel.addSaved(it)- }- }- override fun removeSaved(place: SavedPlace) {- savedPlacesViewModel.removeSaved(place)- }- override fun openNearestStop(lat: Double, lon: Double) {- pushDepartures(lat, lon, null)- }- }- }+ val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel, poiSection)+ val panelActions = rememberPanelActions() val panelContent: (@Composable (Modifier) -> Unit)? = when { panelSearch && searchActions != null -> { modifier -> MapSidePanel(@@ -98,13 +83,13 @@ internal fun MapPageScope.MapWideHost( panelState = panelState, panelActions = panelActions, selectedFeature = selectedFeature,- onSelectFeature = { viewModel.set(it) },+ onSelectFeature = onSelectFeature(), route = route,- selectedRouteType = chrome.selectedRouteType,- onSelectedRouteType = { chrome.selectedRouteType = it },+ selectedRouteType = selectedRouteType,+ onSelectedRouteType = onRouteMode, inactiveNavigation = inactiveNavigation, navState = navState,- onClosePanel = { viewModel.set(null) },+ onClosePanel = { sheetStack.popSheet() }, modifier = modifier, ) }@@ -116,16 +101,13 @@ internal fun MapPageScope.MapWideHost( panelState = panelState, panelActions = panelActions, selectedFeature = selectedFeature,- onSelectFeature = { viewModel.set(it) },+ onSelectFeature = onSelectFeature(), route = route,- selectedRouteType = chrome.selectedRouteType,- onSelectedRouteType = { chrome.selectedRouteType = it },+ selectedRouteType = selectedRouteType,+ onSelectedRouteType = onRouteMode, inactiveNavigation = inactiveNavigation, navState = navState,- onClosePanel = {- viewModel.set(null)- viewModel.setInactiveNavigation(null)- },+ onClosePanel = { sheetStack.reset(SheetRoute.Browse) }, modifier = modifier, ) }
maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.ktindex 874804be6c..f65db690e9 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt@@ -37,6 +37,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue+import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape@@ -91,7 +92,7 @@ fun PlaceSheet( modifier: Modifier = Modifier, ) { val poi by viewModel.currentPoiInfo.collectAsState()- val selectedSection by viewModel.poiSection.collectAsState()+ var selectedSection by rememberSaveable { mutableStateOf(PoiSection.DETAILS) } PlaceSheetContent( poi = poi, selectedSection = selectedSection,@@ -109,7 +110,7 @@ fun PlaceSheet( onDepartures: (() -> Unit)? = null, ) { val poi by viewModel.currentPoiInfo.collectAsState()- val selectedSection by viewModel.poiSection.collectAsState()+ var selectedSection by rememberSaveable { mutableStateOf(PoiSection.DETAILS) } PlaceSheetContent( poi = poi, selectedSection = selectedSection,
maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheetHeader.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheetHeader.kt b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheetHeader.ktindex 68cba943b1..9372e2904c 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheetHeader.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheetHeader.kt@@ -15,6 +15,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import androidx.compose.runtime.setValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier@@ -141,11 +142,12 @@ private fun PlaceSheetHeaderContent( website: String?, requestDirections: () -> Unit, ) {- val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel)+ var section by androidx.compose.runtime.saveable.rememberSaveable { androidx.compose.runtime.mutableStateOf(PoiSection.DETAILS) }+ val panelState = rememberPlacePanelState(viewModel, savedPlacesViewModel, section) val panelActions = remember(feature) { object : PlacePanelActions {- override fun setPoiSection(section: PoiSection) {- viewModel.setPoiSection(section)+ override fun setPoiSection(s: PoiSection) {+ section = s } override fun addSaved() { savedPlacesViewModel.addSaved(feature)
maps/src/main/java/com/vayunmathur/maps/ui/map/MapInitialCamera.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapInitialCamera.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapInitialCamera.ktindex 283b4bf402..01cb254f25 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapInitialCamera.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapInitialCamera.kt@@ -53,7 +53,8 @@ fun rememberInitialCamera(viewModel: SelectedFeatureViewModel): CameraState { ) val userPosition by viewModel.userPosition.collectAsState()- val selectedFeature by viewModel.selectedFeature.collectAsState()+ val sheetRoute by viewModel.sheetRoute.collectAsState()+ val selectedFeature = sheetRoute val pendingFocus by viewModel.pendingFocus.collectAsState() var centeredOnFix by remember { mutableStateOf(false) } LaunchedEffect(userPosition, selectedFeature, pendingFocus) {
maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.ktindex 47b61f95ea..76767f6421 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurface.kt@@ -28,6 +28,7 @@ import com.vayunmathur.maps.data.SpecificFeature import com.vayunmathur.maps.data.osmPlace import com.vayunmathur.maps.data.transit.TransitStop import com.vayunmathur.maps.SheetRoute+import com.vayunmathur.maps.selectFeature import com.vayunmathur.library.util.NavBackStack import com.vayunmathur.maps.ipc.FamilyMember import com.vayunmathur.maps.ui.map.MapFeaturePicker.Companion.NATIVE_LABEL_LAYER_IDS@@ -240,7 +241,6 @@ fun MapSurface( is MapHit.Stop -> { // Whatever place sheet was up is replaced, not stacked under: one tap // should take one back to undo, and a board over a stale sheet takes two.- viewModel.set(null) sheetStack?.reset(SheetRoute.Browse, SheetRoute.Departures(hit.stop.id, hit.stop.name, hit.stop.lat, hit.stop.lon)) return@launch }@@ -249,13 +249,11 @@ fun MapSurface( // baked stop and open its board instead of selecting the POI. val station = hit.feature as? SpecificFeature.GenericPlace if (station?.poiType == STATION_POI_TYPE) {- viewModel.set(null) val stop = transitViewModel.resolveNearestStop(station.position.latitude, station.position.longitude) sheetStack?.reset(SheetRoute.Browse, SheetRoute.Departures(stop.id, stop.name, stop.lat, stop.lon)) return@launch }- viewModel.stashRouteSelection()- viewModel.set(hit.feature)+ sheetStack?.selectFeature(hit.feature) // Compact only: in wide the side panel reads the selection // directly, and a null state means the sheets never open. sheetState?.partialExpand()@@ -274,7 +272,6 @@ fun MapSurface( // A transit stop carries no stop id, so its tap opens the nearest baked // stop's departure board rather than a place sheet. if (PoiCategories.opensDepartureBoard(poi.kind)) {- viewModel.set(null) val stop = transitViewModel.resolveNearestStop(poi.position.latitude, poi.position.longitude, poi.name.ifBlank { null }) sheetStack?.reset(SheetRoute.Browse, SheetRoute.Departures(stop.id, stop.name, stop.lat, stop.lon)) return@launch@@ -282,8 +279,7 @@ fun MapSurface( // The archive carries a POI's kind, name and point and nothing else, so // phone, website, hours and address are still joined from the offline // index on IO inside `osmPlace`.- viewModel.stashRouteSelection()- viewModel.set(osmPlace(poi.name, poi.position, poiType = type))+ sheetStack?.selectFeature(osmPlace(poi.name, poi.position, poiType = type)) sheetState?.partialExpand() return@launch }@@ -306,8 +302,7 @@ fun MapSurface( ).mapNotNull { it.toFeature1() } ) if (label != null) {- viewModel.stashRouteSelection()- viewModel.set(label)+ sheetStack?.selectFeature(label) sheetState?.partialExpand() return@launch }@@ -326,8 +321,7 @@ fun MapSurface( val geo = click.position searchViewModel.reverseGeocode(geo.latitude, geo.longitude) { place -> if (place != null) {- viewModel.stashRouteSelection()- viewModel.set(place)+ sheetStack?.selectFeature(place) coroutineScope.launch { sheetState?.partialExpand() } } }
maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.ktindex 0b596a003e..7553febbf5 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/map/MapSurfaceHelpers.kt@@ -288,7 +288,6 @@ internal suspend fun openVehicleTrip( sheetStack: com.vayunmathur.library.util.NavBackStack<com.vayunmathur.maps.SheetRoute>? = null, ): Boolean { val marker = pickVehicle(vehicles, projection, offset) ?: return false- viewModel.set(null) if (sheetStack != null) { sheetStack.reset(com.vayunmathur.maps.SheetRoute.Browse, com.vayunmathur.maps.SheetRoute.Trip(marker.id, marker.position.latitude, marker.position.longitude)) } else {
maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt b/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.ktindex 5ff45fd2e5..a59829d3a2 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/PlacePanelState.kt@@ -60,9 +60,9 @@ interface PlacePanelActions { fun rememberPlacePanelState( viewModel: SelectedFeatureViewModel, savedPlacesViewModel: SavedPlacesViewModel,+ poiSection: PoiSection = PoiSection.DETAILS, ): PlacePanelState { val poi by viewModel.currentPoiInfo.collectAsState()- val poiSection by viewModel.poiSection.collectAsState() val saved by savedPlacesViewModel.saved.collectAsState() val userPosition by viewModel.userPosition.collectAsState() return PlacePanelState(
maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.ktindex aa5aec94f8..a15668600b 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/SelectedFeatureViewModel.kt@@ -9,7 +9,8 @@ import com.vayunmathur.maps.data.osmPlace import com.vayunmathur.maps.data.google.GooglePoiDataSource import com.vayunmathur.maps.data.google.GooglePoiInfo import com.vayunmathur.maps.data.parse-import com.vayunmathur.maps.data.google.PoiSection+import com.vayunmathur.maps.SheetRoute+import com.vayunmathur.maps.effectiveFeature import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow@@ -30,37 +31,27 @@ import com.vayunmathur.maps.data.MapPreferences /** Selected Feature View Model: a application implementation for selected feature view model. */ class SelectedFeatureViewModel(application: Application): AndroidViewModel(application) {- private val _selectedFeature = MutableStateFlow<SpecificFeature?>(null)- val selectedFeature = _selectedFeature.asStateFlow()-- private val _inactiveNavigation = MutableStateFlow<SpecificFeature.Route?>(null)- val inactiveNavigation = _inactiveNavigation.asStateFlow()- /**- * Which of the place sheet's Details / Photos / Reviews tabs is showing.- *- * On the ViewModel rather than remembered in the sheet because the tab row and the panel it- * switches are no longer the same composable: the row is part of the sheet's measured header,- * so that it is visible at the peek and the other tabs are discoverable without expanding,- * and the panel is below the fold. Two sibling slots cannot share a `remember`, and this is- * selection-scoped state that already has a home — which also means the reset lives with the- * selection it belongs to instead of a `remember(key)` in the UI.+ * The sheet-stack destination the derived flows are keyed off: the top+ * Place/AdminLabel/RoutePlan of the MapPage sheet stack, synced from+ * composition by MapPage. This is an engine input (which place to+ * enrich, which waypoints to plan), not selection state — the stack+ * in the UI owns what is showing. */- private val _poiSection = MutableStateFlow(PoiSection.DETAILS)- val poiSection = _poiSection.asStateFlow()+ private val _sheetRoute = MutableStateFlow<SheetRoute?>(null)+ val sheetRoute = _sheetRoute.asStateFlow() - fun setPoiSection(section: PoiSection) {- _poiSection.value = section+ fun setSheetRoute(route: SheetRoute?) {+ _sheetRoute.value = route } - /**- * The route tab the sheet is showing (DRIVE by default). Read once per- * selection by [routes] so the visible tab's mode plans first; the flow- * restarts on the next selection change anyway, so this is a plain var- * rather than a collected flow (collecting it would re-plan every mode- * on each tab switch). Synced from the chrome tab in MapPage.- */- var selectedRouteMode: RouteService.TravelMode = RouteService.TravelMode.DRIVE+ /** A place a non-composition caller (deep link, contact shortcut) asked to open. */+ private val _pendingPlace = MutableStateFlow<SpecificFeature?>(null)+ val pendingPlace = _pendingPlace.asStateFlow()++ fun consumePendingPlace() {+ _pendingPlace.value = null+ } private companion object { /**@@ -159,31 +150,16 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli } /**- * The single choke point every selection flows through. Most selection paths construct a bare- * `GenericPlace(name, null, null, null, pos)` and bypass the `poi_attrs.bin` sidecar lookup,- * so an unenriched place is re-enriched here: the sheet opens instantly with the title, then- * the OSM fields (hours, phone, website, address) fill in when the lookup lands.- *- * The identity check keeps a slow lookup from overwriting a newer selection, and the enriched- * write goes through [setDirect] rather than [set] so it cannot recurse. Restaurants already- * carry their OSM fields from their own construction path and are left alone.+ * Enrich a bare [SpecificFeature.GenericPlace] from the offline sidecar,+ * or null when it already carries OSM fields or the lookup finds none.+ * The caller (the sheet-stack host) writes the result back onto the+ * stack entry it came from. */- fun set(feature: SpecificFeature?) {- setDirect(feature)- val place = feature as? SpecificFeature.GenericPlace ?: return- if (!needsEnrichment(place)) return- viewModelScope.launch {- val enriched = runCatching { osmPlace(place.name, place.position, place.poiType) }.getOrNull()- ?: return@launch- if (hasAnyOsmField(enriched) && _selectedFeature.value === feature) {- setDirect(enriched)- }- }- }-- private fun setDirect(feature: SpecificFeature?) {- _selectedFeature.value = feature- _poiSection.value = PoiSection.DETAILS+ suspend fun enrichedOrNull(place: SpecificFeature.GenericPlace): SpecificFeature.GenericPlace? {+ if (!needsEnrichment(place)) return null+ val enriched = runCatching { osmPlace(place.name, place.position, place.poiType) }.getOrNull()+ ?: return null+ return enriched.takeIf { hasAnyOsmField(it) } } private fun needsEnrichment(place: SpecificFeature.GenericPlace): Boolean =@@ -199,8 +175,14 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli * intent handler (geo:/maps links). Selecting a [SpecificFeature.RoutableFeature] * triggers [currentPoiInfo] enrichment so the pane fills with details. */+ /** Ask the map to fly to [feature] without changing the sheet stack. */+ fun focusFeature(feature: SpecificFeature, zoom: Double? = null) {+ val pos = (feature as? SpecificFeature.RoutableFeature)?.position+ _pendingFocus.value = pos?.let { PlaceFocus(it, zoom) }+ }+ fun selectAndFocus(feature: SpecificFeature, zoom: Double? = null) {- set(feature)+ _pendingPlace.value = feature val pos = (feature as? SpecificFeature.RoutableFeature)?.position _pendingFocus.value = pos?.let { PlaceFocus(it, zoom) } }@@ -210,22 +192,6 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli _pendingFocus.value = null } - fun setInactiveNavigation(route: SpecificFeature.Route?) {- _inactiveNavigation.value = route- }-- /**- * Park the current route, if the selection is one, before selecting something else.- *- * Tapping a place while directions are up should keep the route recoverable rather than- * discard it, which is why every such tap handler did this. They each did it with an- * unchecked `as SpecificFeature.Route` guarded by a separate `is` check, so the cast was- * only safe by inspection; reading the selection once here makes it safe by construction.- */- fun stashRouteSelection() {- (_selectedFeature.value as? SpecificFeature.Route)?.let { _inactiveNavigation.value = it }- }- /** * Resolve the first basemap place label that parses, or null. *@@ -251,9 +217,10 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli * touching the network — zero Google traffic. */ @OptIn(ExperimentalCoroutinesApi::class)- val currentPoiInfo: StateFlow<GooglePoiInfo?> = selectedFeature- .flatMapLatest { feature ->+ val currentPoiInfo: StateFlow<GooglePoiInfo?> = sheetRoute+ .flatMapLatest { route -> if (!googleServicesEnabled()) return@flatMapLatest flowOf(null)+ val feature = (route as? SheetRoute.Place)?.feature val (name, pos) = when (feature) { is SpecificFeature.Restaurant -> feature.name to feature.position is SpecificFeature.GenericPlace -> feature.name to feature.position@@ -279,19 +246,20 @@ class SelectedFeatureViewModel(application: Application): AndroidViewModel(appli // `scan`, and every emission re-resolved the route overlay/traffic tables // and re-pushed to the renderer. The remaining modes compute lazily off // the critical path and arrive in a single coalesced map. [selectedRouteMode]- // is read once per selection (not collected): the flow restarts on the- // next selection change anyway, and collecting the tab here would re-plan- // every mode on each tab switch.+ // is read once per route-plan change (not collected): the flow restarts+ // on the next plan change anyway, and collecting the tab here would+ // re-plan every mode on each tab switch. // // The scan seed: one null per travel mode, merged over as each plan lands. private fun emptyRoutes(): Map<RouteService.TravelMode, RouteService.RouteType?> = RouteService.TravelMode.entries.associateWith { null as RouteService.RouteType? } @OptIn(ExperimentalCoroutinesApi::class)- val routes = selectedFeature- .flatMapLatest { feature ->+ val routes = sheetRoute+ .flatMapLatest { route -> val pos = userPosition.value- val selectedMode = selectedRouteMode- val routeFeature = feature as? SpecificFeature.Route ?: return@flatMapLatest flowOf(null)+ val plan = route as? SheetRoute.RoutePlan ?: return@flatMapLatest flowOf(null)+ val selectedMode = plan.mode+ val routeFeature = SpecificFeature.Route(plan.waypoints) flow { emit(emptyMap())
maps/src/test/java/com/vayunmathur/maps/MainActivitySlice3Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/MainActivitySlice3Test.kt b/maps/src/test/java/com/vayunmathur/maps/MainActivitySlice3Test.ktindex 5054b35441..7c76358503 100644--- a/maps/src/test/java/com/vayunmathur/maps/MainActivitySlice3Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/MainActivitySlice3Test.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.content.Intent import android.net.Uri@@ -196,7 +198,7 @@ class MainActivitySlice3Test { val controller = launch("geo:37.7749,-122.4194?q=Pier+39") val activity = controller.get() val vm = selectedOf(activity)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertTrue(selected.name.contains("Pier")) assertEquals(37.7749, selected.position.latitude, 1e-6)@@ -214,7 +216,7 @@ class MainActivitySlice3Test { } val controller = Robolectric.buildActivity(MainActivity::class.java, intent).setup() val vm = selectedOf(controller.get())- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) assertNull(vm.pendingFocus.value) controller.destroy() }@@ -223,7 +225,7 @@ class MainActivitySlice3Test { fun `cold start with unparseable view link selects nothing and does not crash`() { val controller = launch("https://example.com/not-a-maps-link") val vm = selectedOf(controller.get())- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) assertNull(vm.pendingFocus.value) controller.destroy() }@@ -236,7 +238,7 @@ class MainActivitySlice3Test { } val controller = Robolectric.buildActivity(MainActivity::class.java, intent).setup() val vm = selectedOf(controller.get())- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) assertNull(vm.pendingFocus.value) controller.destroy() }@@ -246,9 +248,9 @@ class MainActivitySlice3Test { val controller = launch(null) val activity = controller.get() val vm = selectedOf(activity)- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) controller.newIntent(viewIntent("geo:37.7749,-122.4194?q=Pier+39"))- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertTrue(selected.name.contains("Pier")) controller.destroy()@@ -259,10 +261,10 @@ class MainActivitySlice3Test { val controller = launch("geo:37.7749,-122.4194?q=Pier+39") val activity = controller.get() val vm = selectedOf(activity)- val before = vm.selectedFeature.value+ val before = vm.sheetRoute.value.toFeature() assertNotNull(before) controller.newIntent(viewIntent("https://example.com/not-a-maps-link"))- assertEquals(before, vm.selectedFeature.value)+ assertEquals(before, vm.sheetRoute.value.toFeature()) controller.destroy() } @@ -409,7 +411,7 @@ class MainActivitySlice3Test { val controller = launch("google.navigation:q=37.7849,-122.4094&mode=d") val vm = selectedOf(controller.get()) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected, "destination place should be selected") assertEquals(37.7849, selected.position.latitude, 1e-6) assertEquals(-122.4094, selected.position.longitude, 1e-6)@@ -425,7 +427,7 @@ class MainActivitySlice3Test { val controller = launch("geo:37.7849,-122.4094") val vm = selectedOf(controller.get()) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertEquals(context.getString(R.string.dropped_pin), selected.name) assertEquals(37.7849, selected.position.latitude, 1e-6)@@ -440,7 +442,7 @@ class MainActivitySlice3Test { val controller = launch("google.navigation:mode=d") val vm = selectedOf(controller.get()) awaitQuiescence()- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) controller.destroy() } @@ -453,7 +455,7 @@ class MainActivitySlice3Test { val controller = launch("google.navigation:q=37.7849,-122.4094&mode=d") val vm = selectedOf(controller.get()) awaitSelection(vm, maxIters = 2_000)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected, "destination place should be selected") assertEquals(37.7849, selected.position.latitude, 1e-6) assertEquals(-122.4094, selected.position.longitude, 1e-6)@@ -473,7 +475,7 @@ class MainActivitySlice3Test { awaitFix(vm) controller.newIntent(viewIntent("google.navigation:q=37.7849,-122.4094&mode=d")) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected, "destination place should be selected") assertEquals(37.7849, selected.position.latitude, 1e-6) assertEquals(-122.4094, selected.position.longitude, 1e-6)@@ -490,7 +492,7 @@ class MainActivitySlice3Test { awaitFix(vm) controller.newIntent(viewIntent("google.navigation:q=37.7849,-122.4094")) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected, "destination place should be selected") assertEquals(37.7849, selected.position.latitude, 1e-6) controller.destroy()@@ -513,7 +515,7 @@ class MainActivitySlice3Test { val controller = launch("google.navigation:q=zz-unresolvable-place-xyzzy&mode=d") val vm = selectedOf(controller.get()) awaitQuiescence()- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) controller.destroy() } @@ -523,7 +525,7 @@ class MainActivitySlice3Test { val controller = launch("geo:0,0?q=zz-unresolvable-place-xyzzy") val vm = selectedOf(controller.get()) awaitQuiescence()- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) controller.destroy() } @@ -562,7 +564,7 @@ class MainActivitySlice3Test { repeat(maxIters) { Robolectric.flushForegroundThreadScheduler() shadow.idle()- if (vm.selectedFeature.value != null) return+ if (vm.sheetRoute.value.toFeature() != null) return Thread.yield() } }@@ -588,7 +590,7 @@ class MainActivitySlice3Test { // No offline index under Robolectric, so no selection happens; what this // pins is that the fallback path runs without crashing and leaves the // query path (not the point path) taken — nothing selected, no focus.- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) assertNull(vm.pendingFocus.value) controller.destroy() }@@ -602,7 +604,7 @@ class MainActivitySlice3Test { val activity = controller.get() val vm = selectedOf(activity) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertEquals("Pier 39", selected.name) assertNotNull(vm.pendingFocus.value)@@ -626,7 +628,7 @@ class MainActivitySlice3Test { val controller = launch("geo:37.7849,-122.4094") val vm = selectedOf(controller.get()) awaitSelection(vm)- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertEquals("Pier 39", selected.name) controller.destroy()@@ -646,7 +648,7 @@ class MainActivitySlice3Test { // Routing still fails without an archive, so the resolved destination // degrades to an opened place — but the destination came from the // index, not from raw coordinates.- val selected = vm.selectedFeature.value+ val selected = vm.sheetRoute.value.toFeature() assertIs<SpecificFeature.GenericPlace>(selected) assertEquals("Pier 39", selected.name) controller.destroy()@@ -675,7 +677,7 @@ class MainActivitySlice3Test { ViewModelProvider(activity) [com.vayunmathur.maps.util.MapsSearchViewModel::class.java].query.value, )- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature()) controller.destroy() } finally { // (0,0) is the "no fix stored" sentinel: restore it so sibling
maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.ktindex 9728b7ef44..0a31fd1a7b 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/BottomSheetWiringSlice2Test.kt@@ -55,7 +55,6 @@ class BottomSheetWiringSlice2Test { var opened: Pair<Double, Double>? = null val actions = object : PlacePanelActions { override fun setPoiSection(s: PoiSection) {- selected.setPoiSection(s) section = s } @@ -76,7 +75,6 @@ class BottomSheetWiringSlice2Test { actions.openNearestStop(37.8, -122.4) } assertEquals(PoiSection.PHOTOS, section)- assertEquals(PoiSection.PHOTOS, selected.poiSection.value) assertEquals(37.8, opened?.first) assertEquals(-122.4, opened?.second) }@@ -85,10 +83,9 @@ class BottomSheetWiringSlice2Test { fun `added places read back as saved through the panel state`() { val selected = SelectedFeatureViewModel(app) val savedVm = SavedPlacesViewModel(app)- rule.runOnIdle { selected.setPoiSection(PoiSection.PHOTOS) } var panel: PlacePanelState? = null rule.setContent {- panel = rememberPlacePanelState(selected, savedVm)+ panel = rememberPlacePanelState(selected, savedVm, PoiSection.PHOTOS) } rule.waitForIdle() assertEquals(PoiSection.PHOTOS, panel?.poiSection)
maps/src/test/java/com/vayunmathur/maps/ui/MapSheetEffectsSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/MapSheetEffectsSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/MapSheetEffectsSlice3ExtraTest.ktindex 9f6ea30f4c..297f3c045a 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/MapSheetEffectsSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/MapSheetEffectsSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.ui+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import androidx.activity.ComponentActivity@@ -84,7 +86,7 @@ class MapSheetEffectsSlice3ExtraTest { rule.waitForIdle() // Back with a selection clears the selection via the search BackHandler chain: // set the VM selection the way the sheet would see it first- rule.runOnUiThread { vm.set(feature) }+ rule.runOnUiThread { vm.setSheetRoute(feature!!.toSheetRoute()) } rule.waitForIdle() }
maps/src/test/java/com/vayunmathur/maps/ui/SearchActionsSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/ui/SearchActionsSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/ui/SearchActionsSlice3ExtraTest.ktindex 50201e479b..20eb707e49 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/SearchActionsSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/SearchActionsSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.ui+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import androidx.compose.runtime.rememberCoroutineScope@@ -68,12 +70,12 @@ class SearchActionsSlice3ExtraTest { actions!!.selectResult(result) // selectResult launches on the passed scope (paused Main under Robolectric): pump + wait withTimeout(10000) {- while (selectedVm.selectedFeature.value == null) {+ while (selectedVm.pendingPlace.value == null) { Shadows.shadowOf(android.os.Looper.getMainLooper()).idle() delay(50) } }- assertEquals("Blue Bottle", (selectedVm.selectedFeature.value as SpecificFeature.GenericPlace).name)+ assertEquals("Blue Bottle", (selectedVm.pendingPlace.value as SpecificFeature.GenericPlace).name) withTimeout(5000) { while (closed == 0) { Shadows.shadowOf(android.os.Looper.getMainLooper()).idle()@@ -90,23 +92,30 @@ class SearchActionsSlice3ExtraTest { val selectedVm = SelectedFeatureViewModel(app) var closed = 0 var actions: SearchActions? = null- // Current selection is a Route with two waypoints; picking for waypoint 1 replaces it+ // A RoutePlan under a Search sheet: picking for waypoint 1 rewrites+ // that leg on the stack and pops the search back to the plan. val from = SpecificFeature.GenericPlace("From", null, null, null, GeoPoint(-122.4, 37.8)) val to = SpecificFeature.GenericPlace("To", null, null, null, GeoPoint(-122.3, 37.9))- selectedVm.set(SpecificFeature.Route(listOf(from, to)))+ val stack = com.vayunmathur.library.util.NavBackStack<com.vayunmathur.maps.SheetRoute>(+ arrayOf(+ com.vayunmathur.maps.SheetRoute.Browse,+ com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(from, to)),+ com.vayunmathur.maps.SheetRoute.Search(1, 37.8, -122.4),+ ),+ ) rule.setContent { val scope = rememberCoroutineScope()- actions = rememberSearchActions(com.vayunmathur.maps.SheetRoute.Search(1, 37.8, -122.4), searchVm, selectedVm, scope) { closed++ }+ actions = rememberSearchActions(com.vayunmathur.maps.SheetRoute.Search(1, 37.8, -122.4), searchVm, selectedVm, scope, sheetStack = stack) { closed++ } DynamicTheme { androidx.compose.foundation.layout.Box {} } } actions!!.selectResult(com.vayunmathur.maps.util.SearchResult("id2", "Middle", null, 37.85, -122.35, null)) withTimeout(10000) {- while ((selectedVm.selectedFeature.value as? SpecificFeature.Route)?.waypoints?.getOrNull(1)?.name != "Middle") {+ while ((stack.backStack.filterIsInstance<com.vayunmathur.maps.SheetRoute.RoutePlan>().lastOrNull())?.waypoints?.getOrNull(1)?.name != "Middle") { Shadows.shadowOf(android.os.Looper.getMainLooper()).idle() delay(50) } }- assertEquals(0, closed) // route replacement does not close the sheet+ assertTrue(closed > 0) // picking a waypoint pops the search sheet Unit } } @@ -122,7 +131,7 @@ class SearchActionsSlice3ExtraTest { val vm = SelectedFeatureViewModel(app) val from = SpecificFeature.GenericPlace("From", null, null, null, GeoPoint(-122.4, 37.8)) val to = SpecificFeature.GenericPlace("To", null, null, null, GeoPoint(-122.3, 37.9))- vm.set(SpecificFeature.Route(listOf(from, to)))+ vm.setSheetRoute(com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(from, to))) // WhileSubscribed flow on viewModelScope (paused Main) + IO planning: pump both var latest: Map<RouteService.TravelMode, RouteService.RouteType?>? = null val job = kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch {
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 a5042c2e50..e8a0b89487 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/Slice3Pass5SheetsTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.ui+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import androidx.compose.material3.SheetValue@@ -125,7 +127,7 @@ class Slice3Pass5SheetsTest { ) rule.setContent { val scope = compactScope(place)- scope.viewModel.set(place)+ scope.viewModel.setSheetRoute(place.toSheetRoute()) DynamicTheme { with(scope) { MapSheets(searchActions = null, searchState = SearchUiState())@@ -143,7 +145,7 @@ class Slice3Pass5SheetsTest { ) rule.setContent { val vm = SelectedFeatureViewModel(app)- vm.set(place)+ vm.setSheetRoute(place.toSheetRoute()) DynamicTheme { PlaceSheet(viewModel = vm, feature = place) }@@ -158,7 +160,7 @@ class Slice3Pass5SheetsTest { ) rule.setContent { val vm = SelectedFeatureViewModel(app)- vm.set(restaurant)+ vm.setSheetRoute(restaurant.toSheetRoute()) DynamicTheme { PlaceSheet(viewModel = vm, feature = restaurant) }
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 b00cc741bd..5ba002ca07 100644--- a/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/ui/WideHostSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.ui+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import androidx.compose.runtime.rememberCoroutineScope@@ -141,7 +143,7 @@ class WideHostSlice3ExtraTest { ) rule.setContent { val scope = buildScope(place)- scope.viewModel.set(place)+ scope.viewModel.setSheetRoute(place.toSheetRoute()) DynamicTheme { with(scope) { MapWideHost(searchActions = null, searchState = SearchUiState(), panelSearch = false, panelPlace = true)
maps/src/test/java/com/vayunmathur/maps/util/MapsSelectedFeatureC5Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/MapsSelectedFeatureC5Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/MapsSelectedFeatureC5Test.ktindex c9f13adf02..24458d5387 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/MapsSelectedFeatureC5Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/MapsSelectedFeatureC5Test.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.util+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import android.os.Looper@@ -39,7 +41,7 @@ class MapsSelectedFeatureC5Test { SpecificFeature.GenericPlace("To", null, null, null, pt(-122.0, 37.002)), ), )- vm.set(routeFeature)+ vm.setSheetRoute(routeFeature.toSheetRoute()) // stateIn(WhileSubscribed) only runs while collected. val scope = kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Main) val collectJob = scope.launch {@@ -70,7 +72,7 @@ class MapsSelectedFeatureC5Test { @Test fun `clearing the selection empties planned routes`() { val vm = SelectedFeatureViewModel(app)- vm.set(null)+ vm.setSheetRoute(null) Shadows.shadowOf(Looper.getMainLooper()).idle() assertNull(vm.routes.value) }@@ -96,7 +98,7 @@ class MapsSelectedFeatureC5Test { val vm = SelectedFeatureViewModel(app) val place = SpecificFeature.GenericPlace("C5 Town", null, null, null, pt(-122.4, 37.8)) vm.selectAndFocus(place, zoom = 15.0)- assertEquals(place, vm.selectedFeature.value)+ assertEquals(place, vm.pendingPlace.value) assertEquals(15.0, vm.pendingFocus.value?.zoom) vm.consumeFocus() assertNull(vm.pendingFocus.value)
maps/src/test/java/com/vayunmathur/maps/util/SelectedFeatureSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/SelectedFeatureSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/SelectedFeatureSlice3ExtraTest.ktindex eb77235aab..27d02da4bf 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/SelectedFeatureSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/SelectedFeatureSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.util+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import android.os.Looper@@ -45,33 +47,35 @@ class SelectedFeatureSlice3ExtraTest { @Test fun setBarePlaceAttemptsEnrichmentAndKeepsSelection() { val vm = SelectedFeatureViewModel(app) val place = barePlace()- vm.set(place)- assertEquals(place, vm.selectedFeature.value)- assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, vm.poiSection.value)- vm.setPoiSection(com.vayunmathur.maps.data.google.PoiSection.PHOTOS)- assertEquals(com.vayunmathur.maps.data.google.PoiSection.PHOTOS, vm.poiSection.value)- vm.set(barePlace("Other"))- assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, vm.poiSection.value) // set resets section+ vm.setSheetRoute(place.toSheetRoute())+ assertEquals(place, vm.sheetRoute.value.toFeature())+ // The tab is the Place route's section: a fresh Place defaults to+ // Details, writing PHOTOS back via copy, and a new place resets.+ assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, (vm.sheetRoute.value as com.vayunmathur.maps.SheetRoute.Place).section)+ vm.setSheetRoute((vm.sheetRoute.value as com.vayunmathur.maps.SheetRoute.Place).copy(section = com.vayunmathur.maps.data.google.PoiSection.PHOTOS))+ assertEquals(com.vayunmathur.maps.data.google.PoiSection.PHOTOS, (vm.sheetRoute.value as com.vayunmathur.maps.SheetRoute.Place).section)+ vm.setSheetRoute(barePlace("Other").toSheetRoute())+ assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, (vm.sheetRoute.value as com.vayunmathur.maps.SheetRoute.Place).section) // Enrichment runs async against the (absent) POI sidecar; give it its chance pumpUntil(3000) { false }- assertEquals("Other", (vm.selectedFeature.value as? SpecificFeature.GenericPlace)?.name)+ assertEquals("Other", (vm.sheetRoute.value.toFeature() as? SpecificFeature.GenericPlace)?.name) } @Test fun setEnrichedAndRestaurantSkipLookup() { val vm = SelectedFeatureViewModel(app) val enriched = SpecificFeature.GenericPlace("Has Phone", "555-1", null, null, GeoPoint(-122.4, 37.8))- vm.set(enriched)- assertEquals(enriched, vm.selectedFeature.value)+ vm.setSheetRoute(enriched.toSheetRoute())+ assertEquals(enriched, vm.sheetRoute.value.toFeature()) val rest = SpecificFeature.Restaurant("Pizza", null, null, null, null, GeoPoint(-122.4, 37.8))- vm.set(rest)- assertEquals(rest, vm.selectedFeature.value)- vm.set(null)- assertNull(vm.selectedFeature.value)+ vm.setSheetRoute(rest.toSheetRoute())+ assertEquals(rest, vm.sheetRoute.value.toFeature())+ vm.setSheetRoute(null)+ assertNull(vm.sheetRoute.value.toFeature()) } @Test fun poiInfoGateOffByDefault() { runBlocking { val vm = SelectedFeatureViewModel(app)- vm.set(barePlace())+ vm.setSheetRoute(barePlace().toSheetRoute()) val info = withTimeoutOrNull(5000) { val d = CoroutineScope(Dispatchers.Default).async { vm.currentPoiInfo.first { it != null || true } } pumpUntil(4000) { d.isCompleted }@@ -87,7 +91,7 @@ class SelectedFeatureSlice3ExtraTest { val vm = SelectedFeatureViewModel(app) val from = SpecificFeature.GenericPlace("From", null, null, null, GeoPoint(-122.4, 37.8)) val to = SpecificFeature.GenericPlace("To", null, null, null, GeoPoint(-122.3, 37.9))- vm.set(SpecificFeature.Route(listOf(from, to)))+ vm.setSheetRoute(com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(from, to))) // No road pack in the sandbox: the flow must still terminate in a map of // mode -> EmptyRoute/null entries rather than hang or throw here. val got = withTimeoutOrNull(12000) {
maps/src/test/java/com/vayunmathur/maps/util/SelectedPoiInfoSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/SelectedPoiInfoSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/SelectedPoiInfoSlice3ExtraTest.ktindex 544fcc1844..7c5ea5e215 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/SelectedPoiInfoSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/SelectedPoiInfoSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.util+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import android.os.Looper@@ -85,7 +87,7 @@ class SelectedPoiInfoSlice3ExtraTest { } try { val vm = SelectedFeatureViewModel(app)- vm.set(SpecificFeature.GenericPlace(name, "555", null, null, GeoPoint(-122.4, 37.8)))+ vm.setSheetRoute(SpecificFeature.GenericPlace(name, "555", null, null, GeoPoint(-122.4, 37.8)).toSheetRoute()) val seen = java.util.concurrent.atomic.AtomicReference<com.vayunmathur.maps.data.google.GooglePoiInfo?>(null) val job = CoroutineScope(Dispatchers.Default).launch { vm.currentPoiInfo.collect { if (it != null) seen.set(it) }@@ -118,7 +120,7 @@ class SelectedPoiInfoSlice3ExtraTest { GooglePoiDataSource.httpGet = { Payload().searchBody() } // zero entries -> NoMatch try { val vm = SelectedFeatureViewModel(app)- vm.set(SpecificFeature.GenericPlace("Nowhere Place", "555", null, null, GeoPoint(-122.4, 37.8)))+ vm.setSheetRoute(SpecificFeature.GenericPlace("Nowhere Place", "555", null, null, GeoPoint(-122.4, 37.8)).toSheetRoute()) val seen = java.util.concurrent.atomic.AtomicReference<com.vayunmathur.maps.data.google.GooglePoiInfo?>(null) val job = CoroutineScope(Dispatchers.Default).launch { vm.currentPoiInfo.collect { seen.set(it) }
maps/src/test/java/com/vayunmathur/maps/util/SelectedRoutesReviewsSlice3ExtraTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/SelectedRoutesReviewsSlice3ExtraTest.kt b/maps/src/test/java/com/vayunmathur/maps/util/SelectedRoutesReviewsSlice3ExtraTest.ktindex 009ed74031..41bffa2560 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/SelectedRoutesReviewsSlice3ExtraTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/SelectedRoutesReviewsSlice3ExtraTest.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.util+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import android.app.Application import android.os.Looper@@ -90,7 +92,7 @@ class SelectedRoutesReviewsSlice3ExtraTest { GooglePoiDataSource.httpGet = { url -> requested.add(url); Payload().searchBody(entry) } try { val vm = SelectedFeatureViewModel(app)- vm.set(SpecificFeature.GenericPlace(name, "555", null, null, GeoPoint(-122.4, 37.8)))+ vm.setSheetRoute(SpecificFeature.GenericPlace(name, "555", null, null, GeoPoint(-122.4, 37.8)).toSheetRoute()) val seen = java.util.concurrent.atomic.AtomicReference<com.vayunmathur.maps.data.google.GooglePoiInfo?>(null) val job = CoroutineScope(Dispatchers.Default).launch { vm.currentPoiInfo.collect { if (it != null) seen.set(it) }@@ -116,7 +118,7 @@ class SelectedRoutesReviewsSlice3ExtraTest { val vm = SelectedFeatureViewModel(app) val from = SpecificFeature.GenericPlace("From", null, null, null, GeoPoint(-122.4, 37.8)) val to = SpecificFeature.GenericPlace("To", null, null, null, GeoPoint(-122.3, 37.9))- vm.set(SpecificFeature.Route(listOf(from, to)))+ vm.setSheetRoute(com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(from, to))) val seen = java.util.concurrent.atomic.AtomicReference<Map<RouteService.TravelMode, RouteService.RouteType?>?>(null) val job = CoroutineScope(Dispatchers.Default).launch { vm.routes.collect { if (it != null) seen.set(it) }
maps/src/test/java/com/vayunmathur/maps/util/ViewModelsSlice3Test.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/util/ViewModelsSlice3Test.kt b/maps/src/test/java/com/vayunmathur/maps/util/ViewModelsSlice3Test.ktindex e38f649f52..b4ebba966d 100644--- a/maps/src/test/java/com/vayunmathur/maps/util/ViewModelsSlice3Test.kt+++ b/maps/src/test/java/com/vayunmathur/maps/util/ViewModelsSlice3Test.kt@@ -1,4 +1,6 @@ package com.vayunmathur.maps.util+import com.vayunmathur.maps.toFeature+import com.vayunmathur.maps.toSheetRoute import androidx.test.core.app.ApplicationProvider import androidx.compose.ui.test.junit4.createComposeRule@@ -7,6 +9,9 @@ import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.maps.data.SavedPlace import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.parkedRoutePlan+import com.vayunmathur.maps.popSheet+import com.vayunmathur.maps.selectFeature import com.vayunmathur.maps.data.ThemeMode import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch@@ -94,19 +99,18 @@ class ViewModelsSlice3Test { @Test fun `selection starts empty and clears`() { val vm = SelectedFeatureViewModel(app)- assertNull(vm.selectedFeature.value)- vm.set(place())- assertEquals(place(), vm.selectedFeature.value)- vm.set(null)- assertNull(vm.selectedFeature.value)+ assertNull(vm.sheetRoute.value.toFeature())+ vm.setSheetRoute(place().toSheetRoute())+ assertEquals(place(), vm.sheetRoute.value.toFeature())+ vm.setSheetRoute(null)+ assertNull(vm.sheetRoute.value.toFeature()) } @Test fun `selecting resets the poi section to details`() {- val vm = SelectedFeatureViewModel(app)- vm.setPoiSection(com.vayunmathur.maps.data.google.PoiSection.PHOTOS)- vm.set(place())- assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, vm.poiSection.value)+ // A fresh Place route carries the Details section by default.+ val route = place().toSheetRoute() as com.vayunmathur.maps.SheetRoute.Place+ assertEquals(com.vayunmathur.maps.data.google.PoiSection.DETAILS, route.section) } @Test@@ -129,31 +133,21 @@ class ViewModelsSlice3Test { } @Test- fun `stashRouteSelection parks the current route`() {- val vm = SelectedFeatureViewModel(app)- assertNull(vm.inactiveNavigation.value)+ fun `a place over a route parks it as stack depth`() {+ // The parked route is just a RoutePlan under a Place on the stack:+ // parkedRoutePlan reads it, and popping the place returns to it. val route = SpecificFeature.Route(waypoints = listOf(place()))- vm.set(route)- vm.stashRouteSelection()- assertEquals(route, vm.inactiveNavigation.value)- }-- @Test- fun `stashRouteSelection ignores non-route selections`() {- val vm = SelectedFeatureViewModel(app)- vm.set(place())- vm.stashRouteSelection()- assertNull(vm.inactiveNavigation.value)- }-- @Test- fun `setInactiveNavigation replaces the parked route`() {- val vm = SelectedFeatureViewModel(app)- val route = SpecificFeature.Route(waypoints = listOf(place()))- vm.setInactiveNavigation(route)- assertEquals(route, vm.inactiveNavigation.value)- vm.setInactiveNavigation(null)- assertNull(vm.inactiveNavigation.value)+ val stack = com.vayunmathur.library.util.NavBackStack<com.vayunmathur.maps.SheetRoute>(+ arrayOf(com.vayunmathur.maps.SheetRoute.Browse),+ )+ stack.selectFeature(route)+ stack.selectFeature(place())+ assertEquals(+ com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(place())),+ stack.backStack.parkedRoutePlan(),+ )+ stack.popSheet()+ assertEquals(com.vayunmathur.maps.SheetRoute.RoutePlan(listOf(place())), stack.last()) } // --- SavedPlacesViewModel ---