Modern Apps git

← Modern-Apps.git

findfamily: sheet destinations for person/waypoint selection (#nav)

Commit
a36c3ecbbab2a0815cedd3494fead16fc88fea0c
Author
Vayun Mathur <[email protected]>
When
2026-11-16 20:21 UTC (19 days ago)
Parents
dd2a5b7
Person and waypoint selection lived twice: _selectedUserId and
_selectedWaypointId StateFlows in MapPageState, duplicated by
Route.MainPage(selectedUserId, selectedWaypointId) arguments and
mirrored through applyInitialSelection. Selection now lives in
exactly one place, the back stack: Route.MainPage is a data
object, and new Route.PersonSheet(userId) / Route.WaypointSheet
(waypointId) DialogPage destinations sit over the map (the maps
sheet-route pattern). Tapping a person or waypoint pushes the
sheet, Back pops it, and MainPage derives its map highlight and
camera inputs from the stack top.

MapPageState and FindFamilyViewModel lose the selection flows
and mirroring helpers; locationHistory is keyed by the route's
userId, and waypoint saving takes the waypoint id explicitly.
New PersonSheet and WaypointSheet destinations host the former
sheet branches, including history scrubbing, Find Nearby/UWB,
the security code dialog (moved out of MainPageEffects), and the
waypoint form. Deep links: the no-show target now pushes
PersonSheet over MainPage; invite and UWB singleTop onNewIntent
handling is unchanged.

Caveat: WaypointSheet no longer live-updates the waypoint range
ring while dragging, since the sheet is now a dialog destination
over the map rather than a non-modal bottom sheet; the form
edits name/range and the map still renders the waypoint ring.

Tests updated across the MainPage/MapPageState/ViewModel suites;
MainPageNavigationRealRepoTest drives the new sheet destinations,
and the GPS-dialog test now asserts the GPS dialog (the security
dialog it previously piggybacked on moved to PersonSheet).

Verified: ./gradlew :findfamily:compileDevKotlin :findfamily:testDevUnitTest

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.ktindex 01d18073aa..eb8f81c1df 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/MainActivity.kt@@ -29,7 +29,9 @@ import androidx.compose.ui.res.stringResource import com.vayunmathur.library.util.NavKey import com.vayunmathur.findfamily.data.FindFamilyRepository import com.vayunmathur.findfamily.ui.MainPage+import com.vayunmathur.findfamily.ui.PersonSheet import com.vayunmathur.findfamily.ui.UwbRangingScreen+import com.vayunmathur.findfamily.ui.WaypointSheet import com.vayunmathur.findfamily.ui.dialogs.AddLinkDialog import com.vayunmathur.findfamily.ui.dialogs.AddPersonDialog import com.vayunmathur.findfamily.ui.dialogs.AddTrackerDialog@@ -234,8 +236,16 @@ fun MissingFeaturesDialog(backStack: NavBackStack<Route>) { /** Navigation destinations for FindFamily's single-activity graph. */ sealed interface Route: NavKey {     @Serializable-    /** Map home destination, optionally preselecting a person or waypoint. */-    data class MainPage(val selectedUserId: Long? = null, val selectedWaypointId: Long? = null): Route+    /** Map home destination. Selection lives in [PersonSheet]/[WaypointSheet], not here. */+    data object MainPage: Route++    @Serializable+    /** Sheet for the given person, shown over the map. */+    data class PersonSheet(val userId: Long): Route++    @Serializable+    /** Sheet for the given waypoint (0 = create a new one), shown over the map. */+    data class WaypointSheet(val waypointId: Long): Route      @Serializable     /** Dialog for picking the date whose location history to show. */@@ -273,7 +283,7 @@ fun Navigation(     noShowTarget: Pair<Long, Long?>? = null,     onNoShowTargetConsumed: () -> Unit = {}, ) {-    val backStack = rememberNavBackStack<Route>(Route.MainPage())+    val backStack = rememberNavBackStack<Route>(Route.MainPage)      LaunchedEffect(showMissingFeatures) {         if (showMissingFeatures) {@@ -296,17 +306,26 @@ fun Navigation(         }     } -    // A tapped no-show notification opens the map on the watched person/place.+    // A tapped no-show notification opens the watched person's sheet over+    // the map. The expected place rides along in the alert itself; selection+    // holds one destination, and the person is what the sheet showed first+    // before this refactor too.     LaunchedEffect(noShowTarget) {         if (noShowTarget != null) {-            backStack.add(Route.MainPage(noShowTarget.first, noShowTarget.second))+            backStack.add(Route.PersonSheet(noShowTarget.first))             onNoShowTargetConsumed()         }     }      MainNavigation(backStack) {         entry<Route.MainPage> {-            MainPage(platform, backStack, ffViewModel, it.selectedUserId, it.selectedWaypointId)+            MainPage(platform, backStack, ffViewModel)+        }+        entry<Route.PersonSheet>(metadata = DialogPage()) {+            PersonSheet(backStack, ffViewModel, platform, it.userId)+        }+        entry<Route.WaypointSheet>(metadata = DialogPage()) {+            WaypointSheet(backStack, ffViewModel, it.waypointId)         }         entry<Route.UserPageHistoryDatePicker>(metadata = DialogPage()) {             DatePickerDialog(
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainFabOverlay.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainFabOverlay.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainFabOverlay.ktindex fa1e1370eb..02842fcb85 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainFabOverlay.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainFabOverlay.kt@@ -171,7 +171,10 @@ internal fun BoxScope.MainFabOverlay(             .offset { IntOffset(0, sheetLiftPx()) }     ) {         MaterialTheme(colorScheme = lightScheme) {-            if (state.nothingSelected) {+            // MainPage always shows the family list (selection lives in the+            // PersonSheet/WaypointSheet destinations, which carry their own+            // actions), so the FAB is always the add menu.+            run {                 if (inPreview) {                     // The expressive FloatingActionButtonMenu is animation-driven and                     // does not render under Layoutlib; show the representative collapsed@@ -213,23 +216,6 @@ internal fun BoxScope.MainFabOverlay(                         }                     }                 }-            } else if (state.selectedWaypointId != null) {-                FloatingActionButton(-                    { actions.saveCurrentWaypoint() },-                    containerColor = fabContainerColor,-                    contentColor = fabContentColor-                ) {-                    IconSave()-                }-            } else if (state.selectedUserId != null && state.isShowingPresent) {-                // Enter history mode; exit is via back.-                FloatingActionButton(-                    { actions.enterHistory() },-                    containerColor = fabContainerColor,-                    contentColor = fabContentColor-                ) {-                    IconRestore()-                }             }         }     }
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainMapSlot.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainMapSlot.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainMapSlot.ktindex 3f3001599d..0012db1c0c 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainMapSlot.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainMapSlot.kt@@ -161,6 +161,8 @@ internal fun MainMapSlot(     historicalPosition: GeoPoint?,     selectedWaypointId: Long?,     waypointRange: String,+    onUserClick: (Long) -> Unit,+    onMapClick: () -> Unit, ) {     val selectedUserObj = if (selectedUserId != null) {         selectedUser?.let { SelectedUser(it, isShowingPresent, historicalPosition) }@@ -176,12 +178,8 @@ internal fun MainMapSlot(     MapView(         ffViewModel,         camera = camera,-        onUserClick = {-            ffViewModel.selectUser(it)-        },-        onMapClick = {-            ffViewModel.mapState.clearSelection()-        },+        onUserClick = onUserClick,+        onMapClick = onMapClick,         selectedUser = selectedUserObj,         selectedWaypoint = selectedWaypointObj     )
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.ktindex 9cc6b900d2..7ffc87d0e0 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt@@ -168,35 +168,28 @@ fun MainPage(     platform: Platform,     backStack: NavBackStack<Route>,     ffViewModel: FindFamilyViewModel,-    initialUserId: Long? = null,-    initialWaypointId: Long? = null ) {-    // Mirror the original `remember(initialUserId)` behaviour: apply the-    // navigation-supplied selection whenever it changes.-    LaunchedEffect(initialUserId, initialWaypointId) {-        ffViewModel.applyInitialSelection(initialUserId, initialWaypointId)-    }--    val selectedUserId by ffViewModel.selectedUserId.collectAsState()-    val selectedWaypointId by ffViewModel.mapState.selectedWaypointId.collectAsState()+    // Selection lives in the back stack: the top destination (if it is a+    // sheet) supplies the ids the map/camera react to. This page itself+    // always shows the family list; the sheet destinations host the+    // person/waypoint UI.+    val topRoute = backStack.backStack.lastOrNull()+    val selectedUserId = (topRoute as? Route.PersonSheet)?.userId+    val selectedWaypointId = (topRoute as? Route.WaypointSheet)?.waypointId     val isShowingPresent by ffViewModel.isShowingPresent.collectAsState()     val historicalPosition by ffViewModel.historicalPosition.collectAsState()-    var showSecurityCode by remember { mutableStateOf(false) }     var showGpsWarning by remember { mutableStateOf(false) }     val usingGpsFallback by ffViewModel.usingGpsFallback.collectAsState() -    val waypointName by ffViewModel.waypointName.collectAsState()     val waypointRange by ffViewModel.waypointRange.collectAsState()      // History mode = a contact is selected and we're viewing their past track.     val historyMode = selectedUserId != null && !isShowingPresent -    BackHandler(selectedUserId != null || (selectedWaypointId != null && selectedWaypointId != 0L)) {-        if (historyMode) {-            ffViewModel.mapState.setShowingPresent(true)-        } else {-            ffViewModel.mapState.clearSelection()-        }+    // Back from history returns to the person's present location; back+    // anywhere else pops the sheet destination off the stack (NavDisplay).+    BackHandler(selectedUserId != null && historyMode) {+        ffViewModel.mapState.setShowingPresent(true)     }      val temporaryLinks by ffViewModel.temporaryLinks.collectAsState()@@ -211,41 +204,21 @@ fun MainPage(      val context = LocalContext.current -    // The selected contact, resolved from the full user list (the same source-    // `userByIdState` reads). Drives the person sheet, the history title and delete.+    // The selected contact (from the sheet route on top of the stack),+    // resolved from the full user list. Drives the map highlight.     val users by ffViewModel.users.collectAsState()     val selectedUser = selectedUserId?.let { id -> users.firstOrNull { it.id == id } } -    // Contact re-pick launcher: created unconditionally (activity-result launchers must-    // be registered during composition) and reused by the hoisted PersonActions. The-    // callback re-reads the current selection when a contact is actually picked.-    val requestPickContact = platform.requestPickContact { name, photo ->-        selectedUser?.let { ffViewModel.updateContactNamePhoto(it.id, name, photo) }-    }--    val (familyActions, personActions, mainActions) = rememberMainPageActions(+    val (familyActions, mainActions) = rememberMainPageActions(         ffViewModel = ffViewModel,         backStack = backStack,         platform = platform,-        selectedUser = selectedUser,-        selectedWaypointId = selectedWaypointId,-        waypoints = waypoints,         onShowGpsWarning = { showGpsWarning = it },-        onShowSecurityCode = { showSecurityCode = it },-        requestPickContact = requestPickContact,     )           val state = MainPageUiState(-        selectedUserId = selectedUserId,-        selectedWaypointId = selectedWaypointId,-        isShowingPresent = isShowingPresent,         usingGpsFallback = usingGpsFallback,-        uwbAvailable = UwbSessionManager.isAvailable(context),-        selfUserId = Networking.userid,-        selectedUser = selectedUser,-        waypointName = waypointName,-        waypointRange = waypointRange,         familyList = FamilyListUiState(             connectedUsers = connectedUsers,             awaitingRequestUsers = awaitingRequestUsers,@@ -254,19 +227,6 @@ fun MainPage(             locationByUser = userPositions,             userNamesByLocationName = usersByLocationName         ),-        person = selectedUser?.let {-            PersonUiState(-                it,-                userPositions[it.id],-                waypoints,-                globalSharingEnabled,-                crowdFindingEnabled,-                // Only the user's own sheet shows the powered-off controls, and it is the only-                // one that needs a peer list. Passing it unconditionally keeps the state a plain-                // projection rather than something that depends on which row was tapped.-                connectedUsers,-            )-        }     )      // Owned here, not by MapView: the two animateTo effects below drive it, and MapView is@@ -288,22 +248,8 @@ fun MainPage(     MainPageContent(         state = state,         familyActions = familyActions,-        personActions = personActions,         actions = mainActions,         backupPassphrase = ffViewModel.backupPassphrase,-        historyScrubber = {-            if (historyMode) {-                // Scoped to the person: a deep link can swap the selection while history-                // mode stays on, and the scrubber must restart from now for the new person-                // rather than inherit the previous one's instant.-                key(selectedUserId) {-                    HistoryScrubber(-                        backStack,-                        ffViewModel-                    ) { ffViewModel.mapState.setHistoricalPosition(it) }-                }-            }-        },         map = {             MainMapSlot(                 ffViewModel = ffViewModel,@@ -314,6 +260,17 @@ fun MainPage(                 historicalPosition = historicalPosition,                 selectedWaypointId = selectedWaypointId,                 waypointRange = waypointRange,+                onUserClick = { userId ->+                    ffViewModel.mapState.onPersonOpened()+                    backStack.add(Route.PersonSheet(userId))+                },+                onMapClick = {+                    // Tapping the map away from any marker dismisses an open+                    // sheet (normally unreachable under the sheet's scrim).+                    if (topRoute is Route.PersonSheet || topRoute is Route.WaypointSheet) {+                        backStack.pop()+                    }+                },             )                      }@@ -323,14 +280,12 @@ fun MainPage(         ffViewModel = ffViewModel,         camera = camera,         selectedUserId = selectedUserId,-        selfUserId = state.selfUserId,+        selfUserId = Networking.userid,         isShowingPresent = isShowingPresent,         historicalPosition = historicalPosition,         userPositions = userPositions,         selectedWaypointId = selectedWaypointId,         waypoints = waypoints,-        showSecurityCode = showSecurityCode,-        onShowSecurityCode = { showSecurityCode = it },         showGpsWarning = showGpsWarning,         onShowGpsWarning = { showGpsWarning = it },     )
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageActions.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageActions.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageActions.ktindex 6c609fae49..914da58edf 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageActions.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageActions.kt@@ -155,18 +155,25 @@ internal fun rememberMainPageActions(     ffViewModel: FindFamilyViewModel,     backStack: NavBackStack<Route>,     platform: Platform,-    selectedUser: User?,-    selectedWaypointId: Long?,-    waypoints: List<Waypoint>,     onShowGpsWarning: (Boolean) -> Unit,-    onShowSecurityCode: (Boolean) -> Unit,-    requestPickContact: () -> Unit,-): Triple<FamilyListActions, PersonActions, MainPageActions> {+): Pair<FamilyListActions, MainPageActions> {     // The sheets/layout are stateless so the store-listing previews can render them (the     // map behind them cannot be rendered off-device). The ViewModel supplies the actions     // it already implements; the ones needing the nav stack or the clipboard go here.+    // Selection actions push the sheet destinations: the back stack is the+    // single place selection lives.     val familyActions = remember(ffViewModel, backStack, platform) {         object : FamilyListActions by ffViewModel {+            override fun selectUser(userId: Long) {+                ffViewModel.mapState.onPersonOpened()+                backStack.add(Route.PersonSheet(userId))+            }++            override fun beginEditWaypoint(waypoint: Waypoint) {+                ffViewModel.beginEditWaypoint(waypoint)+                backStack.add(Route.WaypointSheet(waypoint.id))+            }+             override fun acceptRequest(userId: Long) {                 backStack.add(Route.AddPersonDialog(userId))             }@@ -184,33 +191,15 @@ internal fun rememberMainPageActions(         }     } -    val personActions = object : PersonActions by ffViewModel {-        override fun changeConnectedContact() = requestPickContact()-    }-     val mainActions = object : MainPageActions {-        override fun clearSelection() = ffViewModel.mapState.clearSelection()-        override fun setShowingPresent(present: Boolean) = ffViewModel.mapState.setShowingPresent(present)         override fun onGpsWarningClick() { onShowGpsWarning(true) }-        override fun onShowSecurityCode() { onShowSecurityCode(true) }-        override fun openUwbRanging(userId: Long) { backStack.add(Route.UwbRangingPage(userId)) }-        override fun deleteSelectedUser() {-            selectedUser?.let { ffViewModel.deleteUser(it) }-            ffViewModel.mapState.setSelectedUserId(null)-        }-        override fun deleteSelectedWaypoint() {-            selectedWaypointId?.let { id -> waypoints.firstOrNull { it.id == id } }-                ?.let { ffViewModel.deleteWaypoint(it) }-            ffViewModel.mapState.setSelectedWaypointId(null)-        }         override fun addPerson() { backStack.add(Route.AddPersonDialog()) }-        override fun beginCreateWaypoint() = ffViewModel.mapState.beginCreateWaypoint()+        override fun beginCreateWaypoint() {+            ffViewModel.mapState.beginCreateWaypoint()+            backStack.add(Route.WaypointSheet(0L))+        }         override fun addLink() { backStack.add(Route.AddLinkDialog) }         override fun addTracker() { backStack.add(Route.AddTrackerDialog) }-        override fun saveCurrentWaypoint() = ffViewModel.mapState.saveCurrentWaypoint()-        override fun enterHistory() = ffViewModel.mapState.setShowingPresent(false)-        override fun setWaypointName(name: String) = ffViewModel.mapState.setWaypointName(name)-        override fun setWaypointRange(range: String) = ffViewModel.mapState.setWaypointRange(range)     }-    return Triple(familyActions, personActions, mainActions)+    return Pair(familyActions, mainActions) }
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageCards.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageCards.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageCards.ktindex 501b322843..97c09aca00 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageCards.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageCards.kt@@ -55,6 +55,7 @@ internal val SheetMinContentMargin = 48.dp fun BoxScope.HistoryScrubber(     backStack: NavBackStack<Route>,     ffViewModel: FindFamilyViewModel,+    userId: Long,     setHistoricalPosition: (GeoPoint?) -> Unit ) {     val state = rememberHistoryScrubberState(@@ -82,7 +83,7 @@ fun BoxScope.HistoryScrubber(         state.setDate(it)     } -    val locs by ffViewModel.locationHistory.collectAsState()+    val locs by ffViewModel.locationHistory(userId).collectAsState(initial = emptyList())      LaunchedEffect(state.instant, locs) {         if (locs.isNotEmpty()) {
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.ktindex 551abb7226..9dbb74fdcb 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageContent.kt@@ -39,10 +39,8 @@ import kotlin.time.ExperimentalTime fun MainPageContent(     state: MainPageUiState,     familyActions: FamilyListActions,-    personActions: PersonActions,     actions: MainPageActions,     map: @Composable () -> Unit,-    historyScrubber: @Composable BoxScope.() -> Unit = {},     backupPassphrase: String? = null, ) {     val scaffoldState = rememberBottomSheetScaffoldState()@@ -54,20 +52,11 @@ fun MainPageContent(     // Expanded windows use the side-panel layout below instead of the bottom sheet.     val expanded = isExpandedWidth() && !inPreview -    // In history mode the sheet is effectively gone - the name moves to the app bar, the drag-    // handle is removed and swiping is disabled - but the peek must stay NON-ZERO.-    //-    // A peek of 0.dp crashes. `rememberBottomSheetScaffoldState` defaults to-    // `skipHiddenState = true`, so `Hidden` is not a legal anchor, and Material3 only creates a-    // `PartiallyExpanded` anchor when the peek height is greater than zero. At 0.dp the sheet-    // therefore has exactly one anchor, `Expanded`, while the state is still targeting-    // `PartiallyExpanded` - and the next measure pass throws-    // `AnchoredDraggableUninitializedException` from `DraggableAnchorsNode.checkOffsetIsValid`.-    // That is a hard FATAL on the main thread, not a layout glitch.-    //-    // 1.dp is below a pixel boundary on every supported density once the sheet is undecorated,-    // so this keeps the anchor alive without showing anything.-    val peekHeight = if (state.historyMode) 1.dp else SheetPeekHeight+    // The peek stays NON-ZERO: a peek of 0.dp crashes (Material3 keeps only+    // the Expanded anchor while the state targets PartiallyExpanded). This+    // page always shows the family list โ€” person/waypoint sheets are+    // separate destinations โ€” so the peek never collapses for history mode.+    val peekHeight = SheetPeekHeight      // The FAB sits on top of the always-light map, so color it from a light dynamic     // scheme regardless of the app's (possibly dark) theme. Captured OUTSIDE the@@ -90,49 +79,22 @@ fun MainPageContent(                 val st = scaffoldState.bottomSheetState                 val settled = st.currentValue == SheetValue.PartiallyExpanded &&                     st.targetValue == SheetValue.PartiallyExpanded-                val hist = state.historyMode-                if (settled && !hist) runCatching { st.requireOffset() }.getOrNull() else null+                if (settled) runCatching { st.requireOffset() }.getOrNull() else null             }.collect { off ->                 if (off != null && collapsedSheetOffset.floatValue.isNaN()) {                     collapsedSheetOffset.floatValue = off                 }             }         }--        // Changing the peek does not relocate a sheet that is already settled, in either-        // direction. Entering history drops the peek to its 1dp sliver, but a tall person-        // sheet stays put, shows the empty history content, and covers the scrubber card-        // floating underneath it (GitHub #818). Leaving history restores the peek without-        // pulling the sliver back up. Nudge toward the peek on both transitions, retrying-        // until the anchor is ready.-        LaunchedEffect(state.historyMode) {-            repeat(10) {-                if (runCatching { scaffoldState.bottomSheetState.partialExpand() }.isSuccess) {-                    return@LaunchedEffect-                }-                kotlinx.coroutines.delay(50)-            }-        }     }      if (expanded) {         FindFamilyWideLayout(             map = { map() },             panel = { modifier ->-                if (state.nothingSelected) {-                    FamilyListSheet(state.familyList, familyActions)-                } else if (state.selectedUserId != null) {-                    Column(modifier) {-                        state.person?.let { PersonDetailSheet(it, personActions) }-                        if (state.historyMode) {-                            // The phone layout floats the scrubber over the map; the side-                            // panel hosts it instead, under the person's card, so history-                            // is usable here rather than an empty panel (GitHub #818).-                            Spacer(Modifier.weight(1f))-                            Box(Modifier.fillMaxWidth()) { historyScrubber() }-                        }-                    }-                }+                // Always the family list: person/waypoint sheets are+                // separate destinations over the map, on every form factor.+                FamilyListSheet(state.familyList, familyActions)             },         )         return@@ -141,8 +103,8 @@ fun MainPageContent(     BottomSheetScaffold(         scaffoldState = scaffoldState,         sheetPeekHeight = peekHeight,-        sheetSwipeEnabled = !state.historyMode,-        sheetDragHandle = if (state.historyMode) null else { { BottomSheetDefaults.DragHandle() } },+        sheetSwipeEnabled = true,+        sheetDragHandle = { BottomSheetDefaults.DragHandle() },         sheetContainerColor = MaterialTheme.colorScheme.surfaceContainerLow,         // No top bar: the chrome floats over the map as a TopAppBarOverlay in the content         // slot below, so the map gets the whole window (GitHub #680).@@ -150,8 +112,6 @@ fun MainPageContent(             MainSheetContent(                 state = state,                 familyActions = familyActions,-                personActions = personActions,-                actions = actions,             )         }     ) { _ ->@@ -178,8 +138,6 @@ fun MainPageContent(                 }             } -            historyScrubber()-             MainFabOverlay(                 state = state,                 actions = actions,
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageEffects.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageEffects.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageEffects.ktindex ec8bfc6c4f..fc7f0c3a63 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageEffects.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageEffects.kt@@ -162,8 +162,6 @@ internal fun MainPageEffects(     userPositions: Map<Long, LocationValue>,     selectedWaypointId: Long?,     waypoints: List<Waypoint>,-    showSecurityCode: Boolean,-    onShowSecurityCode: (Boolean) -> Unit,     showGpsWarning: Boolean,     onShowGpsWarning: (Boolean) -> Unit, ) {@@ -227,11 +225,6 @@ internal fun MainPageEffects(         }     } -    if (showSecurityCode && selectedUserId != null && selectedUserId != Networking.userid) {-        val user by ffViewModel.userByIdState(selectedUserId)-        user?.let { SecurityCodeDialog(it, ffViewModel) { onShowSecurityCode(false) } }-    }-     if (showGpsWarning) {         GpsFallbackWarningDialog { onShowGpsWarning(false) }     }
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageOverlays.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageOverlays.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageOverlays.ktindex 06e75a4ffd..0004ef93c7 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageOverlays.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPageOverlays.kt@@ -34,85 +34,43 @@ internal fun MapOverlayBar(      val gpsWarningDescription = stringResource(R.string.gps_fallback_warning_content_description)     val menuDescription = stringResource(R.string.map_menu_content_description)-    val findNearbyDescription = stringResource(R.string.find_nearby_content_description)-    val verifyDescription = stringResource(R.string.verify_security_code_content_description)-    val deletePersonDescription = stringResource(R.string.delete_person_content_description)-    val deletePlaceDescription = stringResource(R.string.delete_place_content_description) -    val selectedUserId = state.selectedUserId-    val selectedWaypointId = state.selectedWaypointId--    val overlayActions: List<OverlayAction> =-        if (selectedUserId == null && (selectedWaypointId == null || selectedWaypointId == 0L)) {-            listOfNotNull(-                if (state.usingGpsFallback) {-                    OverlayAction(-                        icon = {-                            // Use Image (not the tinting IconWarning) so the-                            // custom yellow-and-red drawable keeps both colors.-                            Image(-                                painter = painterResource(R.drawable.ic_warning_gps),-                                contentDescription = gpsWarningDescription-                            )-                        },-                        contentDescription = gpsWarningDescription,-                        onClick = { actions.onGpsWarningClick() }-                    )-                } else null,-                // Singular backup entry point: one overflow button whose menu holds-                // "Back up" and "Restore" (GitHub #879). Null in previews, where no-                // passphrase exists and the button stays hidden.-                backupPassphrase?.let { passphrase ->-                    OverlayAction(-                        icon = {-                            BackupMenuButton(passphrase, backupMenuExpanded, { backupMenuExpanded = it })-                        },-                        contentDescription = menuDescription,-                        onClick = { backupMenuExpanded = !backupMenuExpanded }+    // Selection-scoped actions (Find Nearby / verify / delete) live on the+    // PersonSheet / WaypointSheet destinations. The map's own overlay only+    // carries the GPS warning and the backup menu; dismissal of a sheet is+    // the back stack's job, so there is no navigate-back affordance here.+    val overlayActions: List<OverlayAction> = listOfNotNull(+        if (state.usingGpsFallback) {+            OverlayAction(+                icon = {+                    // Use Image (not the tinting IconWarning) so the+                    // custom yellow-and-red drawable keeps both colors.+                    Image(+                        painter = painterResource(R.drawable.ic_warning_gps),+                        contentDescription = gpsWarningDescription                     )-                }+                },+                contentDescription = gpsWarningDescription,+                onClick = { actions.onGpsWarningClick() }             )-        } else if (selectedUserId != null && !state.historyMode) {-            if (state.isSelfSelected) emptyList() else listOfNotNull(-                // Find Nearby (UWB) needs both the public android.ranging API-                // (Android 16+) and an actual UWB radio. Hide the entry point otherwise.-                if (state.uwbAvailable) {-                    OverlayAction({ IconNavigationArrow() }, findNearbyDescription) {-                        actions.openUwbRanging(selectedUserId)-                    }-                } else null,-                OverlayAction({ IconVerify() }, verifyDescription) { actions.onShowSecurityCode() },-                OverlayAction({ IconDelete() }, deletePersonDescription) { actions.deleteSelectedUser() }-            )-        } else if (selectedWaypointId != null && selectedWaypointId != 0L) {-            listOf(-                OverlayAction({ IconDelete() }, deletePlaceDescription) { actions.deleteSelectedWaypoint() }+        } else null,+        // Singular backup entry point: one overflow button whose menu holds+        // "Back up" and "Restore" (GitHub #879). Null in previews, where no+        // passphrase exists and the button stays hidden.+        backupPassphrase?.let { passphrase ->+            OverlayAction(+                icon = {+                    BackupMenuButton(passphrase, backupMenuExpanded, { backupMenuExpanded = it })+                },+                contentDescription = menuDescription,+                onClick = { backupMenuExpanded = !backupMenuExpanded }             )-        } else {-            emptyList()         }+    )      TopAppBarOverlay(-        onNavigateBack = if (selectedUserId != null || selectedWaypointId != null) {-            {-                if (state.historyMode) actions.setShowingPresent(true) else actions.clearSelection()-            }-        } else null,+        onNavigateBack = null,         actions = overlayActions,-        // The overlay draws no container of its own, so the history title carries its own-        // surface to stay legible over the map.-        title = if (state.historyMode) {-            {-                Card(Modifier.padding(start = Spacing.sm)) {-                    Text(-                        stringResource(R.string.history_title, state.selectedUser?.name ?: ""),-                        Modifier.padding(horizontal = Spacing.md, vertical = Spacing.sm),-                        style = MaterialTheme.typography.titleMedium,-                        maxLines = 1,-                        overflow = TextOverflow.Ellipsis-                    )-                }-            }-        } else null+        title = null     ) }
findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.ktindex 1025a25e85..c416e4e749 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainSheetContent.kt@@ -154,8 +154,6 @@ import kotlin.time.Instant internal fun MainSheetContent(     state: MainPageUiState,     familyActions: FamilyListActions,-    personActions: PersonActions,-    actions: MainPageActions, ) {     // The sheet's own content MUST be taller than the peek, or Material3 emits a single     // anchor and the scaffold crashes.@@ -167,41 +165,10 @@ internal fun MainSheetContent(     // measure pass. That is a hard FATAL, and it is reached by an ordinary route: a fresh     // install has no family members, so FamilyListSheet is close to empty.     //-    // Enforced here, around every branch, rather than inside each one: the history-mode-    // branch below is deliberately empty, and a future branch would inherit the same trap.+    // Person/waypoint sheets are separate destinations (Route.PersonSheet /+    // Route.WaypointSheet) over the map; this in-page sheet always shows the+    // family list.     Box(Modifier.heightIn(min = SheetPeekHeight + SheetMinContentMargin)) {-        if (state.nothingSelected) {         FamilyListSheet(state.familyList, familyActions)-    } else if (state.historyMode) {-        // History mode has no sheet; the name is shown in the map overlay.-    } else if (state.selectedUserId != null) {-        state.person?.let { PersonDetailSheet(it, personActions) }-    } else if (state.selectedWaypointId != null) {-        Column(Modifier.fillMaxWidth().navigationBarsPadding().padding(horizontal = 12.dp, vertical = 4.dp)) {-            OutlinedTextField(-                state.waypointName,-                { actions.setWaypointName(it) },-                Modifier.fillMaxWidth(),-                isError = state.waypointName.isBlank(),-                supportingText = if (state.waypointName.isBlank()) {-                    { Text(stringResource(R.string.waypoint_name_blank_error)) }-                } else null-            )-            Spacer(Modifier.height(8.dp))-            OutlinedTextField(-                state.waypointRange,-                { actions.setWaypointRange(it) },-                Modifier.fillMaxWidth(),-                suffix = { Text(stringResource(R.string.waypoint_range_suffix)) },-                keyboardOptions = KeyboardOptions(-                    keyboardType = KeyboardType.Decimal-                ),-                isError = state.waypointRange.toDoubleOrNull() == null,-                supportingText = if (state.waypointRange.toDoubleOrNull() == null) {-                    { Text(stringResource(R.string.waypoint_range_error)) }-                } else null-            )-        }-    }     } }
findfamily/src/main/java/com/vayunmathur/findfamily/ui/PersonSheet.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/PersonSheet.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/PersonSheet.ktnew file mode 100644index 0000000000..e0e94b5caf--- /dev/null+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/PersonSheet.kt@@ -0,0 +1,162 @@+package com.vayunmathur.findfamily.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.compose.ui.window.Dialog+import com.vayunmathur.findfamily.R+import com.vayunmathur.findfamily.Route+import com.vayunmathur.findfamily.ui.dialogs.SecurityCodeDialog+import com.vayunmathur.findfamily.util.FindFamilyViewModel+import com.vayunmathur.findfamily.util.Networking+import com.vayunmathur.findfamily.util.PersonActions+import com.vayunmathur.findfamily.util.PersonUiState+import com.vayunmathur.findfamily.util.Platform+import com.vayunmathur.findfamily.util.UwbSessionManager+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconRestore+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.NavBackStack++/**+ * Sheet destination for one person (`Route.PersonSheet`), shown over the+ * map. The route argument is the selection: this entry exists only while a+ * person is selected, and dismissing it (back / scrim) pops back to the map.+ *+ * Hosts the person detail sheet plus the actions that used to branch on the+ * selected user in the map overlay/FAB: Find Nearby, verify, delete, and+ * entering history mode (the scrubber renders here; the map underneath+ * keeps showing the historical pin for [userId]).+ */+@Composable+fun PersonSheet(+    backStack: NavBackStack<Route>,+    ffViewModel: FindFamilyViewModel,+    platform: Platform,+    userId: Long,+) {+    // A pushed person starts in present mode with no stale historical pin.+    LaunchedEffect(userId) { ffViewModel.mapState.onPersonOpened() }++    val users by ffViewModel.users.collectAsState()+    val user = users.firstOrNull { it.id == userId }+    val userPositions by ffViewModel.latestLocationByUser.collectAsState()+    val waypoints by ffViewModel.waypoints.collectAsState()+    val globalSharingEnabled by ffViewModel.globalSharingEnabled.collectAsState()+    val crowdFindingEnabled by ffViewModel.crowdFindingEnabled.collectAsState()+    val connectedUsers by ffViewModel.connectedUsers.collectAsState()+    val isShowingPresent by ffViewModel.isShowingPresent.collectAsState()+    val historyMode = !isShowingPresent++    var showSecurityCode by remember { mutableStateOf(false) }++    val requestPickContact = platform.requestPickContact { name, photo ->+        ffViewModel.updateContactNamePhoto(userId, name, photo)+    }+    val personActions = remember(ffViewModel) {+        object : PersonActions by ffViewModel {+            override fun changeConnectedContact() = requestPickContact()+        }+    }++    Dialog(onDismissRequest = { backStack.pop() }) {+        Card {+            Column(+                Modifier.padding(16.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {+                if (user == null) {+                    // Row deleted (or not yet loaded): nothing to show.+                    Text(stringResource(R.string.delete_person_content_description))+                } else if (historyMode) {+                    Text(+                        stringResource(R.string.history_title, user.name),+                        style = MaterialTheme.typography.titleMedium,+                    )+                    Box(Modifier.fillMaxWidth()) {+                        HistoryScrubber(backStack, ffViewModel, userId) {+                            ffViewModel.mapState.setHistoricalPosition(it)+                        }+                    }+                    OutlinedButton(+                        { ffViewModel.mapState.setShowingPresent(true) },+                        Modifier.fillMaxWidth(),+                    ) {+                        IconRestore()+                        Text(stringResource(R.string.history_title, user.name))+                    }+                } else {+                    PersonDetailSheet(+                        PersonUiState(+                            user,+                            userPositions[user.id],+                            waypoints,+                            globalSharingEnabled,+                            crowdFindingEnabled,+                            connectedUsers,+                        ),+                        personActions,+                    )+                    val context = LocalContext.current+                    val isSelf = userId == Networking.userid+                    if (!isSelf) {+                        Row(+                            Modifier.fillMaxWidth(),+                            horizontalArrangement = Arrangement.spacedBy(8.dp),+                        ) {+                            if (UwbSessionManager.isAvailable(context)) {+                                OutlinedButton(+                                    { backStack.add(Route.UwbRangingPage(userId)) },+                                    Modifier.weight(1f),+                                ) { Text(stringResource(R.string.find_nearby_content_description)) }+                            }+                            OutlinedButton(+                                { showSecurityCode = true },+                                Modifier.weight(1f),+                            ) { Text(stringResource(R.string.verify_security_code_content_description)) }+                        }+                        Row(+                            Modifier.fillMaxWidth(),+                            horizontalArrangement = Arrangement.spacedBy(8.dp),+                        ) {+                            OutlinedButton(+                                { ffViewModel.mapState.setShowingPresent(false) },+                                Modifier.weight(1f),+                            ) {+                                IconRestore()+                                Text(stringResource(R.string.history_title, user.name))+                            }+                            OutlinedButton(+                                {+                                    ffViewModel.deleteUser(user)+                                    backStack.pop()+                                },+                                Modifier.weight(1f),+                            ) { Text(stringResource(R.string.delete_person_content_description)) }+                        }+                    }+                }+            }+        }+    }++    if (showSecurityCode && user != null && userId != Networking.userid) {+        SecurityCodeDialog(user, ffViewModel) { showSecurityCode = false }+    }+}
findfamily/src/main/java/com/vayunmathur/findfamily/ui/WaypointSheet.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/WaypointSheet.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/WaypointSheet.ktnew file mode 100644index 0000000000..f67704e787--- /dev/null+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/WaypointSheet.kt@@ -0,0 +1,104 @@+package com.vayunmathur.findfamily.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.unit.dp+import androidx.compose.ui.window.Dialog+import com.vayunmathur.findfamily.R+import com.vayunmathur.findfamily.Route+import com.vayunmathur.findfamily.util.FindFamilyViewModel+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.NavBackStack++/**+ * Sheet destination for one waypoint (`Route.WaypointSheet`), shown over+ * the map. The route argument is the selection (0 = create a new place);+ * the editable form state itself (name / range / coordinate) lives in+ * `MapPageState` and is prefilled by `beginCreateWaypoint` /+ * `beginEditWaypoint` before this destination is pushed.+ *+ * The coordinate follows the map centre while the sheet is open (the map+ * underneath keeps reporting its dragged centre for the selected+ * waypoint), matching the previous in-page editor.+ */+@Composable+fun WaypointSheet(+    backStack: NavBackStack<Route>,+    ffViewModel: FindFamilyViewModel,+    waypointId: Long,+) {+    val waypointName by ffViewModel.waypointName.collectAsState()+    val waypointRange by ffViewModel.waypointRange.collectAsState()+    val waypoints by ffViewModel.waypoints.collectAsState()+    val existing = waypoints.firstOrNull { it.id == waypointId }++    Dialog(onDismissRequest = { backStack.pop() }) {+        Card {+            Column(+                Modifier.padding(16.dp),+                verticalArrangement = Arrangement.spacedBy(8.dp),+            ) {+                OutlinedTextField(+                    waypointName,+                    { ffViewModel.mapState.setWaypointName(it) },+                    Modifier.fillMaxWidth(),+                    isError = waypointName.isBlank(),+                    supportingText = if (waypointName.isBlank()) {+                        { Text(stringResource(R.string.waypoint_name_blank_error)) }+                    } else null,+                )+                OutlinedTextField(+                    waypointRange,+                    { ffViewModel.mapState.setWaypointRange(it) },+                    Modifier.fillMaxWidth(),+                    suffix = { Text(stringResource(R.string.waypoint_range_suffix)) },+                    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),+                    isError = waypointRange.toDoubleOrNull() == null,+                    supportingText = if (waypointRange.toDoubleOrNull() == null) {+                        { Text(stringResource(R.string.waypoint_range_error)) }+                    } else null,+                )+                Row(+                    Modifier.fillMaxWidth(),+                    horizontalArrangement = Arrangement.spacedBy(8.dp),+                ) {+                    OutlinedButton(+                        { backStack.pop() },+                        Modifier.weight(1f),+                    ) { Text(stringResource(android.R.string.cancel)) }+                    Button(+                        {+                            if (ffViewModel.mapState.saveCurrentWaypoint(waypointId)) {+                                backStack.pop()+                            }+                        },+                        Modifier.weight(1f),+                    ) { Text(stringResource(android.R.string.ok)) }+                }+                if (waypointId != 0L && existing != null) {+                    OutlinedButton(+                        {+                            ffViewModel.deleteWaypoint(existing)+                            backStack.pop()+                        },+                        Modifier.fillMaxWidth(),+                    ) { Text(stringResource(R.string.delete_place_content_description)) }+                }+            }+        }+    }+}
findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.ktindex 249864e9f3..3573c5123d 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt@@ -37,8 +37,11 @@ data class FamilyListUiState(  * Family-sheet callbacks. Every method has a no-op default so a preview can render the  * sheet without supplying behaviour โ€” [Noop] is the whole implementation a preview needs.  *- * [FindFamilyViewModel] implements the three that are pure state changes; the two that- * need the nav back stack or the clipboard are supplied by the caller.+ * [selectUser] and [beginEditWaypoint] are navigation actions (they push+ * `Route.PersonSheet` / `Route.WaypointSheet`); the caller that owns the back+ * stack supplies them. [FindFamilyViewModel] implements only the pure+ * data change ([deleteTemporaryLink], plus the waypoint-form prefill behind+ * `beginEditWaypoint`).  */ interface FamilyListActions {     fun selectUser(userId: Long) {}@@ -102,58 +105,34 @@ interface PersonActions {  /**  * Everything the stateless map-page layout (`MainPageContent`) needs to lay out its chrome:- * which sheet to show, the top-bar contents and the floating action button. It carries plain+ * the family sheet, the top-bar contents and the floating action button. It carries plain  * data only โ€” no ViewModel โ€” so both the real app and the store-listing previews can build it.  *+ * Selection is deliberately absent: `MainPage` always shows the family list.+ * The selected person/place lives in the back stack (`Route.PersonSheet` /+ * `Route.WaypointSheet`) and its UI is hosted by those destinations.+ *  * The map itself is passed to `MainPageContent` as a slot, so this state deliberately says  * nothing about map tiles or the camera.  */ data class MainPageUiState(-    val selectedUserId: Long? = null,-    val selectedWaypointId: Long? = null,-    /** False while viewing a contact's past track (history mode). */-    val isShowingPresent: Boolean = true,     val usingGpsFallback: Boolean = false,-    /** Whether UWB "Find Nearby" is available on this device (controls the overlay entry). */-    val uwbAvailable: Boolean = false,-    /** This device's own user id, so the layout can hide self-only controls. */-    val selfUserId: Long = -1L,-    /** The selected contact, resolved for the person sheet, history title and delete action. */-    val selectedUser: User? = null,-    val waypointName: String = "",-    val waypointRange: String = "",     val familyList: FamilyListUiState = FamilyListUiState(),-    /** Built for [selectedUser] when a person (not a place) is selected. */-    val person: PersonUiState? = null,-) {-    /** A contact is selected and we're viewing their past track. */-    val historyMode: Boolean get() = selectedUserId != null && !isShowingPresent-    val isSelfSelected: Boolean get() = selectedUserId != null && selectedUserId == selfUserId-    val nothingSelected: Boolean get() = selectedUserId == null && selectedWaypointId == null-}+)  /**  * Map-overlay and FAB callbacks for the map page. Same no-op-default arrangement as the sheet  * action interfaces so [Noop] is all a preview needs. The stateful `MainPage` wires these to- * the ViewModel and nav back stack.+ * the ViewModel and nav back stack. Selection-scoped actions (delete, UWB,+ * history, waypoint save) live on the `PersonSheet` / `WaypointSheet`+ * destinations, not here.  */ interface MainPageActions {-    fun clearSelection() {}-    fun setShowingPresent(present: Boolean) {}     fun onGpsWarningClick() {}-    fun onShowSecurityCode() {}-    fun openUwbRanging(userId: Long) {}-    fun deleteSelectedUser() {}-    fun deleteSelectedWaypoint() {}     fun addPerson() {}     fun beginCreateWaypoint() {}     fun addLink() {}     fun addTracker() {}-    fun saveCurrentWaypoint() {}-    /** Enter history mode for the selected contact. */-    fun enterHistory() {}-    fun setWaypointName(name: String) {}-    fun setWaypointRange(range: String) {}      /** No-op [MainPageActions] for previews. */     companion object {
findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.ktindex 1131d1ab31..e68644a60a 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyViewModel.kt@@ -30,13 +30,11 @@ import com.vayunmathur.findfamily.R import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.library.util.DatabaseHelper import kotlinx.coroutines.Dispatchers-import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow-import kotlinx.coroutines.flow.flatMapLatest-import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch@@ -51,7 +49,9 @@ import kotlin.time.Duration.Companion.minutes  * ViewModel for the FindFamily app.  *  * Owns:- *  - selection state (selected user / waypoint, history vs present, historical position)+ *  - history-vs-present state, the historical position, and the waypoint+ *    editing form (which person/place is selected lives in the navigation+ *    back stack โ€” `Route.PersonSheet` / `Route.WaypointSheet` โ€” not here)  *  - waypoint editing form state + persistence  *  - exposed DB-backed flows for users / waypoints / temporary links and the  *    latest LocationValue per user (`latestLocationByUser`)@@ -225,27 +225,16 @@ class FindFamilyViewModel(     // ------------------------------------------------------------------      /**-     * Which user / waypoint is selected, present-vs-history, the historical-     * position, and the waypoint editing form. Lives in [MapPageState] so this-     * class stays under the function cap; the StateFlows below are the same-     * observables as before.+     * Present-vs-history, the historical position, and the waypoint editing+     * form. Lives in [MapPageState] so this class stays under the function+     * cap; the StateFlows below are the same observables as before. Selection+     * itself is not here โ€” it is the top of the navigation back stack.      */     val mapState = MapPageState(viewModelScope, repository) -    val selectedUserId: StateFlow<Long?> = mapState.selectedUserId     val isShowingPresent: StateFlow<Boolean> = mapState.isShowingPresent     val historicalPosition: StateFlow<GeoPoint?> = mapState.historicalPosition -    override fun selectUser(userId: Long) = mapState.selectUser(userId)--    /**-     * Apply the initial selection passed in via navigation. Called from the-     * MainPage entry so that opening the screen with a deep-linked user or-     * waypoint id selects it on arrival.-     */-    fun applyInitialSelection(initialUserId: Long?, initialWaypointId: Long?) =-        mapState.applyInitialSelection(initialUserId, initialWaypointId)-     val waypointName: StateFlow<String> = mapState.waypointName     val waypointRange: StateFlow<String> = mapState.waypointRange @@ -253,16 +242,16 @@ class FindFamilyViewModel(     override fun beginEditWaypoint(waypoint: Waypoint) = mapState.beginEditWaypoint(waypoint)      // -------------------------------------------------------------------    // Per-user location history (raw, filtered by selected user)+    // Per-user location history (raw, keyed by the person-sheet route arg)     // ------------------------------------------------------------------ -    @OptIn(ExperimentalCoroutinesApi::class)-    val locationHistory: StateFlow<List<LocationValue>> = mapState.selectedUserId-        .flatMapLatest { userId ->-            if (userId == null) flowOf(emptyList())-            else repository.locationHistory(userId)-        }-        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())+    /**+     * Raw location history for [userId]. The id comes from the+     * `Route.PersonSheet` route argument at the call site โ€” the ViewModel+     * holds no selection to key this off.+     */+    fun locationHistory(userId: Long): Flow<List<LocationValue>> =+        repository.locationHistory(userId)      // ------------------------------------------------------------------     // Permissions
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingNotifications.ktindex 51585c53f8..4b340604cb 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingNotifications.kt@@ -148,7 +148,7 @@ internal fun Context.notifyNoShowAlert(     FindFamilyNotificationChannels.ensureNoShowChannel(this, user.id, user.name)     val channelId = FindFamilyNotificationChannels.noShowChannelId(user.id)     // Deep-link to the watched person / expected place: MainActivity routes-    // Route.MainPage(selectedUserId, selectedWaypointId) from these extras.+    // Route.PersonSheet(watchedUserId) from these extras.     val openIntent = Intent(this, MainActivity::class.java).apply {         putExtra(EXTRA_NOSHOW_USER_ID, user.id)         if (waypointId != null) putExtra(EXTRA_NOSHOW_WAYPOINT_ID, waypointId)
findfamily/src/main/java/com/vayunmathur/findfamily/util/MapPageState.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/MapPageState.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/MapPageState.ktindex d2f3dc6376..90b480c7f9 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/MapPageState.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/MapPageState.kt@@ -10,28 +10,23 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch-import kotlinx.coroutines.withContext  /**  * Map-page UI state extracted from [FindFamilyViewModel] so the ViewModel  * stays under the function cap.  *- * Owns which user / waypoint is selected, present-vs-history display, the- * historical position, and the waypoint editing form (name / range /- * coordinate + edited id, persisted through [repository] on [scope]).- * Selection writes are synchronous; only [saveCurrentWaypoint] launches.+ * Owns present-vs-history display, the historical position, and the waypoint+ * editing form (name / range / coordinate, persisted through [repository] on+ * [scope]). Which person/place is selected is NOT held here: selection lives+ * in the navigation back stack (`Route.PersonSheet` / `Route.WaypointSheet`),+ * and call sites receive the selected id from the route. Only+ * [saveCurrentWaypoint] launches.  */ class MapPageState(     private val scope: CoroutineScope,     private val repository: FindFamilyRepository, ) { -    private val _selectedUserId = MutableStateFlow<Long?>(null)-    val selectedUserId: StateFlow<Long?> = _selectedUserId.asStateFlow()--    private val _selectedWaypointId = MutableStateFlow<Long?>(null)-    val selectedWaypointId: StateFlow<Long?> = _selectedWaypointId.asStateFlow()-     private val _isShowingPresent = MutableStateFlow(true)     val isShowingPresent: StateFlow<Boolean> = _isShowingPresent.asStateFlow() @@ -47,13 +42,6 @@ class MapPageState(     private val _waypointCoord = MutableStateFlow(Coord(0.0, 0.0))     val waypointCoord: StateFlow<Coord> = _waypointCoord.asStateFlow() -    fun setSelectedUserId(id: Long?) {-        _selectedUserId.value = id-        // A new person means no historical pin yet: never show whoever was viewed-        // before as this person's position (GitHub #818 follow-up).-        _historicalPosition.value = null-    }-    fun setSelectedWaypointId(id: Long?) { _selectedWaypointId.value = id }     fun setShowingPresent(value: Boolean) {         _isShowingPresent.value = value         // Leaving history drops the historical pin with it, so it cannot linger as a@@ -65,37 +53,18 @@ class MapPageState(     fun setWaypointRange(range: String) { _waypointRange.value = range }     fun setWaypointCoord(coord: Coord) { _waypointCoord.value = coord } -    fun selectUser(userId: Long) {-        _selectedUserId.value = userId-        _selectedWaypointId.value = null-        _isShowingPresent.value = true-        // Same reason as setSelectedUserId: the newly selected person starts with no-        // historical pin of their own.-        _historicalPosition.value = null-    }--    fun clearSelection() {-        _selectedUserId.value = null-        _selectedWaypointId.value = null-        _historicalPosition.value = null-    }-     /**-     * Apply the initial selection passed in via navigation. Called from the-     * MainPage entry so that opening the screen with a deep-linked user or-     * waypoint id selects it on arrival.+     * Reset history state for a newly opened person sheet. Called when a+     * `Route.PersonSheet` is pushed: the newly selected person starts in+     * present mode with no historical pin of their own (GitHub #818).      */-    fun applyInitialSelection(initialUserId: Long?, initialWaypointId: Long?) {-        _selectedUserId.value = initialUserId-        _selectedWaypointId.value = initialWaypointId-        // A deep link can swap the person while history mode stays on, so the previous-        // person's pin must not survive the switch.+    fun onPersonOpened() {+        _isShowingPresent.value = true         _historicalPosition.value = null     }      /** Begin creating a brand-new waypoint with sensible defaults. */     fun beginCreateWaypoint() {-        _selectedWaypointId.value = 0L         _waypointName.value = ""         _waypointRange.value = "100"         _waypointCoord.value = Coord(0.0, 0.0)@@ -103,28 +72,26 @@ class MapPageState(      /** Begin editing an existing waypoint, prefilling the form. */     fun beginEditWaypoint(waypoint: Waypoint) {-        _selectedWaypointId.value = waypoint.id         _waypointName.value = waypoint.name         _waypointRange.value = waypoint.range.toString()         _waypointCoord.value = waypoint.coord     }      /**-     * Persist the in-progress waypoint. Silently no-ops if the form is invalid-     * (matching the original FAB-click behaviour).+     * Persist the in-progress waypoint [waypointId] (0 means create). Returns+     * false without touching the repository if the form is invalid (matching+     * the original FAB-click behaviour); the caller pops the sheet only on+     * true.      */-    fun saveCurrentWaypoint() {+    fun saveCurrentWaypoint(waypointId: Long): Boolean {         val name = _waypointName.value-        val range = _waypointRange.value.toDoubleOrNull() ?: return-        if (name.isBlank()) return-        val id = _selectedWaypointId.value ?: return+        val range = _waypointRange.value.toDoubleOrNull() ?: return false+        if (name.isBlank()) return false         val coord = _waypointCoord.value         scope.launch(Dispatchers.IO) {-            val base = if (id == 0L) Waypoint.NEW_WAYPOINT else repository.waypointStore.get(id)+            val base = if (waypointId == 0L) Waypoint.NEW_WAYPOINT else repository.waypointStore.get(waypointId)             repository.waypointStore.upsert(base.copy(name = name, range = range, coord = coord))-            withContext(Dispatchers.Main) {-                _selectedWaypointId.value = null-            }         }+        return true     } }
findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt
diff --git a/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt b/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.ktindex 4ca2f7e3a0..f7060c0e50 100644--- a/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt+++ b/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt@@ -193,7 +193,6 @@ class MetadataPreviews {             MainPageContent(                 state = MainPageUiState(familyList = sampleFamilyList()),                 familyActions = FamilyListActions.Noop,-                personActions = PersonActions.Noop,                 actions = MainPageActions.Noop,                 map = { StaticMapBackdrop() },             )@@ -205,17 +204,15 @@ class MetadataPreviews {     @Composable     fun Preview2Person() {         DynamicTheme(darkTheme = true) {-            MainPageContent(-                state = MainPageUiState(-                    selectedUserId = maya.id,-                    selectedUser = maya,-                    person = PersonUiState(user = maya, location = mayaLocation, waypoints = sampleWaypoints),-                ),-                familyActions = FamilyListActions.Noop,-                personActions = PersonActions.Noop,-                actions = MainPageActions.Noop,-                map = { StaticMapBackdrop() },-            )+            // Person UI is now the Route.PersonSheet destination; preview+            // its sheet content directly over the static map backdrop.+            Box(Modifier.fillMaxSize()) {+                StaticMapBackdrop()+                PersonDetailSheet(+                    PersonUiState(user = maya, location = mayaLocation, waypoints = sampleWaypoints),+                    PersonActions.Noop,+                )+            }         }     } 
findfamily/src/test/java/com/vayunmathur/findfamily/ui/DialogsWithVmTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/DialogsWithVmTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/DialogsWithVmTest.ktindex cc1d4aab1c..b14b64ac47 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/DialogsWithVmTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/DialogsWithVmTest.kt@@ -51,7 +51,7 @@ class DialogsWithVmTest {         vm = FindFamilyViewModel(app, repo)     } -    private fun stack(): NavBackStack<Route> = NavBackStack(arrayOf(Route.MainPage()))+    private fun stack(): NavBackStack<Route> = NavBackStack(arrayOf(Route.MainPage))      private fun user(name: String = "Alice") = User(         name = name, photo = null, locationName = "Home", sendingEnabled = true,
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageActionsRealRepoTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageActionsRealRepoTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageActionsRealRepoTest.ktindex 9a924278ff..7ea4248dc4 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageActionsRealRepoTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageActionsRealRepoTest.kt@@ -63,28 +63,21 @@ class MainPageActionsRealRepoTest {         ))         val alice = repo.getUser(aliceId)!!         val wpId = repo.waypointStore.upsert(Waypoint(name = "Home", range = 100.0, coord = Coord(1.0, 2.0)))-        val stack = NavBackStack<Route>(arrayOf(Route.MainPage()))+        val stack = NavBackStack<Route>(arrayOf(Route.MainPage))         var gpsShown = false-        var securityShown = false-        var contactPicks = 0-        var captured: Triple<+        var captured: Pair<             com.vayunmathur.findfamily.util.FamilyListActions,-            com.vayunmathur.findfamily.util.PersonActions,             MainPageActions>? = null         rule.setContent {             DynamicTheme {                 captured = rememberMainPageActions(                     ffViewModel = vm, backStack = stack, platform = Platform(ctx),-                    selectedUser = alice, selectedWaypointId = wpId,-                    waypoints = runBlocking { repo.waypointStore.getAll() },                     onShowGpsWarning = { gpsShown = it },-                    onShowSecurityCode = { securityShown = it },-                    requestPickContact = { contactPicks++ },                 )             }         }         rule.waitForIdle()-        val (family, person, main) = captured!!+        val (family, main) = captured!!         // Family actions: accepting a request pushes the prefilled Add Person dialog.         family.acceptRequest(777L)         assertEquals(Route.AddPersonDialog(777L), stack.last())@@ -98,14 +91,19 @@ class MainPageActionsRealRepoTest {             pqcPublicKey = "bundle", pqcKey = "full-key", id = 124L))         assertTrue(clipboard.primaryClip?.getItemAt(0)?.text?.toString()?.endsWith("#pqc_key=full-key") == true)         family.deleteTemporaryLink(TemporaryLink(name = "x", deleteAt = Clock.System.now(), pqcPublicKey = "b", id = 1L))+        // Selection is navigation: tapping a person/waypoint pushes its sheet+        // destination (the stack is the only selection holder).         family.selectUser(aliceId)+        assertEquals(Route.PersonSheet(aliceId), stack.last())+        stack.pop()         family.beginEditWaypoint(repo.waypointStore.get(wpId))-        // Person actions delegate to the contact picker.-        person.changeConnectedContact()-        assertEquals(1, contactPicks)-        person.setUserSharing(alice, false)+        assertEquals(Route.WaypointSheet(wpId), stack.last())+        assertEquals("Home", vm.waypointName.value)+        stack.pop()+        // Person-scoped actions live on the sheet destination / ViewModel.+        vm.setUserSharing(alice, false)         assertTrue(awaitFamilyCondition { repo.getUser(aliceId)?.sendingEnabled == false })-        // Main actions: dialogs, selection and waypoint form.+        // Main actions: dialogs and waypoint creation.         main.addPerson()         assertEquals(Route.AddPersonDialog(), stack.last())         stack.pop()@@ -115,31 +113,22 @@ class MainPageActionsRealRepoTest {         main.addTracker()         assertEquals(Route.AddTrackerDialog, stack.last())         stack.pop()-        main.openUwbRanging(aliceId)-        assertEquals(Route.UwbRangingPage(aliceId), stack.last())-        stack.pop()         main.onGpsWarningClick()         assertTrue(gpsShown)-        main.onShowSecurityCode()-        assertTrue(securityShown)-        main.setWaypointName("Cabin")-        main.setWaypointRange("250")-        assertEquals("Cabin", vm.waypointName.value)-        assertEquals("250", vm.waypointRange.value)         main.beginCreateWaypoint()-        main.setWaypointName("New Place")-        main.saveCurrentWaypoint()+        assertEquals(Route.WaypointSheet(0L), stack.last())+        vm.mapState.setWaypointName("New Place")+        assertTrue(vm.mapState.saveCurrentWaypoint(0L))         assertTrue(awaitFamilyCondition { repo.waypointStore.getAll().any { it.name == "New Place" } })-        main.enterHistory()+        stack.pop()+        // History present/history toggling is MapPageState, driven by the sheet.+        vm.mapState.setShowingPresent(false)         assertEquals(false, vm.isShowingPresent.value)-        main.setShowingPresent(true)+        vm.mapState.onPersonOpened()         assertEquals(true, vm.isShowingPresent.value)-        vm.selectUser(aliceId)-        main.clearSelection()-        assertNull(vm.selectedUserId.value)-        // Deletes remove the rows and clear the selection.-        main.deleteSelectedWaypoint()-        main.deleteSelectedUser()+        // Deletes remove the rows (sheet destinations pop themselves after).+        vm.deleteWaypoint(repo.waypointStore.get(wpId))+        vm.deleteUser(alice)         assertTrue(awaitFamilyCondition { repo.getUser(aliceId) == null })         Unit     }
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageChromeRealRepoTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageChromeRealRepoTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageChromeRealRepoTest.ktindex 3fa44f9b8c..189ac483b0 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageChromeRealRepoTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageChromeRealRepoTest.kt@@ -134,12 +134,11 @@ class MainPageChromeRealRepoTest {         assertTrue(rule.onAllNodesWithText("home-place", substring = true).fetchSemanticsNodes().isNotEmpty())     } -    @Test fun pageEffectsShowSecurityAndGpsDialogs() = runBlocking {+    @Test fun pageEffectsShowGpsDialog() = runBlocking {         val alice = repo.upsertUser(User(             name = "Alice", photo = null, locationName = "Home", sendingEnabled = true,             requestStatus = RequestStatus.MUTUAL_CONNECTION, lastLocationChangeTime = Clock.System.now(),         ))-        var security = true         var gps = true         rule.setContent {             DynamicTheme {@@ -149,7 +148,6 @@ class MainPageChromeRealRepoTest {                     selfUserId = Networking.userid, isShowingPresent = true,                     historicalPosition = null, userPositions = emptyMap(),                     selectedWaypointId = null, waypoints = emptyList(),-                    showSecurityCode = security, onShowSecurityCode = { security = it },                     showGpsWarning = gps, onShowGpsWarning = { gps = it },                 )             }@@ -157,7 +155,7 @@ class MainPageChromeRealRepoTest {         rule.waitForIdle()         Thread.sleep(300)         rule.waitForIdle()-        assertTrue(rule.onAllNodesWithText("Alice", substring = true).fetchSemanticsNodes().isNotEmpty())+        assertTrue(rule.onAllNodesWithText("GPS", substring = true).fetchSemanticsNodes().isNotEmpty())         Unit     } 
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.ktindex ba39efdba4..af61db614d 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageContentTest.kt@@ -37,10 +37,8 @@ class MainPageContentTest {     private class RecordingActions : MainPageActions {         var addPerson = 0         var addLink = 0-        var clear = 0         override fun addPerson() { addPerson++ }         override fun addLink() { addLink++ }-        override fun clearSelection() { clear++ }     }      private fun content(state: MainPageUiState, actions: MainPageActions) {@@ -49,7 +47,6 @@ class MainPageContentTest {                 MainPageContent(                     state = state,                     familyActions = FamilyListActions.Noop,-                    personActions = PersonActions.Noop,                     actions = actions,                     map = { Text("MAP-SLOT") })             }@@ -64,22 +61,20 @@ class MainPageContentTest {         composeRule.onNodeWithText("Ann").assertIsDisplayed()     } -    @Test fun personSelectedShowsPersonSheet() {+    @Test fun personSheetContentShowsDetail() {+        // Person UI moved to the Route.PersonSheet destination; the sheet+        // content itself is still PersonDetailSheet over PersonUiState.         val ann = user(2L, "Ann")-        val state = MainPageUiState(-            selectedUserId = 2L,-            selectedUser = ann,-            person = PersonUiState(user = ann),-            familyList = FamilyListUiState(connectedUsers = listOf(ann)))-        content(state, RecordingActions())+        composeRule.setContent {+            DynamicTheme {+                PersonDetailSheet(PersonUiState(user = ann), PersonActions.Noop)+            }+        }         composeRule.onNodeWithText("Ann").assertIsDisplayed()     } -    @Test fun waypointSelectedShowsWaypointForm() {+    @Test fun familySheetListsWaypoints() {         val state = MainPageUiState(-            selectedWaypointId = 5L,-            waypointName = "Home",-            waypointRange = "150",             familyList = FamilyListUiState(                 waypoints = listOf(Waypoint("Home", 150.0, Coord(1.0, 2.0), id = 5L))))         content(state, RecordingActions())
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageInteractionsTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageInteractionsTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageInteractionsTest.ktindex baaddb84fa..1ca401b854 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageInteractionsTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageInteractionsTest.kt@@ -65,7 +65,7 @@ class MainPageInteractionsTest {             override fun acceptRequest(userId: Long) { accepted = userId }         }         rule.setContent {-            MainPageContent(state = state, familyActions = actions, personActions = PersonActions.Noop,+            MainPageContent(state = state, familyActions = actions,                 actions = MainPageActions.Noop, map = {}, backupPassphrase = "pw")         }         rule.waitForIdle()
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageNavigationRealRepoTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageNavigationRealRepoTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageNavigationRealRepoTest.ktindex d6c0d9b6bc..e4c4b6af12 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageNavigationRealRepoTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MainPageNavigationRealRepoTest.kt@@ -41,7 +41,8 @@ import kotlin.time.Clock  * entries never executed. Here the ViewModel is backed by genuine Room  * rows (see [TestFindFamilyRepository]) and the full graph composes:  * family sheet, person sheet, waypoint form, history scrubber and every- * dialog entry the deep links can push.+ * dialog entry the deep links can push. Selection is route-carried+ * (PersonSheet/WaypointSheet destinations), never ViewModel state.  */ @RunWith(AndroidJUnit4::class) class MainPageNavigationRealRepoTest {@@ -144,35 +145,36 @@ class MainPageNavigationRealRepoTest {         assertTrue(rule.onAllNodesWithText("Alice", substring = true).fetchSemanticsNodes().isNotEmpty())     } -    @Test fun mainPageDirectWithSelectedUserShowsPersonSheet() { runBlocking {+    @Test fun personSheetShowsPersonDetail() { runBlocking {         seedFamily()         val alice = repo.getAllUsers().first { it.name == "Alice" }-        vm.selectUser(alice.id)-        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { MainPage(Platform(app), stack(), vm, alice.id, null) } } }+        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { PersonSheet(stack(), vm, Platform(app), alice.id) } } }         rule.waitForIdle()-        rule.onNodeWithText("Alice", substring = true).assertIsDisplayed()+        // Person detail shows Alice in both the header and the name field.+        rule.onAllNodesWithText("Alice", substring = true)[0].assertIsDisplayed()     } } -    @Test fun mainPageDirectWithSelectedWaypointShowsForm() = runBlocking {+    @Test fun waypointSheetShowsEditorForm() = runBlocking {         seedFamily()         val wp = repo.waypointStore.getAll().single()         vm.beginEditWaypoint(wp)-        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { MainPage(Platform(app), stack(), vm, null, wp.id) } } }+        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { WaypointSheet(stack(), vm, wp.id) } } }         rule.waitForIdle()         assertTrue(rule.onAllNodesWithText("Home", substring = true).fetchSemanticsNodes().isNotEmpty())     } -    @Test fun mainPageDirectInHistoryModeShowsScrubber() = runBlocking {+    @Test fun personSheetInHistoryModeShowsScrubber() = runBlocking {         seedFamily()         val alice = repo.getAllUsers().first { it.name == "Alice" }-        vm.selectUser(alice.id)+        // PersonSheet resets to present on open; enter history explicitly.+        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { PersonSheet(stack(), vm, Platform(app), alice.id) } } }+        rule.waitForIdle()         vm.mapState.setShowingPresent(false)-        rule.setContent { androidx.compose.runtime.CompositionLocalProvider(com.vayunmathur.library.util.LocalNavResultRegistry provides com.vayunmathur.library.util.NavResultRegistry()) { DynamicTheme { MainPage(Platform(app), stack(), vm, alice.id, null) } } }         rule.waitForIdle()         assertTrue(rule.onAllNodesWithText("Alice", substring = true).fetchSemanticsNodes().isNotEmpty())     }      private fun stack() = com.vayunmathur.library.util.NavBackStack<com.vayunmathur.findfamily.Route>(-        arrayOf(com.vayunmathur.findfamily.Route.MainPage())+        arrayOf(com.vayunmathur.findfamily.Route.MainPage)     ) }
findfamily/src/test/java/com/vayunmathur/findfamily/ui/MissingFeaturesDialogRealTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MissingFeaturesDialogRealTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MissingFeaturesDialogRealTest.ktindex 78cbdde334..8736482033 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MissingFeaturesDialogRealTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/MissingFeaturesDialogRealTest.kt@@ -25,10 +25,10 @@ class MissingFeaturesDialogRealTest {     private val ctx: Context get() = app      @Test fun dialogDismissesThroughBackStack() {-        val stack = NavBackStack<Route>(arrayOf(Route.MainPage(), Route.AddLinkDialog))+        val stack = NavBackStack<Route>(arrayOf(Route.MainPage, Route.AddLinkDialog))         rule.setContent { MissingFeaturesDialog(stack) }         rule.onNodeWithText("Required Features Disabled").assertIsDisplayed()         rule.onNodeWithText("OK").performClick()-        assertEquals(Route.MainPage(), stack.last())+        assertEquals(Route.MainPage, stack.last())     } }
findfamily/src/test/java/com/vayunmathur/findfamily/ui/OverlayBarsTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/OverlayBarsTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/OverlayBarsTest.ktindex a23348db95..dfb5c013d2 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/OverlayBarsTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/OverlayBarsTest.kt@@ -15,7 +15,6 @@ import com.vayunmathur.findfamily.data.RequestStatus import com.vayunmathur.findfamily.data.User import com.vayunmathur.findfamily.util.MainPageActions import com.vayunmathur.findfamily.util.MainPageUiState-import com.vayunmathur.findfamily.util.PersonUiState import org.junit.Rule import org.junit.runner.RunWith import kotlin.test.Test@@ -33,16 +32,10 @@ class OverlayBarsTest {         rule.setContent { MapOverlayBar(MainPageUiState(usingGpsFallback = true), MainPageActions.Noop, "pw") }         rule.waitForIdle()     }-    @Test fun overlayBarUserSelected() {-        val u = user(3L)-        rule.setContent {-            MapOverlayBar(MainPageUiState(selectedUserId = 3L, selectedUser = u, person = PersonUiState(user = u)), MainPageActions.Noop)-        }-        rule.waitForIdle()-        assertTrue(rule.onAllNodesWithText("Alice", substring = true).fetchSemanticsNodes().isNotEmpty() || true)-    }-    @Test fun overlayBarWaypointSelected() {-        rule.setContent { MapOverlayBar(MainPageUiState(selectedWaypointId = 5L), MainPageActions.Noop) }+    @Test fun overlayBarWithoutGpsFallback() {+        // Selection-scoped overlay actions moved to the sheet destinations;+        // the map overlay renders in its only (unselected) shape.+        rule.setContent { MapOverlayBar(MainPageUiState(), MainPageActions.Noop, "pw") }         rule.waitForIdle()     }     @Test fun fabOverlayNothingSelected() {@@ -55,10 +48,10 @@ class OverlayBarsTest {         }         rule.waitForIdle()     }-    @Test fun fabOverlayUserSelected() {+    @Test fun fabOverlayInPreview() {         rule.setContent {             Box(Modifier.fillMaxSize()) {-                MainFabOverlay(MainPageUiState(selectedUserId = 1L), MainPageActions.Noop, 80.dp, { 0 },+                MainFabOverlay(MainPageUiState(), MainPageActions.Noop, 80.dp, { 0 },                     MaterialTheme.colorScheme.primaryContainer, MaterialTheme.colorScheme.primary,                     MaterialTheme.colorScheme.onPrimaryContainer, lightColorScheme(), inPreview = true)             }
findfamily/src/test/java/com/vayunmathur/findfamily/ui/W5MainPageContentTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/W5MainPageContentTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/W5MainPageContentTest.ktindex 3f55d22c8c..7ef9709c13 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/W5MainPageContentTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/W5MainPageContentTest.kt@@ -3,28 +3,22 @@ package com.vayunmathur.findfamily.ui import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText-import androidx.compose.ui.test.performTextInput import androidx.test.ext.junit.runners.AndroidJUnit4-import com.vayunmathur.findfamily.data.Coord import com.vayunmathur.findfamily.data.RequestStatus import com.vayunmathur.findfamily.data.User-import com.vayunmathur.findfamily.data.Waypoint import com.vayunmathur.findfamily.util.FamilyListActions import com.vayunmathur.findfamily.util.FamilyListUiState-import com.vayunmathur.findfamily.util.MainPageActions import com.vayunmathur.findfamily.util.MainPageUiState-import com.vayunmathur.findfamily.util.PersonActions-import com.vayunmathur.findfamily.util.PersonUiState import kotlin.time.Clock import org.junit.Rule import org.junit.runner.RunWith import kotlin.test.Test-import kotlin.test.assertEquals  /**- * Robolectric Compose tests for [MainPageContent] (via the internal- * [MainSheetContent] branches plus overlay chrome): empty list, person- * detail, history mode, and the waypoint editor form.+ * Robolectric Compose tests for the in-page sheet ([MainSheetContent]):+ * it always renders the family list now โ€” person/waypoint sheets are the+ * `Route.PersonSheet` / `Route.WaypointSheet` destinations, covered by+ * navigation-level tests.  */ @RunWith(AndroidJUnit4::class) class W5MainPageContentTest {@@ -42,18 +36,11 @@ class W5MainPageContentTest {         id = id,     ) -    private fun content(-        state: MainPageUiState,-        actions: MainPageActions = MainPageActions.Noop,-    ) {-        // MainSheetContent directly: the scaffold sheet keeps its content-        // collapsed/off-screen, but the branch logic under test lives here.+    private fun content(state: MainPageUiState) {         rule.setContent {             MainSheetContent(                 state = state,                 familyActions = FamilyListActions.Noop,-                personActions = PersonActions.Noop,-                actions = actions,             )         }     }@@ -73,71 +60,4 @@ class W5MainPageContentTest {         )         rule.onNodeWithText("Alice").assertIsDisplayed()     }--    @Test-    fun personSelectedShowsDetail() {-        val u = user(1L)-        content(-            MainPageUiState(-                selectedUserId = 1L,-                selectedUser = u,-                person = PersonUiState(user = u),-            ),-        )-        rule.onNodeWithText("Alice").assertIsDisplayed()-        rule.onNodeWithText("Change connected contact", substring = true).assertIsDisplayed()-    }--    @Test-    fun waypointEditorEditsName() {-        var name = "old"-        val actions = object : MainPageActions {-            override fun setWaypointName(value: String) {-                name = value-            }-        }-        rule.setContent {-            MainSheetContent(-                state = MainPageUiState(-                    selectedWaypointId = 3L,-                    waypointName = "old",-                    waypointRange = "100",-                ),-                familyActions = FamilyListActions.Noop,-                personActions = PersonActions.Noop,-                actions = actions,-            )-        }-        // The field reports edits through setWaypointName; typing appends to-        // the callback value observed here.-        rule.onNodeWithText("old").performTextInput("X")-        assertEquals("Xold", name)-    }--    @Test-    fun blankWaypointNameShowsError() {-        content(-            MainPageUiState(-                selectedWaypointId = 3L,-                waypointName = "",-                waypointRange = "100",-            ),-        )-        // Error text from R.string.waypoint_name_blank_error is shown.-        rule.waitForIdle()-    }--    @Test-    fun historyModeHidesSheetPersonCard() {-        val u = user(1L)-        content(-            MainPageUiState(-                selectedUserId = 1L,-                selectedUser = u,-                isShowingPresent = false,-                person = PersonUiState(user = u),-            ),-        )-        rule.waitForIdle()-    } }
findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/DialogsRealRepoInteractionsTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/DialogsRealRepoInteractionsTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/DialogsRealRepoInteractionsTest.ktindex ed7d38152c..d96030437f 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/DialogsRealRepoInteractionsTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/ui/dialogs/DialogsRealRepoInteractionsTest.kt@@ -61,7 +61,7 @@ class DialogsRealRepoInteractionsTest {         vm = FindFamilyViewModel(app, repo)     } -    private fun stack(): NavBackStack<Route> = NavBackStack(arrayOf(Route.MainPage()))+    private fun stack(): NavBackStack<Route> = NavBackStack(arrayOf(Route.MainPage))      private fun user(id: Long, name: String, status: RequestStatus = RequestStatus.MUTUAL_CONNECTION) = User(         name = name, photo = null, locationName = "Home", sendingEnabled = true,
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.ktindex 04b4aea13d..82a0b8e35b 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelDbTest.kt@@ -105,13 +105,12 @@ class FindFamilyViewModelDbTest {         // Repository one-shot sees the fix (same getLatest DAO query the VM flow wraps).         assertEquals(80f, kotlinx.coroutines.runBlocking { repo.latestLocationsOnce().firstOrNull()?.battery })         assertEquals(alice, kotlinx.coroutines.runBlocking { repo.latestLocationByUser.first().keys.firstOrNull() })-        // Selection + history-        vm.selectUser(alice)-        awaitTrue("location history") { vm.locationHistory.value.size == 1 }+        // History is keyed by the person-sheet route arg, passed explicitly.+        awaitTrue("location history") { kotlinx.coroutines.runBlocking { vm.locationHistory(alice).first().size == 1 } }         vm.mapState.setShowingPresent(false)         assertEquals(false, vm.isShowingPresent.value)-        vm.mapState.clearSelection()-        assertEquals(null, vm.selectedUserId.value)+        vm.mapState.onPersonOpened()+        assertEquals(true, vm.isShowingPresent.value)         collectJob.cancel()     } @@ -125,7 +124,7 @@ class FindFamilyViewModelDbTest {             CoroutineScope(Dispatchers.Default).async { vm.usersByLocationName.collect { } },             CoroutineScope(Dispatchers.Default).async { vm.waypoints.collect { } },             CoroutineScope(Dispatchers.Default).async { vm.latestLocationByUser.collect { } },-            CoroutineScope(Dispatchers.Default).async { vm.locationHistory.collect { } },+            CoroutineScope(Dispatchers.Default).async { vm.locationHistory(0L).collect { } },             CoroutineScope(Dispatchers.Default).async { vm.temporaryLinks.collect { } },         )         jobs.forEach { it.await() }@@ -142,7 +141,7 @@ class FindFamilyViewModelDbTest {         assertEquals("Gym", vm.waypointName.value)         vm.mapState.setWaypointName("Gym2")         vm.mapState.setWaypointRange("75")-        vm.mapState.saveCurrentWaypoint()+        assertTrue(vm.mapState.saveCurrentWaypoint(wpId))         awaitTrue("waypoint saved") { kotlinx.coroutines.runBlocking { repo.waypointStore.get(wpId).name == "Gym2" } }         vm.deleteWaypoint(repo.waypointStore.get(wpId))         awaitTrue("waypoint deleted") { kotlinx.coroutines.runBlocking { repo.waypointStore.getAll().isEmpty() } }@@ -158,19 +157,20 @@ class FindFamilyViewModelDbTest {     }      @Test-    fun waypointFormCreateAndInitialSelection() = runBlocking {+    fun waypointFormCreateAndPersonOpenedReset() = runBlocking {         val vm = FindFamilyViewModel(app, repo)         vm.mapState.beginCreateWaypoint()         vm.mapState.setWaypointName("Park")         vm.mapState.setWaypointRange("200")         vm.mapState.setWaypointCoord(Coord(5.0, 6.0))-        vm.mapState.saveCurrentWaypoint()+        assertTrue(vm.mapState.saveCurrentWaypoint(0L))         awaitTrue("waypoint created") { kotlinx.coroutines.runBlocking { repo.waypointStore.getAll().any { it.name == "Park" } } }-        val uid = repo.upsertUser(user("Frank"))-        vm.applyInitialSelection(uid, null)-        assertEquals(uid, vm.selectedUserId.value)-        vm.applyInitialSelection(null, repo.waypointStore.getAll().first().id)-        assertNotNull(vm.mapState.selectedWaypointId.value)+        // Opening a person sheet resets history mode and drops any stale pin.+        vm.mapState.setShowingPresent(false)+        vm.mapState.setHistoricalPosition(com.vayunmathur.library.map.GeoPoint(1.0, 2.0))+        vm.mapState.onPersonOpened()+        assertEquals(true, vm.isShowingPresent.value)+        assertEquals(null, vm.historicalPosition.value)         vm.refreshPermissions()         // Permission flags must be readable (values depend on Robolectric grants).         @Suppress("UNUSED_EXPRESSION") vm.hasForeground.value; vm.hasBackground.value; vm.hasBluetooth.value
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.ktindex bd6e6b465c..c503aa37f4 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelProbeTest.kt@@ -50,13 +50,12 @@ class FindFamilyViewModelProbeTest {         assertFalse(vm.hasForeground.value)     } -    @Test fun selectionDelegatesToMapState() {-        assertNull(vm.selectedUserId.value)-        vm.selectUser(11L)-        assertEquals(11L, vm.selectedUserId.value)+    @Test fun personOpenedAndWaypointFormDelegateToMapState() {+        // Selection lives in the back stack now; the VM only resets history+        // state when a person sheet opens and prefills the waypoint form.+        vm.mapState.setShowingPresent(false)+        vm.mapState.onPersonOpened()         assertTrue(vm.isShowingPresent.value)-        vm.applyInitialSelection(3L, 4L)-        assertEquals(3L, vm.selectedUserId.value)         val waypoint = com.vayunmathur.findfamily.data.Waypoint(             "Home", 100.0, com.vayunmathur.findfamily.data.Coord(1.0, 2.0), id = 8L)         vm.beginEditWaypoint(waypoint)
findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.ktindex 005b840d4b..7b2d0a104c 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/FindFamilyViewModelRealRepoTest.kt@@ -135,45 +135,44 @@ class FindFamilyViewModelRealRepoTest {         assertEquals(10.minutes, alert.grace)     } -    @Test fun selectionAndWaypointFormState() = runBlocking {+    @Test fun waypointFormAndHistoryState() = runBlocking {         val wpId = repo.waypointStore.upsert(Waypoint(name = "Office", range = 250.0, coord = Coord(3.0, 4.0)))-        vm.applyInitialSelection(7L, wpId)-        assertEquals(7L, vm.selectedUserId.value)-        assertEquals(wpId, vm.mapState.selectedWaypointId.value)         vm.beginEditWaypoint(repo.waypointStore.get(wpId))         assertEquals("Office", vm.waypointName.value)         assertEquals("250.0", vm.waypointRange.value)         vm.mapState.setWaypointName("Office 2")         vm.mapState.setWaypointRange("300")-        vm.mapState.saveCurrentWaypoint()+        assertTrue(vm.mapState.saveCurrentWaypoint(wpId))         await("waypoint saved") { repo.waypointStore.get(wpId).name == "Office 2" }         assertEquals(300.0, repo.waypointStore.get(wpId).range)         vm.mapState.beginCreateWaypoint()-        assertEquals(0L, vm.mapState.selectedWaypointId.value)         assertEquals("100", vm.waypointRange.value)         vm.mapState.setWaypointName("New Place")         vm.mapState.setWaypointCoord(Coord(5.0, 6.0))-        vm.mapState.saveCurrentWaypoint()+        assertTrue(vm.mapState.saveCurrentWaypoint(0L))         await("waypoint created") { repo.waypointStore.getAll().any { it.name == "New Place" } }-        vm.selectUser(9L)         vm.mapState.setShowingPresent(false)         assertFalse(vm.isShowingPresent.value)         vm.mapState.setHistoricalPosition(com.vayunmathur.library.map.GeoPoint(1.0, 2.0))         assertNotNull(vm.historicalPosition.value)         vm.mapState.setShowingPresent(true)         assertNull(vm.historicalPosition.value)-        vm.mapState.clearSelection()-        assertNull(vm.selectedUserId.value)+        // Opening another person also drops the pin and returns to present.+        vm.mapState.setShowingPresent(false)+        vm.mapState.setHistoricalPosition(com.vayunmathur.library.map.GeoPoint(3.0, 4.0))+        vm.mapState.onPersonOpened()+        assertTrue(vm.isShowingPresent.value)+        assertNull(vm.historicalPosition.value)     }      @Test fun invalidWaypointFormDoesNotPersist() = runBlocking {         vm.mapState.beginCreateWaypoint()         vm.mapState.setWaypointName("")-        vm.mapState.saveCurrentWaypoint()+        assertFalse(vm.mapState.saveCurrentWaypoint(0L))         assertTrue(repo.waypointStore.getAll().isEmpty())         vm.mapState.setWaypointName("Named")         vm.mapState.setWaypointRange("not-a-number")-        vm.mapState.saveCurrentWaypoint()+        assertFalse(vm.mapState.saveCurrentWaypoint(0L))         assertTrue(repo.waypointStore.getAll().isEmpty())     } @@ -227,7 +226,7 @@ class FindFamilyViewModelRealRepoTest {             kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch { vm.connectedUsers.collect {} },             kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch { vm.awaitingRequestUsers.collect {} },             kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch { vm.usersById.collect {} },-            kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch { vm.locationHistory.collect {} },+            kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.Default).launch { vm.locationHistory(0L).collect {} },         )         val alice = repo.upsertUser(user(name = "Alice"))         repo.upsertUser(user(name = "Bob", status = RequestStatus.AWAITING_REQUEST))@@ -248,9 +247,8 @@ class FindFamilyViewModelRealRepoTest {         assertEquals(listOf("Bob"), vm.awaitingRequestUsers.value.map { it.name })         await("by-id projected") { vm.usersById.value[alice]?.name == "Alice" }         assertEquals("Alice", vm.usersById.value[alice]?.name)-        vm.selectUser(alice)-        await("history projected") { vm.locationHistory.value.size == 1 }-        assertEquals(66f, vm.locationHistory.value.single().battery)+        await("history projected") { vm.locationHistory(alice).first().size == 1 }+        assertEquals(66f, vm.locationHistory(alice).first().single().battery)         collectors.forEach { it.cancel() }     } 
findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.ktindex 2498d5398c..69f3bb856c 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/MapAndControllerTest.kt@@ -18,7 +18,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.test.runTest -/** MapPageState form/selection logic and LocationServiceController persisted flags. */+/** MapPageState form/history logic and LocationServiceController persisted flags. */ @org.junit.runner.RunWith(org.robolectric.RobolectricTestRunner::class) class MapAndControllerTest { @@ -29,16 +29,14 @@ class MapAndControllerTest {     private fun mapState(): MapPageState =         MapPageState(CoroutineScope(Dispatchers.Unconfined), FindFamilyRepository.get(app)) -    @Test fun selectionTransitionsClearHistory() {+    @Test fun personOpenedClearsHistory() {         val s = mapState()-        assertNull(s.selectedUserId.value)         assertTrue(s.isShowingPresent.value)         s.setHistoricalPosition(GeoPoint(1.0, 2.0))-        s.selectUser(42L)-        assertEquals(42L, s.selectedUserId.value)-        assertNull(s.selectedWaypointId.value)+        // Opening a person sheet drops any stale historical pin and+        // returns to present mode (selection itself lives in the stack).+        s.onPersonOpened()         assertTrue(s.isShowingPresent.value)-        // Selecting a person drops any stale historical pin.         assertNull(s.historicalPosition.value)          s.setHistoricalPosition(GeoPoint(3.0, 4.0))@@ -47,42 +45,26 @@ class MapAndControllerTest {         s.setShowingPresent(false)         s.setHistoricalPosition(GeoPoint(5.0, 6.0))         assertEquals(GeoPoint(5.0, 6.0), s.historicalPosition.value)-        s.clearSelection()-        assertNull(s.selectedUserId.value)+        s.onPersonOpened()         assertNull(s.historicalPosition.value)     } -    @Test fun initialSelectionAppliesAndDropsPin() {-        val s = mapState()-        s.setHistoricalPosition(GeoPoint(1.0, 1.0))-        s.applyInitialSelection(7L, 9L)-        assertEquals(7L, s.selectedUserId.value)-        assertEquals(9L, s.selectedWaypointId.value)-        assertNull(s.historicalPosition.value)-        s.applyInitialSelection(null, null)-        assertNull(s.selectedUserId.value)-    }-     @Test fun waypointFormCreateEditAndInvalidSaves() {         val s = mapState()         s.beginCreateWaypoint()-        assertEquals(0L, s.selectedWaypointId.value)         assertEquals("", s.waypointName.value)         assertEquals("100", s.waypointRange.value)-        // Invalid forms silently no-op (no selection change, no DB write).-        s.saveCurrentWaypoint()-        assertEquals(0L, s.selectedWaypointId.value)+        // Invalid forms silently no-op (return false, no DB write).+        assertFalse(s.saveCurrentWaypoint(0L))         s.setWaypointName("Home")         s.setWaypointRange("not-a-number")-        s.saveCurrentWaypoint()-        assertEquals(0L, s.selectedWaypointId.value)+        assertFalse(s.saveCurrentWaypoint(0L))         s.setWaypointRange("250")         s.setWaypointCoord(Coord(38.7, -9.1))         assertEquals(Coord(38.7, -9.1), s.waypointCoord.value)          val existing = Waypoint("Work", 500.0, Coord(1.0, 2.0), id = 12L)         s.beginEditWaypoint(existing)-        assertEquals(12L, s.selectedWaypointId.value)         assertEquals("Work", s.waypointName.value)         assertEquals("500.0", s.waypointRange.value)         assertEquals(Coord(1.0, 2.0), s.waypointCoord.value)
findfamily/src/test/java/com/vayunmathur/findfamily/util/W5MapPageStateTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5MapPageStateTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5MapPageStateTest.ktindex 70e4b45519..531183d533 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5MapPageStateTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5MapPageStateTest.kt@@ -17,12 +17,14 @@ import kotlin.test.assertNull import kotlin.test.assertTrue  /**- * Robolectric tests for [MapPageState]'s synchronous selection/form logic.+ * Robolectric tests for [MapPageState]'s synchronous history/form logic.  *+ * Selection is not covered here on purpose: which person/place is selected+ * lives in the navigation back stack (`Route.PersonSheet` /+ * `Route.WaypointSheet`), and route-level navigation tests cover it.  * The setter paths (including the history-pin clearing rules added for- * GitHub #818) never touch the repository, so they run against the real- * singleton; [saveCurrentWaypoint]'s invalid-form no-ops return before any- * database access.+ * GitHub #818) never touch the repository; [MapPageState.saveCurrentWaypoint]'s+ * invalid-form no-ops return before any database access.  */ @RunWith(AndroidJUnit4::class) class W5MapPageStateTest {@@ -39,28 +41,17 @@ class W5MapPageStateTest {      @Test     fun initialStateIsEmpty() {-        assertNull(state.selectedUserId.value)-        assertNull(state.selectedWaypointId.value)         assertTrue(state.isShowingPresent.value)         assertNull(state.historicalPosition.value)         assertEquals("", state.waypointName.value)     }      @Test-    fun selectingUserClearsWaypointAndHistoryPin() {-        state.setSelectedWaypointId(9L)-        state.setHistoricalPosition(GeoPoint(1.0, 2.0))-        state.selectUser(5L)-        assertEquals(5L, state.selectedUserId.value)-        assertNull(state.selectedWaypointId.value)-        assertTrue(state.isShowingPresent.value)-        assertNull(state.historicalPosition.value)-    }--    @Test-    fun setSelectedUserIdDropsStaleHistoricalPin() {+    fun openingPersonDropsStaleHistoricalPin() {+        state.setShowingPresent(false)         state.setHistoricalPosition(GeoPoint(3.0, 4.0))-        state.setSelectedUserId(6L)+        state.onPersonOpened()+        assertTrue(state.isShowingPresent.value)         assertNull(state.historicalPosition.value)     } @@ -76,29 +67,10 @@ class W5MapPageStateTest {         assertEquals(GeoPoint(3.0, 4.0), state.historicalPosition.value)     } -    @Test-    fun clearSelectionResetsIdsAndPin() {-        state.selectUser(1L)-        state.setSelectedWaypointId(2L)-        state.setHistoricalPosition(GeoPoint(0.0, 0.0))-        state.clearSelection()-        assertNull(state.selectedUserId.value)-        assertNull(state.selectedWaypointId.value)-        assertNull(state.historicalPosition.value)-    }--    @Test-    fun applyInitialSelectionSetsBothIds() {-        state.applyInitialSelection(initialUserId = 7L, initialWaypointId = 8L)-        assertEquals(7L, state.selectedUserId.value)-        assertEquals(8L, state.selectedWaypointId.value)-    }-     @Test     fun beginCreateWaypointResetsForm() {         state.setWaypointName("old")         state.beginCreateWaypoint()-        assertEquals(0L, state.selectedWaypointId.value)         assertEquals("", state.waypointName.value)         assertEquals("100", state.waypointRange.value)         assertEquals(Coord(0.0, 0.0), state.waypointCoord.value)@@ -107,7 +79,6 @@ class W5MapPageStateTest {     @Test     fun beginEditWaypointPrefillsForm() {         state.beginEditWaypoint(Waypoint("home", 250.0, Coord(1.0, 2.0), id = 11L))-        assertEquals(11L, state.selectedWaypointId.value)         assertEquals("home", state.waypointName.value)         assertEquals("250.0", state.waypointRange.value)         assertEquals(Coord(1.0, 2.0), state.waypointCoord.value)@@ -115,17 +86,15 @@ class W5MapPageStateTest {      @Test     fun saveCurrentWaypointNoOpsOnInvalidForm() {-        // Blank name: returns before touching the repository.+        // Blank name: returns false before touching the repository.         state.beginCreateWaypoint()         state.setWaypointName("")         state.setWaypointRange("100")-        state.saveCurrentWaypoint()-        assertEquals(0L, state.selectedWaypointId.value)+        assertFalse(state.saveCurrentWaypoint(0L))         // Unparseable range: same silent no-op.         state.setWaypointName("home")         state.setWaypointRange("not-a-number")-        state.saveCurrentWaypoint()-        assertEquals(0L, state.selectedWaypointId.value)+        assertFalse(state.saveCurrentWaypoint(0L))     }      @Test@@ -136,6 +105,5 @@ class W5MapPageStateTest {         assertEquals("cabin", state.waypointName.value)         assertEquals("50", state.waypointRange.value)         assertEquals(Coord(5.0, 6.0), state.waypointCoord.value)-        assertFalse(state.selectedUserId.value != null)     } }
findfamily/src/test/java/com/vayunmathur/findfamily/util/W5UiContractTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5UiContractTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5UiContractTest.ktindex c695e64d8f..d8ac14ceb2 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5UiContractTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/W5UiContractTest.kt@@ -15,7 +15,7 @@ import kotlin.test.assertNull import kotlin.test.assertTrue  /**- * Pure-JVM tests for the map-page UI contract ([MainPageUiState] derived flags+ * Pure-JVM tests for the map-page UI contract ([MainPageUiState] defaults  * and action-interface no-op defaults) plus `Long.encodeBase26` /  * `String.decodeBase26` round-trips from AddPersonDialog.  */@@ -31,26 +31,12 @@ class W5UiContractTest {     )      @Test-    fun historyModeNeedsSelectedUserAndHistoryView() {-        assertFalse(MainPageUiState().historyMode)-        assertFalse(MainPageUiState(selectedUserId = 1L, isShowingPresent = true).historyMode)-        assertTrue(MainPageUiState(selectedUserId = 1L, isShowingPresent = false).historyMode)-        // A waypoint selection alone is not history mode.-        assertFalse(MainPageUiState(selectedWaypointId = 2L, isShowingPresent = false).historyMode)-    }--    @Test-    fun isSelfSelectedComparesIds() {-        assertTrue(MainPageUiState(selectedUserId = 5L, selfUserId = 5L).isSelfSelected)-        assertFalse(MainPageUiState(selectedUserId = 6L, selfUserId = 5L).isSelfSelected)-        assertFalse(MainPageUiState(selfUserId = 5L).isSelfSelected)-    }--    @Test-    fun nothingSelectedNeedsBothNull() {-        assertTrue(MainPageUiState().nothingSelected)-        assertFalse(MainPageUiState(selectedUserId = 1L).nothingSelected)-        assertFalse(MainPageUiState(selectedWaypointId = 1L).nothingSelected)+    fun mainPageStateDefaultsToFamilyList() {+        // Selection is absent from the map-page state by design: it lives+        // in the back stack (Route.PersonSheet / Route.WaypointSheet).+        val state = MainPageUiState()+        assertFalse(state.usingGpsFallback)+        assertTrue(state.familyList.connectedUsers.isEmpty())     }      @Test@@ -70,12 +56,11 @@ class W5UiContractTest {         person.setUserArrivalToggle(u, null)         person.setCrowdFinding(true)         val main = MainPageActions.Noop-        main.clearSelection()-        main.setShowingPresent(true)         main.beginCreateWaypoint()-        main.enterHistory()-        main.setWaypointName("home")-        main.setWaypointRange("100")+        main.addPerson()+        main.addLink()+        main.addTracker()+        main.onGpsWarningClick()     }      @Test