findfamily: hoist stateless MainPageContent (map slot); full-page store screenshots reuse it
- Commit
79d1aec75c0717592bc8347a661fa87ecf3f7e87- Author
- vayun-mathur <[email protected]>
- When
- 2026-08-16 16:20 UTC (3 months ago)
- Parents
ea31df8
Diff
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 e1f7637eb3..927d6188e8 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/ui/MainPage.kt@@ -107,6 +107,8 @@ import com.vayunmathur.findfamily.ui.dialogs.SecurityCodeDialog import com.vayunmathur.findfamily.util.FamilyListActions import com.vayunmathur.findfamily.util.FamilyListUiState import com.vayunmathur.findfamily.util.FindFamilyViewModel+import com.vayunmathur.findfamily.util.MainPageActions+import com.vayunmathur.findfamily.util.MainPageUiState import com.vayunmathur.findfamily.util.Networking import com.vayunmathur.findfamily.util.PersonActions import com.vayunmathur.findfamily.util.PersonUiState@@ -189,11 +191,23 @@ fun MainPage( val usersByLocationName by ffViewModel.usersByLocationName.collectAsState() val userPositions by ffViewModel.latestLocationByUser.collectAsState() - val scaffoldState = rememberBottomSheetScaffoldState()+ 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.+ val users by ffViewModel.users.collectAsState()+ val selectedUser = selectedUserId?.let { id -> users.firstOrNull { it.id == id } } - // The sheets 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 two that need the nav stack or the clipboard go here.+ // 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) }+ }++ // 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. val familyActions = remember(ffViewModel, backStack, platform) { object : FamilyListActions by ffViewModel { override fun acceptRequest(userId: Long) {@@ -208,8 +222,171 @@ fun MainPage( } } + val personActions = object : PersonActions by ffViewModel {+ override fun changeConnectedContact() = requestPickContact()+ }++ val mainActions = object : MainPageActions {+ override fun clearSelection() = ffViewModel.clearSelection()+ override fun setShowingPresent(present: Boolean) = ffViewModel.setShowingPresent(present)+ override fun onGpsWarningClick() { showGpsWarning = true }+ override fun onShowSecurityCode() { showSecurityCode = true }+ override fun openUwbRanging(userId: Long) { backStack.add(Route.UwbRangingPage(userId)) }+ override fun deleteSelectedUser() {+ selectedUser?.let { ffViewModel.deleteUser(it) }+ ffViewModel.setSelectedUserId(null)+ }+ override fun deleteSelectedWaypoint() {+ selectedWaypointId?.let { id -> waypoints.firstOrNull { it.id == id } }+ ?.let { ffViewModel.deleteWaypoint(it) }+ ffViewModel.setSelectedWaypointId(null)+ }+ override fun addPerson() { backStack.add(Route.AddPersonDialog()) }+ override fun beginCreateWaypoint() = ffViewModel.beginCreateWaypoint()+ override fun addLink() { backStack.add(Route.AddLinkDialog) }+ override fun addTracker() { backStack.add(Route.AddTrackerDialog) }+ override fun saveCurrentWaypoint() = ffViewModel.saveCurrentWaypoint()+ override fun enterHistory() = ffViewModel.setShowingPresent(false)+ override fun setWaypointName(name: String) = ffViewModel.setWaypointName(name)+ override fun setWaypointRange(range: String) = ffViewModel.setWaypointRange(range)+ }++ 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,+ temporaryLinks = temporaryLinks,+ waypoints = waypoints,+ locationByUser = userPositions,+ userNamesByLocationName = usersByLocationName+ ),+ person = selectedUser?.let { PersonUiState(it, userPositions[it.id], waypoints) }+ )++ MainPageContent(+ state = state,+ familyActions = familyActions,+ personActions = personActions,+ actions = mainActions,+ backupButtons = {+ BackupButtons(+ dbConfigs = listOf("passwords-db" to ffViewModel.backupPassphrase),+ dbCodec = SqlCipherDbCodec,+ extraFiles = emptyList()+ )+ },+ historyScrubber = {+ if (historyMode) {+ HistoryScrubber(+ backStack,+ ffViewModel,+ selectedUserId!!+ ) { ffViewModel.setHistoricalPosition(it) }+ }+ },+ map = {+ val selectedUserObj = if (selectedUserId != null) {+ selectedUser?.let { SelectedUser(it, isShowingPresent, historicalPosition) }+ } else null++ val selectedWaypointObj = if (selectedWaypointId != null) {+ val waypoint by ffViewModel.waypointByIdState(selectedWaypointId!!) { Waypoint.NEW_WAYPOINT }+ waypoint?.let { wp -> SelectedWaypoint(wp, waypointRange.toDoubleOrNull() ?: 0.0) {+ ffViewModel.setWaypointCoord(it)+ } }+ } else null++ MapView(+ ffViewModel,+ onUserClick = {+ ffViewModel.selectUser(it)+ },+ onMapClick = {+ ffViewModel.clearSelection()+ },+ selectedUser = selectedUserObj,+ selectedWaypoint = selectedWaypointObj+ )+ }+ )++ // Map animation logic+ LaunchedEffect(selectedUserId, isShowingPresent, historicalPosition) {+ if (selectedUserId != null) {+ val targetPosition = if (isShowingPresent) {+ userPositions[selectedUserId!!]?.coord?.toGeoPoint()+ } else {+ historicalPosition+ }+ targetPosition?.let {+ camera.animateTo(+ camera.position.copy(+ target = it,+ zoom = 15.0+ )+ )+ }+ }+ }++ LaunchedEffect(selectedWaypointId) {+ if (selectedWaypointId != null && selectedWaypointId != 0L) {+ val waypoint = waypoints.find { it.id == selectedWaypointId }+ waypoint?.coord?.toGeoPoint()?.let {+ camera.animateTo(+ camera.position.copy(+ target = it,+ zoom = 15.0+ )+ )+ }+ }+ }++ if (showSecurityCode && selectedUserId != null && selectedUserId != Networking.userid) {+ val user by ffViewModel.userByIdState(selectedUserId!!)+ user?.let { SecurityCodeDialog(it, ffViewModel) { showSecurityCode = false } }+ }++ if (showGpsWarning) {+ GpsFallbackWarningDialog { showGpsWarning = false }+ }+}++/**+ * The stateless map-page layout: the [BottomSheetScaffold] (top bar + sheet) with a+ * full-bleed [map] slot and the floating action button on top. It reads only [state] and+ * calls back through [actions]/[familyActions]/[personActions], so both the real app (via+ * the [MainPage] wrapper) and the store-listing previews render the *same* page — the app+ * injects the live [MapView] into [map], the previews inject a static backdrop.+ *+ * [backupButtons] and [historyScrubber] are slots for the two chrome pieces that genuinely+ * need the ViewModel/nav stack; previews leave them empty.+ */+@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)+@Composable+fun MainPageContent(+ state: MainPageUiState,+ familyActions: FamilyListActions,+ personActions: PersonActions,+ actions: MainPageActions,+ map: @Composable () -> Unit,+ backupButtons: @Composable () -> Unit = {},+ historyScrubber: @Composable BoxScope.() -> Unit = {},+) {+ val scaffoldState = rememberBottomSheetScaffoldState()+ // In history mode drop the sheet entirely (peek 0); the name goes in the app bar.- val peekHeight = if (historyMode) 0.dp else SheetPeekHeight+ val peekHeight = if (state.historyMode) 0.dp else 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@@ -231,7 +408,7 @@ fun MainPage( val st = scaffoldState.bottomSheetState val settled = st.currentValue == SheetValue.PartiallyExpanded && st.targetValue == SheetValue.PartiallyExpanded- val hist = selectedUserId != null && !isShowingPresent+ val hist = state.historyMode if (settled && !hist) runCatching { st.requireOffset() }.getOrNull() else null }.collect { off -> if (off != null && collapsedSheetOffset.floatValue.isNaN()) {@@ -242,8 +419,8 @@ fun MainPage( // Leaving history sets the peek back to non-zero, but the collapsed sheet needs // a nudge to animate back to its peek. Retry until the anchor is ready.- LaunchedEffect(historyMode) {- if (!historyMode) {+ LaunchedEffect(state.historyMode) {+ if (!state.historyMode) { repeat(10) { if (runCatching { scaffoldState.bottomSheetState.partialExpand() }.isSuccess) { return@LaunchedEffect@@ -256,35 +433,35 @@ fun MainPage( BottomSheetScaffold( scaffoldState = scaffoldState, sheetPeekHeight = peekHeight,- sheetSwipeEnabled = !historyMode,- sheetDragHandle = if (historyMode) null else { { BottomSheetDefaults.DragHandle() } },+ sheetSwipeEnabled = !state.historyMode,+ sheetDragHandle = if (state.historyMode) null else { { BottomSheetDefaults.DragHandle() } }, sheetContainerColor = MaterialTheme.colorScheme.surfaceContainerLow, // Default (solid) app bar so the map stays cut off beneath it while panning. topBar = { TopAppBar( title = {- if (historyMode) {- val historyUser by ffViewModel.userByIdState(selectedUserId!!)- Text(stringResource(R.string.history_title, historyUser?.name ?: ""))- } else if (selectedUserId == null && selectedWaypointId == null) {+ if (state.historyMode) {+ Text(stringResource(R.string.history_title, state.selectedUser?.name ?: ""))+ } else if (state.nothingSelected) { Text(stringResource(R.string.app_name)) } }, navigationIcon = {- if (selectedUserId != null || selectedWaypointId != null) {+ if (state.selectedUserId != null || state.selectedWaypointId != null) { IconNavigation {- if (historyMode) {- ffViewModel.setShowingPresent(true)+ if (state.historyMode) {+ actions.setShowingPresent(true) } else {- ffViewModel.clearSelection()+ actions.clearSelection() } } } }, actions = {- if (selectedUserId == null && (selectedWaypointId == null || selectedWaypointId == 0L)) {- if (usingGpsFallback) {- IconButton({ showGpsWarning = true }) {+ if (state.selectedUserId == null &&+ (state.selectedWaypointId == null || state.selectedWaypointId == 0L)) {+ if (state.usingGpsFallback) {+ IconButton({ actions.onGpsWarningClick() }) { // Use Image (not the tinting IconWarning) so the // custom yellow-and-red drawable keeps both colors. Image(@@ -295,40 +472,26 @@ fun MainPage( ) } }- BackupButtons(- dbConfigs = listOf("passwords-db" to ffViewModel.backupPassphrase),- dbCodec = SqlCipherDbCodec,- extraFiles = emptyList()- )- } else if (selectedUserId != null && !historyMode) {- if (selectedUserId != Networking.userid) {- val user by ffViewModel.userByIdState(selectedUserId!!)+ backupButtons()+ } else if (state.selectedUserId != null && !state.historyMode) {+ if (!state.isSelfSelected) { // Find Nearby (UWB) needs both the public // android.ranging API (Android 16+) and an actual // UWB radio. Hide the entry point otherwise.- if (UwbSessionManager.isAvailable(context)) {- IconButton({- backStack.add(Route.UwbRangingPage(selectedUserId!!))- }) {+ if (state.uwbAvailable) {+ IconButton({ actions.openUwbRanging(state.selectedUserId) }) { IconNavigationArrow() } }- IconButton({ showSecurityCode = true }) {+ IconButton({ actions.onShowSecurityCode() }) { IconVerify() }- IconButton({- user?.let { ffViewModel.deleteUser(it) }- ffViewModel.setSelectedUserId(null)- }) {+ IconButton({ actions.deleteSelectedUser() }) { IconDelete() } }- } else if (selectedWaypointId != null && selectedWaypointId != 0L) {- val waypoint by ffViewModel.waypointByIdState(selectedWaypointId!!)- IconButton({- waypoint?.let { ffViewModel.deleteWaypoint(it) }- ffViewModel.setSelectedWaypointId(null)- }) {+ } else if (state.selectedWaypointId != null && state.selectedWaypointId != 0L) {+ IconButton({ actions.deleteSelectedWaypoint() }) { IconDelete() } }@@ -336,53 +499,34 @@ fun MainPage( ) }, sheetContent = {- if (selectedUserId == null && selectedWaypointId == null) {- FamilyListSheet(- FamilyListUiState(- connectedUsers = connectedUsers,- awaitingRequestUsers = awaitingRequestUsers,- temporaryLinks = temporaryLinks,- waypoints = waypoints,- locationByUser = userPositions,- userNamesByLocationName = usersByLocationName- ),- familyActions- )- } else if (historyMode) {+ if (state.nothingSelected) {+ FamilyListSheet(state.familyList, familyActions)+ } else if (state.historyMode) { // History mode has no sheet; the name is shown in the app bar.- } else if (selectedUserId != null) {- val selectedUser by ffViewModel.userByIdState(selectedUserId!!)- val requestPickContact = platform.requestPickContact { name, photo ->- selectedUser?.let { ffViewModel.updateContactNamePhoto(it.id, name, photo) }- }- selectedUser?.let { user ->- val personActions = object : PersonActions by ffViewModel {- override fun changeConnectedContact() = requestPickContact()- }- PersonDetailSheet(PersonUiState(user, userPositions[user.id], waypoints), personActions)- }- } else if (selectedWaypointId != null) {+ } 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(- waypointName,- { ffViewModel.setWaypointName(it) },+ state.waypointName,+ { actions.setWaypointName(it) }, Modifier.fillMaxWidth(),- isError = waypointName.isBlank(),- supportingText = if (waypointName.isBlank()) {+ 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(- waypointRange,- { ffViewModel.setWaypointRange(it) },+ state.waypointRange,+ { actions.setWaypointRange(it) }, Modifier.fillMaxWidth(), suffix = { Text(stringResource(R.string.waypoint_range_suffix)) }, keyboardOptions = KeyboardOptions( keyboardType = KeyboardType.Number ),- isError = waypointRange.toDoubleOrNull() == null,- supportingText = if (waypointRange.toDoubleOrNull() == null) {+ isError = state.waypointRange.toDoubleOrNull() == null,+ supportingText = if (state.waypointRange.toDoubleOrNull() == null) { { Text(stringResource(R.string.waypoint_range_error)) } } else null )@@ -390,7 +534,7 @@ fun MainPage( } } ) { _ ->- // Full-bleed map; overlays (FAB, history bar) sit just above the collapsed+ // Full-bleed map slot; overlays (FAB, history bar) sit just above the collapsed // sheet peek and lift upward as the sheet expands. Box(Modifier.fillMaxSize()) { // Lift overlays above their peek baseline as the sheet expands:@@ -402,37 +546,9 @@ fun MainPage( if (cur != null && !base.isNaN()) (cur - base).roundToInt().coerceAtMost(0) else 0 } - val selectedUserObj = if (selectedUserId != null) {- val user by ffViewModel.userByIdState(selectedUserId!!)- user?.let { SelectedUser(it, isShowingPresent, historicalPosition) }- } else null-- val selectedWaypointObj = if (selectedWaypointId != null) {- val waypoint by ffViewModel.waypointByIdState(selectedWaypointId!!) { Waypoint.NEW_WAYPOINT }- waypoint?.let { wp -> SelectedWaypoint(wp, waypointRange.toDoubleOrNull() ?: 0.0) {- ffViewModel.setWaypointCoord(it)- } }- } else null+ map() - MapView(- ffViewModel,- onUserClick = {- ffViewModel.selectUser(it)- },- onMapClick = {- ffViewModel.clearSelection()- },- selectedUser = selectedUserObj,- selectedWaypoint = selectedWaypointObj- )-- if (historyMode) {- HistoryScrubber(- backStack,- ffViewModel,- selectedUserId!!- ) { ffViewModel.setHistoricalPosition(it) }- }+ historyScrubber() // FAB floats just above the sheet peek, lifting as the sheet expands. // Wrapped in the light scheme so it reads correctly over the light map.@@ -442,7 +558,7 @@ fun MainPage( .offset { IntOffset(0, sheetLiftPx()) } ) { MaterialTheme(colorScheme = lightScheme) {- if (selectedUserId == null && selectedWaypointId == null) {+ if (state.nothingSelected) { var expanded by remember { mutableStateOf(false) } FloatingActionButtonMenu(expanded, { ToggleFloatingActionButton(@@ -456,41 +572,33 @@ fun MainPage( IconClose(tint = fabContentColor) } }) {- FloatingActionButtonMenuItem({- backStack.add(Route.AddPersonDialog())- },+ FloatingActionButtonMenuItem({ actions.addPerson() }, { Text(stringResource(R.string.fab_person)) }, { IconPerson() })- FloatingActionButtonMenuItem({- ffViewModel.beginCreateWaypoint()- },+ FloatingActionButtonMenuItem({ actions.beginCreateWaypoint() }, { Text(stringResource(R.string.fab_location)) }, { IconLocationOn() })- FloatingActionButtonMenuItem({- backStack.add(Route.AddLinkDialog)- },+ FloatingActionButtonMenuItem({ actions.addLink() }, { Text(stringResource(R.string.fab_link)) }, { IconLink() }) if (BuildConfig.DEV_BUILD) {- FloatingActionButtonMenuItem({- backStack.add(Route.AddTrackerDialog)- },+ FloatingActionButtonMenuItem({ actions.addTracker() }, { Text(stringResource(R.string.fab_tracker)) }, { IconNavigationArrow() }) } }- } else if (selectedWaypointId != null) {+ } else if (state.selectedWaypointId != null) { FloatingActionButton(- { ffViewModel.saveCurrentWaypoint() },+ { actions.saveCurrentWaypoint() }, containerColor = fabContainerColor, contentColor = fabContentColor ) { IconSave() }- } else if (selectedUserId != null && isShowingPresent) {+ } else if (state.selectedUserId != null && state.isShowingPresent) { // Enter history mode; exit is via back. FloatingActionButton(- { ffViewModel.setShowingPresent(false) },+ { actions.enterHistory() }, containerColor = fabContainerColor, contentColor = fabContentColor ) {@@ -501,48 +609,6 @@ fun MainPage( } } }-- // Map animation logic- LaunchedEffect(selectedUserId, isShowingPresent, historicalPosition) {- if (selectedUserId != null) {- val targetPosition = if (isShowingPresent) {- userPositions[selectedUserId!!]?.coord?.toGeoPoint()- } else {- historicalPosition- }- targetPosition?.let {- camera.animateTo(- camera.position.copy(- target = it,- zoom = 15.0- )- )- }- }- }-- LaunchedEffect(selectedWaypointId) {- if (selectedWaypointId != null && selectedWaypointId != 0L) {- val waypoint = waypoints.find { it.id == selectedWaypointId }- waypoint?.coord?.toGeoPoint()?.let {- camera.animateTo(- camera.position.copy(- target = it,- zoom = 15.0- )- )- }- }- }-- if (showSecurityCode && selectedUserId != null && selectedUserId != Networking.userid) {- val user by ffViewModel.userByIdState(selectedUserId!!)- user?.let { SecurityCodeDialog(it, ffViewModel) { showSecurityCode = false } }- }-- if (showGpsWarning) {- GpsFallbackWarningDialog { showGpsWarning = false }- } } /**
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 545d713785..df88d61128 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/FindFamilyUiContract.kt@@ -76,3 +76,63 @@ interface PersonActions { val Noop: PersonActions = object : 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+ * data only — no ViewModel — so both the real app and the store-listing previews can build it.+ *+ * 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 top-bar 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+}++/**+ * Top-bar 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.+ */+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) {}++ companion object {+ val Noop: MainPageActions = object : MainPageActions {}+ }+}
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 43162f62aa..0c4436cb75 100644--- a/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt+++ b/findfamily/src/screenshotTest/kotlin/com/vayunmathur/findfamily/ui/MetadataPreviews.kt@@ -1,9 +1,14 @@ package com.vayunmathur.findfamily.ui +import androidx.compose.foundation.Canvas+import androidx.compose.foundation.background+import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier+import androidx.compose.ui.geometry.Offset import androidx.compose.ui.tooling.preview.Preview+import androidx.compose.ui.unit.dp import com.android.tools.screenshot.PreviewTest import com.vayunmathur.findfamily.data.Coord import com.vayunmathur.findfamily.data.LocationValue@@ -13,13 +18,14 @@ 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 com.vayunmathur.findfamily.util.UwbSessionManager import com.vayunmathur.findfamily.uwb.RangingSample import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Surface import kotlin.time.Clock import kotlin.time.Duration.Companion.minutes @@ -32,9 +38,10 @@ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420" * The app's headline screen is a map with everyone's pins on it, and that is exactly the * part Layoutlib cannot draw: the map is a tile renderer fed from the network, and the * marker layer only appears once the camera projection resolves — neither happens in a- * preview. So these render the chrome instead: the bottom sheet that lists the family, the- * per-person sharing controls, and the full-screen UWB Find Nearby view. [MainPage] itself- * is not previewable and is deliberately left alone.+ * preview. So instead of drawing isolated bottom sheets, these render the *real* page+ * layout ([MainPageContent]) with a static, muted map backdrop injected into its `map`+ * slot. The app and these previews therefore share one layout with zero duplication: the+ * family list, the per-person sharing controls and the full-screen UWB Find Nearby view. * * Each preview needs @PreviewTest as well as @Preview: @Preview alone renders in Studio but * is not collected as a screenshot test. Previews must also be class members, not top-level@@ -86,47 +93,77 @@ class MetadataPreviews { private val mayaLocation = report(1, 37.7749, -122.4194, speed = 0f, battery = 78f, minutesAgo = 3) + private val sampleWaypoints = listOf(+ Waypoint("Home", 150.0, Coord(37.7749, -122.4194), id = 1),+ Waypoint("Lincoln High School", 250.0, Coord(37.7899, -122.4094), id = 2),+ Waypoint("Soccer practice", 120.0, Coord(37.7649, -122.4294), id = 3),+ )++ private fun sampleFamilyList() = FamilyListUiState(+ connectedUsers = listOf(maya, ravi, dad),+ awaitingRequestUsers = listOf(+ // Inbound requests are only known by their id until accepted.+ person(5_432_109L, "Grandma", "Unnamed Location", arrivedMinutesAgo = 0)+ .copy(requestStatus = RequestStatus.AWAITING_REQUEST)+ ),+ temporaryLinks = listOf(+ TemporaryLink(+ name = "Dog walker",+ deleteAt = now + 45.minutes,+ pqcPublicKey = "",+ pqcKey = "",+ id = 91,+ ),+ ),+ waypoints = sampleWaypoints,+ locationByUser = mapOf(+ 1L to mayaLocation,+ 2L to report(2, 37.7899, -122.4094, speed = 0f, battery = 41f, minutesAgo = 12),+ 3L to report(3, 37.7681, -122.4370, speed = 13.4f, battery = 16f, minutesAgo = 1),+ ),+ userNamesByLocationName = mapOf(+ "Home" to listOf("Maya Chen"),+ "Lincoln High School" to listOf("Ravi Patel"),+ ),+ )++ /**+ * Stand-in for the live [MapView] in the `map` slot: a muted, map-ish neutral fill with a+ * faint grid so the full page reads as "map behind chrome" without any tile rendering.+ */+ @Composable+ private fun StaticMapBackdrop() {+ val gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.25f)+ Box(Modifier.fillMaxSize().background(MaterialTheme.colorScheme.surfaceVariant)) {+ Canvas(Modifier.fillMaxSize()) {+ val step = 48.dp.toPx()+ val stroke = 1.dp.toPx()+ var x = step+ while (x < size.width) {+ drawLine(gridColor, Offset(x, 0f), Offset(x, size.height), stroke)+ x += step+ }+ var y = step+ while (y < size.height) {+ drawLine(gridColor, Offset(0f, y), Offset(size.width, y), stroke)+ y += step+ }+ }+ }+ }+ @PreviewTest @Preview(name = "1-family", device = PHONE, showSystemUi = true) @Composable fun Preview1Family() { DynamicTheme(darkTheme = true) {- Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surfaceContainerLow) {- FamilyListSheet(- FamilyListUiState(- connectedUsers = listOf(maya, ravi, dad),- awaitingRequestUsers = listOf(- // Inbound requests are only known by their id until accepted.- person(5_432_109L, "Grandma", "Unnamed Location", arrivedMinutesAgo = 0)- .copy(requestStatus = RequestStatus.AWAITING_REQUEST)- ),- temporaryLinks = listOf(- TemporaryLink(- name = "Dog walker",- deleteAt = now + 45.minutes,- pqcPublicKey = "",- pqcKey = "",- id = 91,- ),- ),- waypoints = listOf(- Waypoint("Home", 150.0, Coord(37.7749, -122.4194), id = 1),- Waypoint("Lincoln High School", 250.0, Coord(37.7899, -122.4094), id = 2),- Waypoint("Soccer practice", 120.0, Coord(37.7649, -122.4294), id = 3),- ),- locationByUser = mapOf(- 1L to mayaLocation,- 2L to report(2, 37.7899, -122.4094, speed = 0f, battery = 41f, minutesAgo = 12),- 3L to report(3, 37.7681, -122.4370, speed = 13.4f, battery = 16f, minutesAgo = 1),- ),- userNamesByLocationName = mapOf(- "Home" to listOf("Maya Chen"),- "Lincoln High School" to listOf("Ravi Patel"),- ),- ),- FamilyListActions.Noop,- )- }+ MainPageContent(+ state = MainPageUiState(familyList = sampleFamilyList()),+ familyActions = FamilyListActions.Noop,+ personActions = PersonActions.Noop,+ actions = MainPageActions.Noop,+ map = { StaticMapBackdrop() },+ ) } } @@ -135,12 +172,17 @@ class MetadataPreviews { @Composable fun Preview2Person() { DynamicTheme(darkTheme = true) {- Surface(Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surfaceContainerLow) {- PersonDetailSheet(- PersonUiState(user = maya, location = mayaLocation),- PersonActions.Noop,- )- }+ 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() },+ ) } }