Modern Apps git

← Modern-Apps.git

maps P6: saved places + layers sheet + settings

Commit
b17d3046c968038a91a14f181750a64f509c472e
Author
vayun-mathur <[email protected]>
When
2026-08-16 23:57 UTC (3 months ago)
Parents
d0315d3

Diff

maps/src/main/java/com/vayunmathur/maps/MainActivity.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt b/maps/src/main/java/com/vayunmathur/maps/MainActivity.ktindex 8a62396660..4608c27d72 100644--- a/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt+++ b/maps/src/main/java/com/vayunmathur/maps/MainActivity.kt@@ -7,6 +7,8 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue import androidx.lifecycle.viewmodel.compose.viewModel import com.vayunmathur.library.downloadservice.InitialDownloadChecker import com.vayunmathur.library.ui.DynamicTheme@@ -18,13 +20,18 @@ import com.vayunmathur.library.util.NavKey import com.vayunmathur.library.util.rememberNavBackStack import com.vayunmathur.maps.ui.DownloadedMapsPage import com.vayunmathur.maps.ui.MapPage+import com.vayunmathur.maps.ui.SavedPlacesPage import com.vayunmathur.maps.ui.SearchPage+import com.vayunmathur.maps.ui.settings.MapSettingsPage+import com.vayunmathur.maps.data.MapPreferences+import com.vayunmathur.maps.data.ThemeMode import com.vayunmathur.maps.util.MapTileCache import com.vayunmathur.maps.util.MapsSearchViewModel import com.vayunmathur.maps.util.MapsZonesViewModel import com.vayunmathur.maps.util.SavedPlacesViewModel import com.vayunmathur.maps.util.SelectedFeatureViewModel import com.vayunmathur.maps.util.GooglePoiMapViewModel+import com.vayunmathur.maps.util.MapSettingsViewModel import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.network.TrustBundle import kotlinx.serialization.Serializable@@ -56,7 +63,9 @@ class MainActivity : ComponentActivity() { //        }          setContent {-            DynamicTheme {+            val themeMode by ds.stringFlow(MapPreferences.KEY_THEME_MODE)+                .collectAsState(initial = ds.getString(MapPreferences.KEY_THEME_MODE))+            DynamicTheme(darkTheme = ThemeMode.from(themeMode).darkOverride) {                 InitialDownloadChecker(ds, listOf(                     Triple("https://data.vayunmathur.com/metadata.bin", "metadata.bin", getString(R.string.downloading_navigation_metadata)),                     Triple("https://data.vayunmathur.com/road_names.bin", "road_names.bin", getString(R.string.downloading_road_data)),@@ -96,6 +105,10 @@ sealed interface Route: NavKey {     data object MapPage: Route     @Serializable     data object DownloadedMapsPage: Route+    @Serializable+    data object SettingsPage: Route+    @Serializable+    data object SavedPlacesPage: Route      @Serializable     data class SearchPage(val idx: Int?, val east: Double, val west: Double, val north: Double, val south: Double, val query: String? = null): Route@@ -108,15 +121,22 @@ fun Navigation(     zonesViewModel: MapsZonesViewModel = viewModel(),     savedPlacesViewModel: SavedPlacesViewModel = viewModel(),     poiViewModel: GooglePoiMapViewModel = viewModel(),+    settingsViewModel: MapSettingsViewModel = viewModel(), ) {     val backStack = rememberNavBackStack<Route>(Route.MapPage)     MainNavigation(backStack) {         entry<Route.MapPage> {-            MapPage(backStack, viewModel, zonesViewModel, savedPlacesViewModel, poiViewModel, searchViewModel)+            MapPage(backStack, viewModel, zonesViewModel, savedPlacesViewModel, poiViewModel, searchViewModel, settingsViewModel)         }         entry<Route.DownloadedMapsPage> {             DownloadedMapsPage(backStack, zonesViewModel)         }+        entry<Route.SettingsPage> {+            MapSettingsPage(backStack, settingsViewModel)+        }+        entry<Route.SavedPlacesPage> {+            SavedPlacesPage(backStack, savedPlacesViewModel)+        }         entry<Route.SearchPage> {             SearchPage(backStack, viewModel, searchViewModel, it.idx, it.east, it.west, it.north, it.south, it.query)         }
maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt b/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.ktnew file mode 100644index 0000000000..6a4211c5a0--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/data/MapPreferences.kt@@ -0,0 +1,52 @@+package com.vayunmathur.maps.data++/**+ * Central registry of the maps app's DataStore preference keys and their small+ * enum value types (P6). Kept in one place so the settings screen, the layers+ * sheet, `MainActivity` (theme) and `NavigationService` (voice) all agree on the+ * exact key strings and defaults instead of scattering magic strings.+ */+object MapPreferences {+    const val KEY_VOICE_GUIDANCE = "voice_guidance_enabled"+    const val KEY_THEME_MODE = "theme_mode"+    const val KEY_DISTANCE_UNITS = "distance_units"++    // Layer toggles surfaced in the P6 layers sheet.+    const val KEY_LAYER_TRAFFIC = "layer_traffic"+    const val KEY_LAYER_SATELLITE = "layer_satellite"+    const val KEY_LAYER_SAFETY = "layer_safety"++    const val DEFAULT_VOICE_GUIDANCE = true+    const val DEFAULT_LAYER_TRAFFIC = true+    const val DEFAULT_LAYER_SATELLITE = false+    const val DEFAULT_LAYER_SAFETY = false+}++/** App theme selection persisted under [MapPreferences.KEY_THEME_MODE]. */+enum class ThemeMode(val pref: String) {+    SYSTEM("system"),+    LIGHT("light"),+    DARK("dark");++    /** null = follow the system (what [com.vayunmathur.library.ui.DynamicTheme] expects). */+    val darkOverride: Boolean?+        get() = when (this) {+            SYSTEM -> null+            LIGHT -> false+            DARK -> true+        }++    companion object {+        fun from(pref: String?): ThemeMode = entries.firstOrNull { it.pref == pref } ?: SYSTEM+    }+}++/** Distance unit selection persisted under [MapPreferences.KEY_DISTANCE_UNITS]. */+enum class DistanceUnit(val pref: String) {+    KILOMETERS("km"),+    MILES("mi");++    companion object {+        fun from(pref: String?): DistanceUnit = entries.firstOrNull { it.pref == pref } ?: KILOMETERS+    }+}
maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.ktnew file mode 100644index 0000000000..a5f2c36615--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/data/SavedPlaceStore.kt@@ -0,0 +1,75 @@+package com.vayunmathur.maps.data++import com.vayunmathur.library.util.DataStoreUtils+import kotlinx.coroutines.flow.Flow+import kotlinx.coroutines.flow.map+import kotlinx.serialization.json.Json++/**+ * Persistence for every kind of saved place (P6), extracted from+ * `SavedPlacesViewModel` so the store logic lives in one place and can grow+ * beyond the original Home/Work slots:+ *+ *  - **Home / Work** — single quick-access slots (unchanged from P4; a blank+ *    string clears the slot and decodes back to null).+ *  - **Saved** — a flat starred list the user builds from the place sheet.+ *  - **Lists** — named collections (Vela's `PlaceListStore`), e.g. "Trip",+ *    "Favorites"; a map of list-name → places.+ *+ * Each field is a small JSON string in DataStore. The store is deliberately thin+ * (flows + suspend setters); [com.vayunmathur.maps.util.SavedPlacesViewModel]+ * owns the coroutine scope and turns these into `StateFlow`s.+ */+class SavedPlaceStore(private val ds: DataStoreUtils) {++    // --- Home / Work slots -------------------------------------------------++    fun homeFlow(): Flow<SavedPlace?> = ds.stringFlow(KEY_HOME).map { decode(it) }+    fun workFlow(): Flow<SavedPlace?> = ds.stringFlow(KEY_WORK).map { decode(it) }+    fun homeInitial(): SavedPlace? = decode(ds.getString(KEY_HOME))+    fun workInitial(): SavedPlace? = decode(ds.getString(KEY_WORK))++    suspend fun setHome(place: SavedPlace?) = ds.setString(KEY_HOME, encode(place))+    suspend fun setWork(place: SavedPlace?) = ds.setString(KEY_WORK, encode(place))++    // --- Flat saved (starred) list ----------------------------------------++    fun savedFlow(): Flow<List<SavedPlace>> = ds.stringFlow(KEY_SAVED).map { decodeList(it) }+    fun savedInitial(): List<SavedPlace> = decodeList(ds.getString(KEY_SAVED))++    suspend fun setSaved(list: List<SavedPlace>) = ds.setString(KEY_SAVED, Json.encodeToString(list))++    // --- Named lists -------------------------------------------------------++    fun listsFlow(): Flow<Map<String, List<SavedPlace>>> = ds.stringFlow(KEY_LISTS).map { decodeLists(it) }+    fun listsInitial(): Map<String, List<SavedPlace>> = decodeLists(ds.getString(KEY_LISTS))++    suspend fun setLists(lists: Map<String, List<SavedPlace>>) =+        ds.setString(KEY_LISTS, Json.encodeToString(lists))++    // --- encode / decode ---------------------------------------------------++    private fun encode(place: SavedPlace?): String =+        place?.let { Json.encodeToString(it) } ?: ""++    private fun decode(raw: String?): SavedPlace? =+        raw?.takeIf { it.isNotBlank() }+            ?.let { runCatching { Json.decodeFromString<SavedPlace>(it) }.getOrNull() }++    private fun decodeList(raw: String?): List<SavedPlace> =+        raw?.takeIf { it.isNotBlank() }+            ?.let { runCatching { Json.decodeFromString<List<SavedPlace>>(it) }.getOrNull() }+            ?: emptyList()++    private fun decodeLists(raw: String?): Map<String, List<SavedPlace>> =+        raw?.takeIf { it.isNotBlank() }+            ?.let { runCatching { Json.decodeFromString<Map<String, List<SavedPlace>>>(it) }.getOrNull() }+            ?: emptyMap()++    companion object {+        private const val KEY_HOME = "saved_place_home"+        private const val KEY_WORK = "saved_place_work"+        private const val KEY_SAVED = "saved_places_list"+        private const val KEY_LISTS = "saved_place_lists"+    }+}
maps/src/main/java/com/vayunmathur/maps/ui/LayersSheet.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/LayersSheet.kt b/maps/src/main/java/com/vayunmathur/maps/ui/LayersSheet.ktnew file mode 100644index 0000000000..4a6813e9a1--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/LayersSheet.kt@@ -0,0 +1,85 @@+package com.vayunmathur.maps.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconShield+import com.vayunmathur.library.ui.IconStyle+import com.vayunmathur.library.ui.IconWarning+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.ModalBottomSheet+import com.vayunmathur.library.ui.SettingsSwitchRow+import com.vayunmathur.library.ui.Text+import com.vayunmathur.maps.R++/**+ * Map-layers toggle sheet (P6), opened from the browse [LayersButton]. Only the+ * layers MA can actually support are surfaced, each gated on what exists:+ *+ *  - **Traffic** — LIVE. MA already renders `traffic-layer` in [MyMapLayers]; the+ *    toggle controls its visibility.+ *  - **Satellite** — GATED. Only shown when a raster tile source is hosted+ *    ([SatelliteSource.available]); hidden entirely otherwise (Decision D11).+ *  - **Safety layers** — GATED on the P13 PMTiles v5. The toggle is shown now but+ *    disabled (with a "coming soon" hint) until [SafetyLayersSource.available].+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun LayersSheet(+    onDismiss: () -> Unit,+    trafficEnabled: Boolean,+    onTrafficChange: (Boolean) -> Unit,+    satelliteEnabled: Boolean,+    onSatelliteChange: (Boolean) -> Unit,+    safetyEnabled: Boolean,+    onSafetyChange: (Boolean) -> Unit,+) {+    ModalBottomSheet(onDismissRequest = onDismiss) {+        Column(Modifier.fillMaxWidth().padding(bottom = 24.dp)) {+            Text(+                stringResource(R.string.layers_title),+                style = MaterialTheme.typography.titleMedium,+                color = MaterialTheme.colorScheme.primary,+                modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp),+            )++            // Traffic — live.+            SettingsSwitchRow(+                title = stringResource(R.string.layer_traffic),+                supportingText = stringResource(R.string.layer_traffic_desc),+                checked = trafficEnabled,+                onCheckedChange = onTrafficChange,+                leadingContent = { IconWarning() },+            )++            // Satellite — only when a tile source is hosted.+            if (SatelliteSource.available) {+                SettingsSwitchRow(+                    title = stringResource(R.string.layer_satellite),+                    supportingText = stringResource(R.string.layer_satellite_desc),+                    checked = satelliteEnabled,+                    onCheckedChange = onSatelliteChange,+                    leadingContent = { IconStyle() },+                )+            }++            // Safety layers — surfaced now, gated on the P13 PMTiles v5.+            SettingsSwitchRow(+                title = stringResource(R.string.layer_safety),+                supportingText = stringResource(+                    if (SafetyLayersSource.available) R.string.layer_safety_desc+                    else R.string.layer_safety_unavailable+                ),+                checked = safetyEnabled && SafetyLayersSource.available,+                onCheckedChange = onSafetyChange,+                enabled = SafetyLayersSource.available,+                leadingContent = { IconShield() },+            )+        }+    }+}
maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.ktindex 93b404d682..9a42de8c82 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MapPage.kt@@ -77,6 +77,7 @@ import com.vayunmathur.maps.util.OfflineRouter import com.vayunmathur.maps.util.RouteService import com.vayunmathur.maps.util.SavedPlacesViewModel import com.vayunmathur.maps.util.GooglePoiMapViewModel+import com.vayunmathur.maps.util.MapSettingsViewModel import com.vayunmathur.maps.util.MapsSearchViewModel import com.vayunmathur.maps.util.SelectedFeatureViewModel import com.vayunmathur.maps.util.ZoneDownloadManager@@ -111,13 +112,25 @@ import com.vayunmathur.maps.R as MapsR  @OptIn(ExperimentalMaterial3Api::class) @Composable-fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, zonesViewModel: MapsZonesViewModel, savedPlacesViewModel: SavedPlacesViewModel, poiViewModel: GooglePoiMapViewModel, searchViewModel: MapsSearchViewModel) {+fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel, zonesViewModel: MapsZonesViewModel, savedPlacesViewModel: SavedPlacesViewModel, poiViewModel: GooglePoiMapViewModel, searchViewModel: MapsSearchViewModel, settingsViewModel: MapSettingsViewModel) {     val selectedFeature by viewModel.selectedFeature.collectAsState()     val context = LocalContext.current     val coroutineScope = rememberCoroutineScope()      val savedHome by savedPlacesViewModel.home.collectAsState()     val savedWork by savedPlacesViewModel.work.collectAsState()+    val savedList by savedPlacesViewModel.saved.collectAsState()++    // All saved places drawn as pins: Home, Work and the starred list, deduped.+    val savedPins = remember(savedHome, savedWork, savedList) {+        (listOfNotNull(savedHome, savedWork) + savedList).distinct()+    }++    // Map-layer visibility toggles (P6 layers sheet, persisted via DataStore).+    val trafficEnabled by settingsViewModel.trafficLayer.collectAsState()+    val satelliteEnabled by settingsViewModel.satelliteLayer.collectAsState()+    val safetyEnabled by settingsViewModel.safetyLayer.collectAsState()+    var showLayersSheet by remember { mutableStateOf(false) }      // Google POI overlay pins (viewport scrape → custom layer, replacing the     // suppressed native basemap POIs).@@ -363,7 +376,7 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,             modifier = Modifier.padding(top = paddingValues.calculateTopPadding()),             actions = {                 IconButton({-                    backStack.add(Route.DownloadedMapsPage)+                    backStack.add(Route.SettingsPage)                 }) {                     IconSettings()                 }@@ -392,6 +405,10 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,                                     offset,                                     setOf(SEARCH_RESULT_LAYER_ID)                                 )?.firstNotNullOfOrNull { it.toSelectedSearchResult() }+                                    ?: projection?.queryRenderedFeatures(+                                        offset,+                                        setOf(SAVED_PLACE_LAYER_ID)+                                    )?.firstNotNullOfOrNull { it.toSelectedSavedPlace() }                                     ?: projection?.queryRenderedFeatures(                                         offset,                                         setOf(GOOGLE_POI_LAYER_ID)@@ -450,7 +467,7 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,                             ClickResult.Pass                         }                 ) {-                        MyMapLayers(selectedFeature, route?.get(selectedRouteType), json, userPosition, userBearing, navProgress, googlePins, searchResults)+                        MyMapLayers(selectedFeature, route?.get(selectedRouteType), json, userPosition, userBearing, navProgress, googlePins, searchResults, savedPins, trafficEnabled, satelliteEnabled, safetyEnabled)                     }                 } @@ -616,7 +633,7 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,                                 }                             },                         )-                        LayersButton(onClick = { /* P6: open the layers sheet */ })+                        LayersButton(onClick = { showLayersSheet = true })                         FloatingActionButton(                             onClick = {                                 coroutineScope.launch {@@ -656,6 +673,19 @@ fun MapPage(backStack: NavBackStack<Route>, viewModel: SelectedFeatureViewModel,                     onToggleNorthUp = { navNorthUp = !navNorthUp },                     destinationName = com.vayunmathur.maps.util.NavigationSessionManager.destinationName,                 )++                // Map-layers toggle sheet (P6), opened from the LayersButton.+                if (showLayersSheet) {+                    LayersSheet(+                        onDismiss = { showLayersSheet = false },+                        trafficEnabled = trafficEnabled,+                        onTrafficChange = { settingsViewModel.setTrafficLayer(it) },+                        satelliteEnabled = satelliteEnabled,+                        onSatelliteChange = { settingsViewModel.setSatelliteLayer(it) },+                        safetyEnabled = safetyEnabled,+                        onSafetyChange = { settingsViewModel.setSafetyLayer(it) },+                    )+                }             }         }     }
maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.ktindex c51e93b8c5..0bab43b089 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/MyMapLayers.kt@@ -55,6 +55,10 @@ fun MyMapLayers(     navProgress: com.vayunmathur.maps.util.NavigationProgress? = null,     googlePins: List<GooglePoiPin> = emptyList(),     searchResults: List<SearchResult> = emptyList(),+    savedPlaces: List<com.vayunmathur.maps.data.SavedPlace> = emptyList(),+    trafficEnabled: Boolean = true,+    satelliteEnabled: Boolean = false,+    safetyEnabled: Boolean = false, ) {     val trafficVersion by OfflineRouter.trafficVersion.collectAsState()     val context = LocalContext.current@@ -123,27 +127,41 @@ fun MyMapLayers(         }  -        LineLayer(-            "traffic-layer",-            trafficSource,-            sourceLayer = "traffic",-            color = feature["color"].cast<StringValue>().convertToColor(),-            width = interpolate(-                linear(),-                zoom(),-                11 to const(0.8.dp),-                12 to const(1.2.dp),-                14 to const(2.dp),-                18 to const(4.dp)-            ),-            opacity = const(0.6f),-            cap = const(LineCap.Butt)-        )+        // Satellite / aerial imagery (P6, Decision D11). Gated: renders nothing+        // until a raster tile source is hosted. Drawn first so it sits beneath+        // the overlays.+        SatelliteLayer(satelliteEnabled)++        if (trafficEnabled) {+            LineLayer(+                "traffic-layer",+                trafficSource,+                sourceLayer = "traffic",+                color = feature["color"].cast<StringValue>().convertToColor(),+                width = interpolate(+                    linear(),+                    zoom(),+                    11 to const(0.8.dp),+                    12 to const(1.2.dp),+                    14 to const(2.dp),+                    18 to const(4.dp)+                ),+                opacity = const(0.6f),+                cap = const(LineCap.Butt)+            )+        }++        // Safety / road-furniture layer (P6). Gated on the P13 PMTiles v5.+        SafetyLayer(safetyEnabled)          // Custom Google POI overlay (replaces suppressed native basemap POIs).         // Rendered above traffic but below the user puck.         GooglePoiLayer(googlePins) +        // Saved-place pins (Home / Work / starred list). Tap re-selects the+        // place → PlaceSheet (Vela's SavedPin).+        SavedPlacesLayer(savedPlaces)+         // Posted-speed-limit probe overlay (Decision D4). Invisible; queried         // under the puck during navigation. No-op until the tileset is hosted.         MaxspeedLayer()
maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.ktindex 75ff23be1a..25b89ed503 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/PlaceSheet.kt@@ -238,8 +238,8 @@ private fun PlaceActionRow(     requestDirections: () -> Unit, ) {     val context = LocalContext.current-    val home by savedPlacesViewModel.home.collectAsState()-    val isSaved = home?.matches(feature) == true+    val saved by savedPlacesViewModel.saved.collectAsState()+    val isSaved = saved.any { it.matches(feature) }      Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {         PlaceAction(@@ -266,7 +266,11 @@ private fun PlaceActionRow(             { IconSave(tint = if (isSaved) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface) },             stringResource(if (isSaved) R.string.place_action_saved else R.string.place_action_save),         ) {-            if (isSaved) savedPlacesViewModel.clearHome() else savedPlacesViewModel.setHome(feature)+            if (isSaved) {+                saved.firstOrNull { it.matches(feature) }?.let { savedPlacesViewModel.removeSaved(it) }+            } else {+                savedPlacesViewModel.addSaved(feature)+            }         }     } }
maps/src/main/java/com/vayunmathur/maps/ui/SatelliteLayer.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/SatelliteLayer.kt b/maps/src/main/java/com/vayunmathur/maps/ui/SatelliteLayer.ktnew file mode 100644index 0000000000..c3bafa289c--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/SatelliteLayer.kt@@ -0,0 +1,60 @@+package com.vayunmathur.maps.ui++import androidx.compose.runtime.Composable+import org.maplibre.compose.util.MaplibreComposable++/**+ * Satellite / aerial imagery layer (P6), ported conceptually from Vela's+ * `SatelliteLayer`.+ *+ * ⚠️ GATED — NO TILE SOURCE YET: [TILE_URL] is intentionally blank. MA's basemap+ * is the custom Protomaps vector PMTiles (`data.vayunmathur.com/v4.pmtiles`);+ * there is no hosted satellite/aerial raster tileset, and the Vela clone that+ * referenced Google's imagery was removed after research (see+ * `maps/VELA_PORT_PLAN.md`, Decision D11). While unavailable the layers sheet+ * hides the satellite toggle and this composable renders nothing.+ *+ * To activate: host an XYZ raster tileset, set [TILE_URL] to it, and mount a+ * `RasterLayer` over a raster source here behind the [available] guard.+ */+object SatelliteSource {+    const val TILE_URL: String = ""++    val available: Boolean get() = TILE_URL.isNotBlank()+}++/**+ * Mount the satellite raster overlay when [enabled] and a tile source exists.+ * No-op (renders nothing) while [SatelliteSource] is unavailable, so it is+ * always safe to include in the layer tree.+ */+@Composable+@MaplibreComposable+fun SatelliteLayer(enabled: Boolean) {+    if (!enabled || !SatelliteSource.available) return+    // Intentionally empty until a raster tileset is hosted (see SatelliteSource).+}++/**+ * Safety / road-furniture layer (P6), gated on the P13 deliverable.+ *+ * ⚠️ GATED — REQUIRES PMTILES v5: [available] is false until the new PMTiles+ * (safety/road-furniture features: speed cameras, stop signs, traffic signals)+ * lands in P13 and replaces `v4.pmtiles`. The toggle is surfaced now (disabled)+ * so the UI is ready; the layer renders nothing until v5 exists.+ */+object SafetyLayersSource {+    /** Flip to true once the P13 PMTiles v5 (with safety layers) is hosted. */+    const val available: Boolean = false+}++/**+ * Mount the safety-layers overlay when [enabled] and the v5 tileset exists.+ * No-op until P13 lands the PMTiles safety features.+ */+@Composable+@MaplibreComposable+fun SafetyLayer(enabled: Boolean) {+    if (!enabled || !SafetyLayersSource.available) return+    // Intentionally empty until PMTiles v5 ships the safety layers (P13).+}
maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesLayer.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesLayer.kt b/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesLayer.ktnew file mode 100644index 0000000000..a11a69b9f6--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesLayer.kt@@ -0,0 +1,151 @@+package com.vayunmathur.maps.ui++import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.ImageBitmap+import androidx.compose.ui.graphics.asImageBitmap+import androidx.compose.ui.unit.dp+import com.vayunmathur.maps.data.Feature1+import com.vayunmathur.maps.data.SavedPlace+import com.vayunmathur.maps.data.SpecificFeature+import com.vayunmathur.maps.data.string+import kotlinx.serialization.json.JsonObject+import kotlinx.serialization.json.JsonPrimitive+import kotlinx.serialization.json.doubleOrNull+import kotlinx.serialization.json.jsonPrimitive+import org.maplibre.compose.expressions.dsl.const+import org.maplibre.compose.expressions.dsl.image+import org.maplibre.compose.expressions.dsl.interpolate+import org.maplibre.compose.expressions.dsl.linear+import org.maplibre.compose.expressions.dsl.zoom+import org.maplibre.compose.layers.CircleLayer+import org.maplibre.compose.layers.SymbolLayer+import org.maplibre.compose.sources.GeoJsonData+import org.maplibre.compose.sources.GeoJsonOptions+import org.maplibre.compose.sources.GeoJsonSource+import org.maplibre.compose.util.MaplibreComposable+import org.maplibre.spatialk.geojson.FeatureCollection+import org.maplibre.spatialk.geojson.Point+import org.maplibre.spatialk.geojson.Position++/** Symbol layer id — hit-tested in MapPage.onMapClick so a tapped saved pin+ *  re-selects that place (Vela's `SavedPin`). */+const val SAVED_PLACE_LAYER_ID = "saved-place-pins"+private const val SAVED_PLACE_DOT_LAYER_ID = "saved-place-dots"+private const val SAVED_PLACE_SOURCE_ID = "saved-place-geojson"++/** Bookmark accent so saved pins read distinctly from the category-coloured+ *  ambient POIs and the red search-result pins. */+private val SAVED_PLACE_COLOR = Color(0xFF1A73E8)++/**+ * Saved-place overlay (Vela's `SavedPin`): a [GeoJsonSource] fed from the user's+ * saved places (Home, Work and the starred list) plus a [CircleLayer] "dot" and+ * a [SymbolLayer] bookmark glyph on top, ported to maplibre-compose declarative+ * layers exactly like [GooglePoiLayer] / [SearchResultLayer]. Tap → details via+ * [toSelectedSavedPlace], reusing [SpecificFeature.GenericPlace] so the existing+ * enrichment + place sheet render with no new detail path.+ */+@Composable+@MaplibreComposable+fun SavedPlacesLayer(places: List<SavedPlace>) {+    val marker = remember { generateSavedMarkerBitmap() }+    var source by remember { mutableStateOf<GeoJsonSource?>(null) }++    LaunchedEffect(Unit) {+        source = GeoJsonSource(+            SAVED_PLACE_SOURCE_ID,+            GeoJsonData.Features(FeatureCollection(emptyList<Feature1>())),+            GeoJsonOptions(),+        )+    }++    source?.let { src ->+        LaunchedEffect(places) {+            src.setData(GeoJsonData.Features(FeatureCollection(places.map { it.toPinFeature() })))+        }++        CircleLayer(+            SAVED_PLACE_DOT_LAYER_ID,+            src,+            color = const(SAVED_PLACE_COLOR),+            radius = interpolate(+                linear(), zoom(),+                11 to const(5.dp),+                14 to const(7.dp),+                17 to const(9.dp),+            ),+            strokeColor = const(Color.White),+            strokeWidth = const(2.dp),+        )++        SymbolLayer(+            SAVED_PLACE_LAYER_ID,+            src,+            iconImage = image(marker),+            iconSize = interpolate(+                linear(), zoom(),+                11 to const(0.4f),+                14 to const(0.55f),+                17 to const(0.7f),+            ),+        )+    }+}++/** Rebuild a saved place as a GeoJSON point feature; name/lat/lon ride along so+ *  onMapClick can re-select it. */+private fun SavedPlace.toPinFeature(): Feature1 = Feature1(+    Point(Position(lon, lat)),+    JsonObject(+        mapOf(+            "name" to JsonPrimitive(name),+            "lat" to JsonPrimitive(lat),+            "lng" to JsonPrimitive(lon),+        )+    ),+)++/**+ * Convert a hit-tested saved pin feature back into a selectable place, reusing+ * [SpecificFeature.GenericPlace] so `SelectedFeatureViewModel.currentPoiInfo`+ * fetches the Google enrichment and the place sheet renders.+ */+fun Feature1.toSelectedSavedPlace(): SpecificFeature? {+    val props = properties ?: return null+    val name = props.string("name")?.ifBlank { null } ?: return null+    val lat = props["lat"]?.jsonPrimitive?.doubleOrNull ?: return null+    val lng = props["lng"]?.jsonPrimitive?.doubleOrNull ?: return null+    return SpecificFeature.GenericPlace(name, null, null, null, Position(lng, lat))+}++/** Draw the saved marker once: a white bookmark-ish glyph on top of the base+ *  circle (a simple rounded tab reads as "saved" at pin size). */+private fun generateSavedMarkerBitmap(): ImageBitmap {+    val size = 48+    val bmp = android.graphics.Bitmap.createBitmap(size, size, android.graphics.Bitmap.Config.ARGB_8888)+    val canvas = android.graphics.Canvas(bmp)+    val paint = android.graphics.Paint(android.graphics.Paint.ANTI_ALIAS_FLAG)+    paint.color = android.graphics.Color.WHITE+    val w = size / 4f+    val h = size / 3f+    val left = (size - w) / 2f+    val top = (size - h) / 2f+    // Bookmark: a rounded rectangle with a notch cut from the bottom edge.+    canvas.drawRoundRect(left, top, left + w, top + h, 3f, 3f, paint)+    paint.color = android.graphics.Color.TRANSPARENT+    paint.xfermode = android.graphics.PorterDuffXfermode(android.graphics.PorterDuff.Mode.CLEAR)+    val notch = android.graphics.Path().apply {+        moveTo(left, top + h)+        lineTo(left + w / 2f, top + h - h / 3f)+        lineTo(left + w, top + h)+        close()+    }+    canvas.drawPath(notch, paint)+    return bmp.asImageBitmap()+}
maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesPage.ktnew file mode 100644index 0000000000..f56ad7c869--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/SavedPlacesPage.kt@@ -0,0 +1,289 @@+package com.vayunmathur.maps.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+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.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.DropdownMenuItem+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconHome+import com.vayunmathur.library.ui.IconList+import com.vayunmathur.library.ui.IconMoreVert+import com.vayunmathur.library.ui.IconStar+import com.vayunmathur.library.ui.IconWork+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.SettingsRow+import com.vayunmathur.library.ui.SettingsSection+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.maps.R+import com.vayunmathur.maps.Route+import com.vayunmathur.maps.data.SavedPlace+import com.vayunmathur.maps.util.SavedPlacesViewModel++/**+ * Saved-places screen (P6): view / edit / remove the user's saved places. Home+ * and Work quick-access slots, the flat starred list (rename, add-to-list,+ * remove), and named lists (create, delete, remove members). Built from the+ * shared `library/ui` settings components (no raw Scaffold); all edits go through+ * [SavedPlacesViewModel].+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun SavedPlacesPage(backStack: NavBackStack<Route>, viewModel: SavedPlacesViewModel) {+    val home by viewModel.home.collectAsState()+    val work by viewModel.work.collectAsState()+    val saved by viewModel.saved.collectAsState()+    val lists by viewModel.lists.collectAsState()++    var renameTarget by remember { mutableStateOf<SavedPlace?>(null) }+    var addToListTarget by remember { mutableStateOf<SavedPlace?>(null) }+    var showCreateList by remember { mutableStateOf(false) }++    AppScaffold(+        title = stringResource(R.string.saved_places_title),+        backStack = backStack,+    ) { padding ->+        Column(+            Modifier+                .fillMaxSize()+                .padding(padding)+                .verticalScroll(rememberScrollState()),+        ) {+            // --- Quick access: Home / Work ---+            SettingsSection(title = stringResource(R.string.saved_quick_access)) {+                if (home == null && work == null) {+                    SettingsRow(+                        title = stringResource(R.string.saved_quick_access_empty),+                        enabled = false,+                    )+                }+                home?.let { place ->+                    SettingsRow(+                        title = place.name,+                        supportingText = stringResource(R.string.saved_place_home),+                        leadingContent = { IconHome() },+                        trailingContent = {+                            IconButton(onClick = { viewModel.clearHome() }) { IconClose() }+                        },+                    )+                }+                work?.let { place ->+                    SettingsRow(+                        title = place.name,+                        supportingText = stringResource(R.string.saved_place_work),+                        leadingContent = { IconWork() },+                        trailingContent = {+                            IconButton(onClick = { viewModel.clearWork() }) { IconClose() }+                        },+                    )+                }+            }++            // --- Flat saved list ---+            SettingsSection(title = stringResource(R.string.saved_list_header)) {+                if (saved.isEmpty()) {+                    SettingsRow(+                        title = stringResource(R.string.saved_list_empty),+                        enabled = false,+                    )+                }+                saved.forEach { place ->+                    SavedPlaceRow(+                        place = place,+                        onRename = { renameTarget = place },+                        onAddToList = { addToListTarget = place },+                        onRemove = { viewModel.removeSaved(place) },+                    )+                }+            }++            // --- Named lists ---+            SettingsSection(title = stringResource(R.string.saved_lists_header)) {+                SettingsRow(+                    title = stringResource(R.string.saved_lists_new),+                    leadingContent = { IconAdd() },+                    onClick = { showCreateList = true },+                )+                lists.forEach { (name, places) ->+                    SettingsRow(+                        title = name,+                        supportingText = androidx.compose.ui.res.pluralStringResource(+                            R.plurals.saved_list_count, places.size, places.size+                        ),+                        leadingContent = { IconList() },+                        trailingContent = {+                            IconButton(onClick = { viewModel.deleteList(name) }) { IconDelete() }+                        },+                    )+                    places.forEach { place ->+                        SettingsRow(+                            title = place.name,+                            modifier = Modifier.padding(start = 16.dp),+                            leadingContent = { IconStar() },+                            trailingContent = {+                                IconButton(onClick = { viewModel.removeFromList(name, place) }) { IconClose() }+                            },+                        )+                    }+                }+            }+        }+    }++    renameTarget?.let { target ->+        TextEntryDialog(+            title = stringResource(R.string.saved_rename_title),+            initial = target.name,+            confirmLabel = stringResource(R.string.saved_rename_confirm),+            onDismiss = { renameTarget = null },+            onConfirm = { newName ->+                viewModel.renameSaved(target, newName)+                renameTarget = null+            },+        )+    }++    if (showCreateList) {+        TextEntryDialog(+            title = stringResource(R.string.saved_lists_new),+            initial = "",+            confirmLabel = stringResource(R.string.saved_lists_create),+            onDismiss = { showCreateList = false },+            onConfirm = { name ->+                viewModel.createList(name)+                showCreateList = false+            },+        )+    }++    addToListTarget?.let { target ->+        AddToListDialog(+            lists = lists.keys.toList(),+            onDismiss = { addToListTarget = null },+            onPick = { listName ->+                viewModel.addToList(listName, target)+                addToListTarget = null+            },+            onCreateAndAdd = { listName ->+                viewModel.createList(listName)+                viewModel.addToList(listName, target)+                addToListTarget = null+            },+        )+    }+}++@Composable+private fun SavedPlaceRow(+    place: SavedPlace,+    onRename: () -> Unit,+    onAddToList: () -> Unit,+    onRemove: () -> Unit,+) {+    var menuOpen by remember { mutableStateOf(false) }+    SettingsRow(+        title = place.name,+        leadingContent = { IconStar() },+        trailingContent = {+            IconButton(onClick = { menuOpen = true }) { IconMoreVert() }+            DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) {+                DropdownMenuItem(+                    text = { Text(stringResource(R.string.saved_action_rename)) },+                    onClick = { menuOpen = false; onRename() },+                )+                DropdownMenuItem(+                    text = { Text(stringResource(R.string.saved_action_add_to_list)) },+                    onClick = { menuOpen = false; onAddToList() },+                )+                DropdownMenuItem(+                    text = { Text(stringResource(R.string.saved_action_remove)) },+                    onClick = { menuOpen = false; onRemove() },+                )+            }+        },+    )+}++@Composable+private fun TextEntryDialog(+    title: String,+    initial: String,+    confirmLabel: String,+    onDismiss: () -> Unit,+    onConfirm: (String) -> Unit,+) {+    var text by remember { mutableStateOf(initial) }+    AlertDialog(+        onDismissRequest = onDismiss,+        confirmButton = {+            Button(onClick = { onConfirm(text) }, enabled = text.isNotBlank()) {+                Text(confirmLabel)+            }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(R.string.saved_cancel)) }+        },+        title = { Text(title) },+        text = {+            OutlinedTextField(+                value = text,+                onValueChange = { text = it },+                label = { Text(title) },+            )+        },+    )+}++@Composable+private fun AddToListDialog(+    lists: List<String>,+    onDismiss: () -> Unit,+    onPick: (String) -> Unit,+    onCreateAndAdd: (String) -> Unit,+) {+    var newName by remember { mutableStateOf("") }+    AlertDialog(+        onDismissRequest = onDismiss,+        confirmButton = {+            Button(onClick = { onCreateAndAdd(newName) }, enabled = newName.isNotBlank()) {+                Text(stringResource(R.string.saved_lists_create))+            }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(R.string.saved_cancel)) }+        },+        title = { Text(stringResource(R.string.saved_action_add_to_list)) },+        text = {+            Column {+                lists.forEach { name ->+                    SettingsRow(title = name, leadingContent = { IconList() }, onClick = { onPick(name) })+                }+                OutlinedTextField(+                    value = newName,+                    onValueChange = { newName = it },+                    label = { Text(stringResource(R.string.saved_lists_new)) },+                )+            }+        },+    )+}
maps/src/main/java/com/vayunmathur/maps/ui/settings/MapSettingsPage.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/settings/MapSettingsPage.kt b/maps/src/main/java/com/vayunmathur/maps/ui/settings/MapSettingsPage.ktnew file mode 100644index 0000000000..2ad7176648--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/ui/settings/MapSettingsPage.kt@@ -0,0 +1,113 @@+package com.vayunmathur.maps.ui.settings++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+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 com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconClearNight+import com.vayunmathur.library.ui.IconMap+import com.vayunmathur.library.ui.IconRuler+import com.vayunmathur.library.ui.IconStar+import com.vayunmathur.library.ui.IconVolumeUp+import com.vayunmathur.library.ui.SettingsSection+import com.vayunmathur.library.ui.SettingsSelectRow+import com.vayunmathur.library.ui.SettingsSwitchRow+import com.vayunmathur.maps.R+import com.vayunmathur.maps.Route+import com.vayunmathur.maps.data.DistanceUnit+import com.vayunmathur.maps.data.ThemeMode+import com.vayunmathur.maps.util.MapSettingsViewModel+import com.vayunmathur.library.util.NavBackStack++/**+ * Maps settings screen (P6): units, map theme / day-night, and the voice-guidance+ * toggle, plus entry points to the saved-places screen and the offline-maps+ * screen. Built entirely from the shared `library/ui` settings components (no raw+ * Scaffold) and backed by [MapSettingsViewModel] (DataStore).+ *+ * Wiring of the persisted values into behaviour lives at the point of use:+ *  - theme → `MainActivity` passes it to `DynamicTheme`,+ *  - voice guidance → `NavigationService` gates TTS on it,+ *  - distance unit → persisted here for display code to consume.+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun MapSettingsPage(backStack: NavBackStack<Route>, viewModel: MapSettingsViewModel) {+    val unit by viewModel.distanceUnit.collectAsState()+    val theme by viewModel.themeMode.collectAsState()+    val voice by viewModel.voiceGuidance.collectAsState()++    // Pre-resolve option labels — the SettingsSelectRow `label` lambda is a plain+    // (non-@Composable) function, so stringResource can't be called inside it.+    val unitLabels = mapOf(+        DistanceUnit.KILOMETERS to stringResource(R.string.settings_units_km),+        DistanceUnit.MILES to stringResource(R.string.settings_units_mi),+    )+    val themeLabels = mapOf(+        ThemeMode.SYSTEM to stringResource(R.string.settings_theme_system),+        ThemeMode.LIGHT to stringResource(R.string.settings_theme_light),+        ThemeMode.DARK to stringResource(R.string.settings_theme_dark),+    )++    AppScaffold(+        title = stringResource(R.string.settings_title),+        backStack = backStack,+    ) { padding ->+        Column(+            Modifier+                .fillMaxSize()+                .padding(padding)+                .verticalScroll(rememberScrollState()),+        ) {+            SettingsSection(title = stringResource(R.string.settings_section_display)) {+                SettingsSelectRow(+                    title = stringResource(R.string.settings_units),+                    selected = unit,+                    options = DistanceUnit.entries,+                    label = { unitLabels.getValue(it) },+                    onSelect = { viewModel.setDistanceUnit(it) },+                    leadingContent = { IconRuler() },+                )+                SettingsSelectRow(+                    title = stringResource(R.string.settings_theme),+                    selected = theme,+                    options = ThemeMode.entries,+                    label = { themeLabels.getValue(it) },+                    onSelect = { viewModel.setThemeMode(it) },+                    leadingContent = { IconClearNight() },+                )+            }++            SettingsSection(title = stringResource(R.string.settings_section_navigation)) {+                SettingsSwitchRow(+                    title = stringResource(R.string.settings_voice_guidance),+                    supportingText = stringResource(R.string.settings_voice_guidance_desc),+                    checked = voice,+                    onCheckedChange = { viewModel.setVoiceGuidance(it) },+                    leadingContent = { IconVolumeUp() },+                )+            }++            SettingsSection(title = stringResource(R.string.settings_section_places)) {+                com.vayunmathur.library.ui.SettingsRow(+                    title = stringResource(R.string.saved_places_title),+                    onClick = { backStack.add(Route.SavedPlacesPage) },+                    leadingContent = { IconStar() },+                )+                com.vayunmathur.library.ui.SettingsRow(+                    title = stringResource(R.string.downloaded_maps),+                    onClick = { backStack.add(Route.DownloadedMapsPage) },+                    leadingContent = { IconMap() },+                )+            }+        }+    }+}
maps/src/main/java/com/vayunmathur/maps/util/MapSettingsViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/MapSettingsViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/MapSettingsViewModel.ktnew file mode 100644index 0000000000..16c17dd6e5--- /dev/null+++ b/maps/src/main/java/com/vayunmathur/maps/util/MapSettingsViewModel.kt@@ -0,0 +1,90 @@+package com.vayunmathur.maps.util++import android.app.Application+import androidx.lifecycle.AndroidViewModel+import androidx.lifecycle.viewModelScope+import com.vayunmathur.library.util.DataStoreUtils+import com.vayunmathur.maps.data.DistanceUnit+import com.vayunmathur.maps.data.MapPreferences+import com.vayunmathur.maps.data.ThemeMode+import kotlinx.coroutines.flow.SharingStarted+import kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.map+import kotlinx.coroutines.flow.stateIn+import kotlinx.coroutines.launch++/**+ * Backs both the P6 settings screen (units / theme / voice guidance) and the P6+ * layers sheet (traffic / satellite / safety toggles), reading and writing the+ * shared [MapPreferences] keys through [DataStoreUtils].+ *+ * The layer toggles live here (rather than on the map VM) so the same persisted+ * value drives both the sheet's switches and the layer visibility in+ * `MyMapLayers`. Reads use the boolean/string flows seeded with the current+ * snapshot so the first frame already reflects the stored value; writes are+ * fire-and-forget on `viewModelScope`.+ */+class MapSettingsViewModel(application: Application) : AndroidViewModel(application) {+    private val ds = DataStoreUtils.getInstance(application)++    // --- Settings screen ---------------------------------------------------++    val distanceUnit: StateFlow<DistanceUnit> =+        ds.stringFlow(MapPreferences.KEY_DISTANCE_UNITS)+            .map { DistanceUnit.from(it) }+            .stateIn(+                viewModelScope, SharingStarted.Eagerly,+                DistanceUnit.from(ds.getString(MapPreferences.KEY_DISTANCE_UNITS)),+            )++    val themeMode: StateFlow<ThemeMode> =+        ds.stringFlow(MapPreferences.KEY_THEME_MODE)+            .map { ThemeMode.from(it) }+            .stateIn(+                viewModelScope, SharingStarted.Eagerly,+                ThemeMode.from(ds.getString(MapPreferences.KEY_THEME_MODE)),+            )++    val voiceGuidance: StateFlow<Boolean> = boolPref(+        MapPreferences.KEY_VOICE_GUIDANCE, MapPreferences.DEFAULT_VOICE_GUIDANCE,+    )++    fun setDistanceUnit(unit: DistanceUnit) =+        launch { ds.setString(MapPreferences.KEY_DISTANCE_UNITS, unit.pref) }++    fun setThemeMode(mode: ThemeMode) =+        launch { ds.setString(MapPreferences.KEY_THEME_MODE, mode.pref) }++    fun setVoiceGuidance(enabled: Boolean) =+        launch { ds.setBoolean(MapPreferences.KEY_VOICE_GUIDANCE, enabled) }++    // --- Layers sheet ------------------------------------------------------++    val trafficLayer: StateFlow<Boolean> = boolPref(+        MapPreferences.KEY_LAYER_TRAFFIC, MapPreferences.DEFAULT_LAYER_TRAFFIC,+    )+    val satelliteLayer: StateFlow<Boolean> = boolPref(+        MapPreferences.KEY_LAYER_SATELLITE, MapPreferences.DEFAULT_LAYER_SATELLITE,+    )+    val safetyLayer: StateFlow<Boolean> = boolPref(+        MapPreferences.KEY_LAYER_SAFETY, MapPreferences.DEFAULT_LAYER_SAFETY,+    )++    fun setTrafficLayer(enabled: Boolean) =+        launch { ds.setBoolean(MapPreferences.KEY_LAYER_TRAFFIC, enabled) }++    fun setSatelliteLayer(enabled: Boolean) =+        launch { ds.setBoolean(MapPreferences.KEY_LAYER_SATELLITE, enabled) }++    fun setSafetyLayer(enabled: Boolean) =+        launch { ds.setBoolean(MapPreferences.KEY_LAYER_SAFETY, enabled) }++    private fun boolPref(key: String, default: Boolean): StateFlow<Boolean> =+        ds.booleanFlow(key).stateIn(+            viewModelScope, SharingStarted.Eagerly, ds.getBoolean(key, default),+        )++    private fun launch(block: suspend () -> Unit) {+        viewModelScope.launch { block() }+    }+}
maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt b/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.ktindex 2e0b7d5af7..0b3b7e1791 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/NavigationService.kt@@ -113,7 +113,7 @@ class NavigationService : Service() {         when (state) {             is NavigationSessionManager.NavState.Navigating -> {                 val route = NavigationSessionManager.currentRoute-                if (route != null) {+                if (route != null && voiceGuidanceEnabled()) {                     NavigationTts.onProgressUpdate(state.progress, route.step)                 }                 maybeUpdateNotification(state)@@ -146,6 +146,18 @@ class NavigationService : Service() {         }     } +    /**+     * Whether spoken turn-by-turn cues are enabled (P6 settings). Read live from+     * DataStore so toggling voice guidance in settings takes effect immediately;+     * defaults to on when unset.+     */+    private fun voiceGuidanceEnabled(): Boolean =+        com.vayunmathur.library.util.DataStoreUtils.getInstance(this)+            .getBoolean(+                com.vayunmathur.maps.data.MapPreferences.KEY_VOICE_GUIDANCE,+                com.vayunmathur.maps.data.MapPreferences.DEFAULT_VOICE_GUIDANCE,+            )+     private fun maybeUpdateNotification(state: NavigationSessionManager.NavState) {         val now = System.currentTimeMillis()         if (now - lastNotificationUpdateMs >= NOTIFICATION_THROTTLE_MS) {
maps/src/main/java/com/vayunmathur/maps/util/SavedPlacesViewModel.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/util/SavedPlacesViewModel.kt b/maps/src/main/java/com/vayunmathur/maps/util/SavedPlacesViewModel.ktindex 6be9024039..6ce0448b4c 100644--- a/maps/src/main/java/com/vayunmathur/maps/util/SavedPlacesViewModel.kt+++ b/maps/src/main/java/com/vayunmathur/maps/util/SavedPlacesViewModel.kt@@ -5,48 +5,101 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.viewModelScope import com.vayunmathur.library.util.DataStoreUtils import com.vayunmathur.maps.data.SavedPlace+import com.vayunmathur.maps.data.SavedPlaceStore import com.vayunmathur.maps.data.SpecificFeature import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow-import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch-import kotlinx.serialization.json.Json  /**- * Stores the user's Home and Work quick-access places in DataStore. Each slot is- * persisted as a small JSON string; clearing a slot writes an empty string, which- * decodes back to null.+ * Exposes the user's saved places to the UI. P4 introduced the Home/Work+ * quick-access slots; P6 grows this into a full saved-places model backed by+ * [SavedPlaceStore]:+ *+ *  - [home] / [work] — single slots (unchanged public API so P4 wiring keeps+ *    working).+ *  - [saved] — a flat starred list built from the place sheet's Save action.+ *  - [lists] — named collections managed from the saved-places screen.+ *+ * All persistence lives in [SavedPlaceStore]; this class only adds the+ * `viewModelScope`, turns the store's flows into `StateFlow`s, and applies the+ * small list edits (add / remove / rename / list membership) against the latest+ * snapshot before writing it back.  */ class SavedPlacesViewModel(application: Application) : AndroidViewModel(application) {-    private val ds = DataStoreUtils.getInstance(application)+    private val store = SavedPlaceStore(DataStoreUtils.getInstance(application)) -    val home: StateFlow<SavedPlace?> = slotFlow(KEY_HOME)-    val work: StateFlow<SavedPlace?> = slotFlow(KEY_WORK)+    val home: StateFlow<SavedPlace?> =+        store.homeFlow().stateIn(viewModelScope, SharingStarted.Eagerly, store.homeInitial())+    val work: StateFlow<SavedPlace?> =+        store.workFlow().stateIn(viewModelScope, SharingStarted.Eagerly, store.workInitial())+    val saved: StateFlow<List<SavedPlace>> =+        store.savedFlow().stateIn(viewModelScope, SharingStarted.Eagerly, store.savedInitial())+    val lists: StateFlow<Map<String, List<SavedPlace>>> =+        store.listsFlow().stateIn(viewModelScope, SharingStarted.Eagerly, store.listsInitial()) -    fun setHome(feature: SpecificFeature.RoutableFeature) = save(KEY_HOME, SavedPlace.from(feature))-    fun setWork(feature: SpecificFeature.RoutableFeature) = save(KEY_WORK, SavedPlace.from(feature))-    fun clearHome() = clear(KEY_HOME)-    fun clearWork() = clear(KEY_WORK)+    // --- Home / Work slots ------------------------------------------------- -    private fun slotFlow(key: String): StateFlow<SavedPlace?> =-        ds.stringFlow(key)-            .map { decode(it) }-            .stateIn(viewModelScope, SharingStarted.Eagerly, decode(ds.getString(key)))+    fun setHome(feature: SpecificFeature.RoutableFeature) =+        launch { store.setHome(SavedPlace.from(feature)) } -    private fun save(key: String, place: SavedPlace) {-        viewModelScope.launch { ds.setString(key, Json.encodeToString(place)) }+    fun setWork(feature: SpecificFeature.RoutableFeature) =+        launch { store.setWork(SavedPlace.from(feature)) }++    fun clearHome() = launch { store.setHome(null) }+    fun clearWork() = launch { store.setWork(null) }++    // --- Flat saved (starred) list ----------------------------------------++    /** True if [feature] is already in the flat saved list. */+    fun isSaved(feature: SpecificFeature.RoutableFeature): Boolean =+        saved.value.any { it.matches(feature) }++    fun addSaved(feature: SpecificFeature.RoutableFeature) = launch {+        val place = SavedPlace.from(feature)+        if (saved.value.none { it.matches(feature) }) {+            store.setSaved(saved.value + place)+        }+    }++    fun removeSaved(place: SavedPlace) = launch { store.setSaved(saved.value - place) }++    fun renameSaved(place: SavedPlace, newName: String) = launch {+        val name = newName.trim()+        if (name.isEmpty()) return@launch+        store.setSaved(saved.value.map { if (it == place) it.copy(name = name) else it })     } -    private fun clear(key: String) {-        viewModelScope.launch { ds.setString(key, "") }+    // --- Named lists -------------------------------------------------------++    fun createList(name: String) = launch {+        val listName = name.trim()+        if (listName.isEmpty() || lists.value.containsKey(listName)) return@launch+        store.setLists(lists.value + (listName to emptyList()))+    }++    fun deleteList(name: String) = launch { store.setLists(lists.value - name) }++    fun addToList(name: String, feature: SpecificFeature.RoutableFeature) = launch {+        val place = SavedPlace.from(feature)+        val current = lists.value[name].orEmpty()+        if (current.any { it.matches(feature) }) return@launch+        store.setLists(lists.value + (name to (current + place)))     } -    private fun decode(raw: String?): SavedPlace? =-        raw?.takeIf { it.isNotBlank() }?.let { runCatching { Json.decodeFromString<SavedPlace>(it) }.getOrNull() }+    fun addToList(name: String, place: SavedPlace) = launch {+        val current = lists.value[name].orEmpty()+        if (place in current) return@launch+        store.setLists(lists.value + (name to (current + place)))+    }++    fun removeFromList(name: String, place: SavedPlace) = launch {+        val current = lists.value[name] ?: return@launch+        store.setLists(lists.value + (name to (current - place)))+    } -    companion object {-        private const val KEY_HOME = "saved_place_home"-        private const val KEY_WORK = "saved_place_work"+    private fun launch(block: suspend () -> Unit) {+        viewModelScope.launch { block() }     } }
maps/src/main/res/values/strings.xml
diff --git a/maps/src/main/res/values/strings.xml b/maps/src/main/res/values/strings.xmlindex 9d467685c3..98191322a2 100644--- a/maps/src/main/res/values/strings.xml+++ b/maps/src/main/res/values/strings.xml@@ -277,4 +277,82 @@     <string name="min"><xliff:g id="minutes" example="12">%1$s</xliff:g> min · <xliff:g id="distance" example="1.2 km">%2$s</xliff:g></string>     <string name="map_zone_download_title">Map Zone <xliff:g id="zone" example="7">%1$d</xliff:g> (Map)</string>     <string name="map_zone_download_desc">Downloading high-detail offline map data</string>++    <!-- LayersSheet: title of the map-layers toggle sheet. Noun. -->+    <string name="layers_title">Map layers</string>+    <!-- LayersSheet: traffic layer toggle. Noun. -->+    <string name="layer_traffic">Traffic</string>+    <!-- LayersSheet: traffic layer description. -->+    <string name="layer_traffic_desc">Show live traffic conditions</string>+    <!-- LayersSheet: satellite imagery toggle. Noun. -->+    <string name="layer_satellite">Satellite</string>+    <!-- LayersSheet: satellite imagery description. -->+    <string name="layer_satellite_desc">Show aerial imagery</string>+    <!-- LayersSheet: safety layers toggle (speed cameras, stop signs, signals). Noun. -->+    <string name="layer_safety">Safety layers</string>+    <!-- LayersSheet: safety layers description when available. -->+    <string name="layer_safety_desc">Show speed cameras, stop signs and signals</string>+    <!-- LayersSheet: safety layers description while the data isn't available yet. -->+    <string name="layer_safety_unavailable">Coming soon</string>++    <!-- Settings: screen title. Noun. -->+    <string name="settings_title">Settings</string>+    <!-- Settings: section header for display options. Noun. -->+    <string name="settings_section_display">Display</string>+    <!-- Settings: section header for navigation options. Noun. -->+    <string name="settings_section_navigation">Navigation</string>+    <!-- Settings: section header for places and maps entries. Noun. -->+    <string name="settings_section_places">Places &amp; maps</string>+    <!-- Settings: distance-units setting title. Noun. -->+    <string name="settings_units">Distance units</string>+    <!-- Settings: kilometres unit option. -->+    <string name="settings_units_km">Kilometers</string>+    <!-- Settings: miles unit option. -->+    <string name="settings_units_mi">Miles</string>+    <!-- Settings: map-theme setting title. Noun. -->+    <string name="settings_theme">Map theme</string>+    <!-- Settings: theme option following the system day/night setting. -->+    <string name="settings_theme_system">System default</string>+    <!-- Settings: light (day) theme option. -->+    <string name="settings_theme_light">Light</string>+    <!-- Settings: dark (night) theme option. -->+    <string name="settings_theme_dark">Dark</string>+    <!-- Settings: voice-guidance toggle title. Noun. -->+    <string name="settings_voice_guidance">Voice guidance</string>+    <!-- Settings: voice-guidance toggle description. -->+    <string name="settings_voice_guidance_desc">Speak turn-by-turn directions</string>++    <!-- SavedPlacesPage: screen title. Noun. -->+    <string name="saved_places_title">Saved places</string>+    <!-- SavedPlacesPage: section header for Home/Work quick-access slots. Noun. -->+    <string name="saved_quick_access">Quick access</string>+    <!-- SavedPlacesPage: shown when neither Home nor Work is set. -->+    <string name="saved_quick_access_empty">No Home or Work set yet</string>+    <!-- SavedPlacesPage: section header for the starred list. Noun. -->+    <string name="saved_list_header">Saved</string>+    <!-- SavedPlacesPage: shown when the starred list is empty. -->+    <string name="saved_list_empty">Places you save appear here</string>+    <!-- SavedPlacesPage: section header for named lists. Noun. -->+    <string name="saved_lists_header">Lists</string>+    <!-- SavedPlacesPage: row/action to create a new list. Verb phrase. -->+    <string name="saved_lists_new">New list</string>+    <!-- SavedPlacesPage: confirm button to create a list. Verb. -->+    <string name="saved_lists_create">Create</string>+    <!-- SavedPlacesPage: number of places in a list. -->+    <plurals name="saved_list_count">+        <item quantity="one"><xliff:g id="count" example="1">%1$d</xliff:g> place</item>+        <item quantity="other"><xliff:g id="count" example="3">%1$d</xliff:g> places</item>+    </plurals>+    <!-- SavedPlacesPage: rename dialog title. Verb. -->+    <string name="saved_rename_title">Rename place</string>+    <!-- SavedPlacesPage: rename dialog confirm button. Verb. -->+    <string name="saved_rename_confirm">Rename</string>+    <!-- SavedPlacesPage: overflow action to rename a saved place. Verb. -->+    <string name="saved_action_rename">Rename</string>+    <!-- SavedPlacesPage: overflow action to add a saved place to a list. Verb phrase. -->+    <string name="saved_action_add_to_list">Add to list…</string>+    <!-- SavedPlacesPage: overflow action to remove a saved place. Verb. -->+    <string name="saved_action_remove">Remove</string>+    <!-- SavedPlacesPage: generic cancel button. Verb. -->+    <string name="saved_cancel">Cancel</string> </resources>