Modern Apps git

← Modern-Apps.git

maps-wear: the live route overlay is the only route drawn

Commit
a19d15db137c0d8b2b3a6bd265f1d2bcd2141a0f
Author
Vayun Mathur <[email protected]>
When
2026-12-01 10:51 UTC (5 days ago)
Parents
c3ba42c
The renderer had two route sources: the WearRouteState
overlay (correctly cleared when the phone sent
active=false) and ROUTE lines baked into the map snapshot,
drawn unconditionally in route colour. Ending navigation
cleared the overlay and its persisted file but not the
snapshot, so the old route segment stayed on the map while
the route screen said 'No route' โ€” and a reroute drew both
routes at once.

The live overlay is now the sole route source: a pure
wearBasemapLines helper returns snapshot lines minus ROUTE
for the basemap loops. No protocol or store change โ€” the
snapshot may still carry the lines; the watch never renders
them as a route. Regression test on a Berlin-centred fixture
excludes open+closed ROUTE lines while preserving
ROAD/BUILDING order. Projection and store clearing were
audited and cleared. Verified: :maps:wear:testDebugUnitTest
10/10 pass; lint BUILD SUCCESSFUL.

Diff

maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.ktindex d302c864c3..517e00b425 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt@@ -81,6 +81,16 @@ fun wearDistanceM(fromLatE7: Int, fromLonE7: Int, to: WearSavedPlace): Double { fun wearApplyRouteState(current: WearRouteState?, incoming: WearRouteState): WearRouteState? =     if (incoming.active) incoming else null +/**+ * Snapshot lines the renderer may draw as basemap. A [WearLineKind.ROUTE]+ * line baked into a snapshot is never drawn: the live [WearRouteState] is+ * the sole route source, so the explicit clear (`active=false`, which+ * leaves the persisted snapshot untouched) and any reroute (a new overlay+ * over an older snapshot) can never leave a stale route on the map.+ */+fun wearBasemapLines(snapshot: WearMapSnapshot): List<WearMapLine> =+    snapshot.lines.filter { it.kind != WearLineKind.ROUTE }+ /** Stale when the snapshot is older than the protocol window; no snapshot is always stale. */ fun wearIsStale(snapshot: WearMapSnapshot?, nowMillis: Long): Boolean =     snapshot == null || nowMillis - snapshot.generatedAtMillis > WearMapsProtocol.STALE_AFTER_MS
maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.ktindex 611a24d9c6..d016fd06a8 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt@@ -14,6 +14,7 @@ import com.vayunmathur.maps.wear.domain.WearMapProjection import com.vayunmathur.maps.wear.domain.WearMapSnapshot import com.vayunmathur.maps.wear.domain.WearPosition import com.vayunmathur.maps.wear.domain.WearRouteState+import com.vayunmathur.maps.wear.domain.wearBasemapLines import com.vayunmathur.maps.wear.domain.wearDequantize import com.vayunmathur.maps.wear.domain.wearOffsetInSnapshot import com.vayunmathur.maps.wear.domain.wearRoutePointInSnapshot@@ -64,13 +65,17 @@ fun WearMapCanvas(             return path         }         val snapshotPts = { dx: Int, dy: Int -> wearDequantize(dx) to wearDequantize(dy) }+        // Basemap only: a ROUTE line baked into the snapshot is not drawn โ€”+        // the live route overlay below is the sole route source, so a+        // cleared or superseded route cannot linger on the map.+        val basemapLines = wearBasemapLines(snapshot)         // Fills first, then strokes in kind-priority order.-        for (line in snapshot.lines.filter { it.closed }) {+        for (line in basemapLines.filter { it.closed }) {             val color = if (line.kind == WearLineKind.WATER) WaterColor else BuildingColor             drawPath(pathOf(line.pts, snapshotPts), color)         }         for (kind in listOf(WearLineKind.WATER, WearLineKind.ROAD, WearLineKind.PATH)) {-            for (line in snapshot.lines.filter { !it.closed && it.kind == kind }) {+            for (line in basemapLines.filter { !it.closed && it.kind == kind }) {                 drawPath(                     pathOf(line.pts, snapshotPts),                     color = when (kind) {@@ -89,10 +94,7 @@ fun WearMapCanvas(                 )             }         }-        // Snapshot-embedded route lines, then the live route overlay (fresher).-        for (line in snapshot.lines.filter { !it.closed && it.kind == WearLineKind.ROUTE }) {-            drawPath(pathOf(line.pts, snapshotPts), RouteColor, style = Stroke(width = 5f))-        }+        // Live route overlay (sole route source; see wearBasemapLines).         if (route?.active == true && route.routePts.size >= 4) {             val routePath = pathOf(route.routePts) { dx, dy ->                 wearRoutePointInSnapshot(snapshot, route, dx, dy)
maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt
diff --git a/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt b/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.ktindex d5fe16360c..e422e71b1d 100644--- a/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt+++ b/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt@@ -117,6 +117,24 @@ class WearMapsProtocolTest {         assertEquals(null, wearApplyRouteState(null, WearRouteState(active = false)))     } +    @Test+    fun snapshotRouteLinesAreNeverBasemap() {+        // Berlin centre; the baked-in ROUTE segment runs (0 m, 0 m) ->+        // (100 m east, 0 m) in quantized units (50 units * 2 m).+        val road = WearMapLine(WearLineKind.ROAD, listOf(0, 0, 10, 0))+        val building = WearMapLine(WearLineKind.BUILDING, listOf(0, 0, 5, 0, 5, 5), closed = true)+        val bakedRoute = WearMapLine(WearLineKind.ROUTE, listOf(0, 0, 50, 0))+        val closedRoute = WearMapLine(WearLineKind.ROUTE, listOf(0, 0, 50, 0), closed = true)+        val snapshot = WearMapSnapshot(+            centerLatE7 = 525_200_000,+            centerLonE7 = 134_050_000,+            lines = listOf(road, bakedRoute, building, closedRoute),+        )+        // Cleared route (route == null after active=false) and reroute alike:+        // only the live WearRouteState may draw a route, never the snapshot.+        assertEquals(listOf(road, building), wearBasemapLines(snapshot))+    }+     @Test     fun savedDistanceUsesUserPosition() {         val home = WearSavedPlace("Home", latE7 = 0, lonE7 = (0.01 * 1e7).toInt()) // ~1.1 km east