From ad6ea557eda0d8bc549fc7b70e58adead80a4d2e Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 01/22] feat: open the route map full screen from a workout's summary Co-Authored-By: Claude Sonnet 5.5 --- .../app/ui/glow/FullScreenRouteMap.kt | 74 +++++++++++++++++++ .../app/ui/glow/GlowWorkoutSummary.kt | 21 ++++-- .../openstrap/app/ui/glow/SummarySections.kt | 8 +- .../main/res/values/strings_glow_summary.xml | 10 +++ .../app/ui/glow/FullScreenRouteMapTest.kt | 74 +++++++++++++++++++ 5 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt create mode 100644 app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt new file mode 100644 index 00000000..2e3e6ee3 --- /dev/null +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt @@ -0,0 +1,74 @@ +package org.openstrap.app.ui.glow + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawing +import androidx.compose.foundation.layout.windowInsetsPadding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import org.openstrap.app.R +import org.openstrap.app.data.Route +import org.openstrap.app.ui.dashboard.LocalHeartZones +import org.openstrap.app.ui.workout.PhoneSummary + +/** The route cut into stretches in the colour of the heart zone each was run in, for the card's map and the full one. */ +@Composable +internal fun rememberZoneStretches(summary: PhoneSummary): List, Int>> { + val heartZones = LocalHeartZones.current + return remember(summary, heartZones) { + Route.byZone(summary.route, summary.history, summary.analysis.maxHeartRate, heartZones) + } +} + +/** The route map over the whole screen, in its own window so it covers the bars; Back or [onClose] closes it. */ +@Composable +internal fun FullScreenRouteMap(summary: PhoneSummary, onClose: () -> Unit) { + Dialog( + onDismissRequest = onClose, + properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false), + ) { FullScreenRouteMapContent(summary, onClose) } +} + +/** + * The map and its pills, without the window: Close top-end, Route only (or Show map) top-start, and Fit route top-centre + * once a drag has stopped the map following the route. The bottom edge stays free for what is put there. + */ +@Composable +internal fun FullScreenRouteMapContent(summary: PhoneSummary, onClose: () -> Unit) { + val stretches = rememberZoneStretches(summary) + var routeOnly by rememberSaveable { mutableStateOf(false) } + var follow by remember { mutableStateOf(true) } + Box(Modifier.fillMaxSize().background(Color.Black)) { + WorkoutMap( + stretches, + routeOnly, + Modifier.fillMaxSize(), + follow = follow, + fitPadding = PaddingValues(horizontal = 24.dp, vertical = 96.dp), + onPanned = { follow = false }, + ) + Box(Modifier.fillMaxSize().windowInsetsPadding(WindowInsets.safeDrawing).padding(12.dp)) { + val routeOnlyLabel = if (routeOnly) R.string.glow_summary_map_show_map else R.string.glow_summary_map_route_only + IconPill(stringResource(routeOnlyLabel), { routeOnly = !routeOnly }, Modifier.align(Alignment.TopStart)) + if (!follow) { + IconPill(stringResource(R.string.glow_summary_map_fit), { follow = true }, Modifier.align(Alignment.TopCenter)) + } + IconPill(stringResource(R.string.glow_summary_map_close), onClose, Modifier.align(Alignment.TopEnd)) + } + } +} diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt index 2a366c3f..1c9b6c74 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt @@ -9,6 +9,7 @@ import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.tween import androidx.compose.foundation.Canvas import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues @@ -32,6 +33,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.geometry.Offset @@ -328,15 +331,21 @@ private fun DropLine(readings: List>, end: Long, modifier: Modif } } -/** The kept route in its zones' colours; nothing without a route that goes somewhere. */ +/** + * The kept route in its zones' colours; nothing without a route that goes somewhere. Tapping the map calls [onOpen] + * when it is given. + */ @Composable -internal fun RouteMap(summary: PhoneSummary, modifier: Modifier = Modifier) { - val heartZones = LocalHeartZones.current +internal fun RouteMap(summary: PhoneSummary, modifier: Modifier = Modifier, onOpen: (() -> Unit)? = null) { if (!Route.mappable(summary.route)) return - val stretches = remember(summary, heartZones) { - Route.byZone(summary.route, summary.history, summary.analysis.maxHeartRate, heartZones) + val stretches = rememberZoneStretches(summary) + val open = stringResource(R.string.glow_summary_map_open) + val tap = if (onOpen == null) { + Modifier + } else { + Modifier.clickable(onClickLabel = open, onClick = onOpen).semantics { contentDescription = open } } - Box(modifier.fillMaxWidth().height(170.dp).clip(GlowLayout.TileShape).background(Raised)) { + Box(modifier.fillMaxWidth().height(170.dp).clip(GlowLayout.TileShape).background(Raised).then(tap)) { WorkoutMap(stretches, routeOnly = false, Modifier.fillMaxSize()) } } diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/SummarySections.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/SummarySections.kt index 3884226f..d3308834 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/SummarySections.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/SummarySections.kt @@ -5,6 +5,10 @@ import org.openstrap.app.data.Weeks import org.openstrap.app.i18n.Strings import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import org.openstrap.app.presentation.Ranges import org.openstrap.app.presentation.Units import org.openstrap.app.presentation.Pace @@ -257,10 +261,12 @@ internal fun FamilySection( @Composable private fun RouteCard(summary: PhoneSummary) { if (!Route.mappable(summary.route)) return + var full by rememberSaveable { mutableStateOf(false) } + if (full) FullScreenRouteMap(summary) { full = false } PictureCard(MetricColors.steps, Modifier.fillMaxWidth()) { val climb = Route.climb(summary.route)?.let { stringResource(R.string.glow_summary_climb, Math.round(it)) } EdgeTitle(stringResource(R.string.glow_summary_route), climb) - RouteMap(summary, Modifier.padding(top = 12.dp)) + RouteMap(summary, Modifier.padding(top = 12.dp), onOpen = { full = true }) } } diff --git a/app/src/main/res/values/strings_glow_summary.xml b/app/src/main/res/values/strings_glow_summary.xml index bada8171..27e8c3a7 100644 --- a/app/src/main/res/values/strings_glow_summary.xml +++ b/app/src/main/res/values/strings_glow_summary.xml @@ -95,6 +95,16 @@ Route Climb %1$d m + + Open map full screen + + Close + + Route only + + Show map + + Fit route Sets diff --git a/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt new file mode 100644 index 00000000..44c1d116 --- /dev/null +++ b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt @@ -0,0 +1,74 @@ +package org.openstrap.app.ui.glow + +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.platform.LocalInspectionMode +import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.onAllNodesWithText +import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import androidx.test.core.app.ApplicationProvider +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.openstrap.app.R +import org.openstrap.app.data.HeartZones +import org.openstrap.app.data.Route +import org.openstrap.app.data.WorkoutRecorder +import org.openstrap.app.data.db.AppWorkout +import org.openstrap.app.testing.ComposeRules +import org.openstrap.app.ui.workout.PhoneSummary +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** The full-screen route map: its pills, and the summary's route card map that opens it. */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [35], qualifiers = "w411dp-h891dp-port") +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class FullScreenRouteMapTest { + @get:Rule val rules = ComposeRules() + + private val start = 1_792_000_000L + + private fun text(id: Int) = ApplicationProvider.getApplicationContext().getString(id) + + /** A 3 m/s run east along the equator, a fix a second. */ + private fun summary(): PhoneSummary { + val w = AppWorkout(start, start + 40, 1) + val route = (0..40).map { Route.Point(start + it, 0.0, it * 3.0 / 111_195.0, 5f) } + val analysis = WorkoutRecorder.analyse(w, emptyList(), 190, HeartZones.STANDARD) + return PhoneSummary(analysis, emptyList(), start, start + 40, null, route = route) + } + + private fun show(content: @androidx.compose.runtime.Composable () -> Unit) { + rules.compose.setContent { CompositionLocalProvider(LocalInspectionMode provides true) { content() } } + } + + @Test fun `closing calls onClose`() { + var closed = 0 + show { FullScreenRouteMapContent(summary()) { closed++ } } + rules.compose.onNodeWithText(text(R.string.glow_summary_map_close)).performClick() + assertEquals(1, closed) + } + + @Test fun `route only can be switched on and back`() { + show { FullScreenRouteMapContent(summary()) {} } + rules.compose.onNodeWithText(text(R.string.glow_summary_map_route_only)).performClick() + rules.compose.onNodeWithText(text(R.string.glow_summary_map_show_map)).performClick() + rules.compose.onNodeWithText(text(R.string.glow_summary_map_route_only)).assertExists() + } + + @Test fun `fit route shows only after the map was panned`() { + show { FullScreenRouteMapContent(summary()) {} } + rules.compose.onAllNodesWithText(text(R.string.glow_summary_map_fit)).assertCountEquals(0) + } + + @Test fun `the summary's route card map opens it`() { + var opened = 0 + show { RouteMap(summary(), onOpen = { opened++ }) } + rules.compose.onNodeWithContentDescription(text(R.string.glow_summary_map_open)).performClick() + assertEquals(1, opened) + } +} From fae8f492ab34013eac7a4840ee575fcd328624b8 Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 02/22] fix: route card taps open the full-screen map over the live map Co-Authored-By: Claude Sonnet 5.5 --- .../org/openstrap/app/ui/glow/GlowWorkoutSummary.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt index 1c9b6c74..9cdd67cb 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt @@ -340,13 +340,14 @@ internal fun RouteMap(summary: PhoneSummary, modifier: Modifier = Modifier, onOp if (!Route.mappable(summary.route)) return val stretches = rememberZoneStretches(summary) val open = stringResource(R.string.glow_summary_map_open) - val tap = if (onOpen == null) { - Modifier - } else { - Modifier.clickable(onClickLabel = open, onClick = onOpen).semantics { contentDescription = open } - } - Box(modifier.fillMaxWidth().height(170.dp).clip(GlowLayout.TileShape).background(Raised).then(tap)) { + Box(modifier.fillMaxWidth().height(170.dp).clip(GlowLayout.TileShape).background(Raised)) { WorkoutMap(stretches, routeOnly = false, Modifier.fillMaxSize()) + // The live map takes touches itself, so a layer above it catches the tap: the card's map is a preview. + if (onOpen != null) { + Box( + Modifier.matchParentSize().clickable(onClickLabel = open, onClick = onOpen).semantics { contentDescription = open }, + ) + } } } From 6719a5673d4981197a4ab1b89c5ea2be9f84f850 Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 03/22] feat: km markers and split highlight on the full-screen route map Co-Authored-By: Claude Sonnet 5.5 --- .../kotlin/org/openstrap/app/data/Route.kt | 21 ++++-- .../app/ui/glow/FullScreenRouteMap.kt | 30 +++++++- .../app/ui/glow/GlowWorkoutSummary.kt | 12 +++- .../org/openstrap/app/ui/glow/KmMarkers.kt | 43 +++++++++++ .../org/openstrap/app/ui/glow/SplitPicker.kt | 47 ++++++++++++ .../org/openstrap/app/ui/glow/WorkoutMap.kt | 72 ++++++++++++++++--- .../org/openstrap/app/data/RouteTest.kt | 30 ++++++++ .../app/ui/glow/FullScreenRouteMapTest.kt | 37 ++++++++-- .../openstrap/app/ui/glow/KmMarkersTest.kt | 50 +++++++++++++ 9 files changed, 317 insertions(+), 25 deletions(-) create mode 100644 app/src/main/kotlin/org/openstrap/app/ui/glow/KmMarkers.kt create mode 100644 app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt create mode 100644 app/src/test/kotlin/org/openstrap/app/ui/glow/KmMarkersTest.kt diff --git a/app/src/main/kotlin/org/openstrap/app/data/Route.kt b/app/src/main/kotlin/org/openstrap/app/data/Route.kt index b1c7f15c..7fa3352e 100644 --- a/app/src/main/kotlin/org/openstrap/app/data/Route.kt +++ b/app/src/main/kotlin/org/openstrap/app/data/Route.kt @@ -321,24 +321,33 @@ object Route { } /** Per-kilometre splits along [points]; the last one may be partial. Paused time doesn't count. */ - fun splits(points: List, pauses: List = emptyList(), km: Double = 1000.0): List { + fun splits(points: List, pauses: List = emptyList(), km: Double = 1000.0): List = + legs(points, pauses, km).map { it.split } + + /** One kilometre's [split] with the smoothed track [points] it covers, from the previous leg's last point. */ + data class Leg(val split: Split, val points: List) + + /** The kilometres of [splits], each with its stretch of the smoothed track; paused stretches are left out. */ + fun legs(points: List, pauses: List = emptyList(), km: Double = 1000.0): List { val clean = track(points) - val out = mutableListOf() - var startT = clean.firstOrNull()?.t ?: return out + val out = mutableListOf() + val current = mutableListOf(clean.firstOrNull() ?: return out) var meters = 0.0 var seconds = 0L clean.zipWithNext().forEach { (a, b) -> if (paused(a, b, pauses)) return@forEach meters += meters(a, b) seconds += b.t - a.t + current += b if (meters >= km) { - out += Split(out.size, b.t, seconds, meters) + out += Leg(Split(out.size, b.t, seconds, meters), current.toList()) + current.clear() + current += b meters = 0.0 seconds = 0 - startT = b.t } } - if (meters > 0) out += Split(out.size, clean.last().t, seconds, meters) + if (meters > 0) out += Leg(Split(out.size, clean.last().t, seconds, meters), current) return out } diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt index 2e3e6ee3..5bec7385 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing @@ -17,6 +18,8 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog @@ -46,21 +49,33 @@ internal fun FullScreenRouteMap(summary: PhoneSummary, onClose: () -> Unit) { /** * The map and its pills, without the window: Close top-end, Route only (or Show map) top-start, and Fit route top-centre - * once a drag has stopped the map following the route. The bottom edge stays free for what is put there. + * once a drag has stopped the map following the route. Km markers sit along the line, and the split picker along the + * bottom draws the chosen kilometre with a white casing and fits it. */ @Composable internal fun FullScreenRouteMapContent(summary: PhoneSummary, onClose: () -> Unit) { val stretches = rememberZoneStretches(summary) var routeOnly by rememberSaveable { mutableStateOf(false) } var follow by remember { mutableStateOf(true) } + val legs = remember(summary) { Route.legs(summary.route, summary.pauses) } + val kmMarkers = remember(legs) { legs.filter { it.split.meters >= 1000.0 }.map { it.split.index + 1 to it.points.last() } } + val rows = remember(summary) { splitRowsFor(summary, summary.route) } + var selected by rememberSaveable { mutableStateOf(null) } + var pickerHeight by remember { mutableStateOf(0.dp) } + val density = LocalDensity.current + // From the screen's bottom edge to the picker's top, so the fitted route and the map's credit stay above it. + val underPicker = WindowInsets.safeDrawing.asPaddingValues().calculateBottomPadding() + 12.dp + pickerHeight Box(Modifier.fillMaxSize().background(Color.Black)) { WorkoutMap( stretches, routeOnly, Modifier.fillMaxSize(), follow = follow, - fitPadding = PaddingValues(horizontal = 24.dp, vertical = 96.dp), + fitPadding = PaddingValues(start = 24.dp, top = 96.dp, end = 24.dp, bottom = maxOf(96.dp, underPicker + 24.dp)), + creditBottom = underPicker + 8.dp, onPanned = { follow = false }, + kmMarkers = kmMarkers, + highlight = selected?.let { legs.getOrNull(it)?.points }.orEmpty(), ) Box(Modifier.fillMaxSize().windowInsetsPadding(WindowInsets.safeDrawing).padding(12.dp)) { val routeOnlyLabel = if (routeOnly) R.string.glow_summary_map_show_map else R.string.glow_summary_map_route_only @@ -69,6 +84,17 @@ internal fun FullScreenRouteMapContent(summary: PhoneSummary, onClose: () -> Uni IconPill(stringResource(R.string.glow_summary_map_fit), { follow = true }, Modifier.align(Alignment.TopCenter)) } IconPill(stringResource(R.string.glow_summary_map_close), onClose, Modifier.align(Alignment.TopEnd)) + if (rows.isNotEmpty()) { + SplitPicker( + rows, + selected, + onSelect = { + selected = it + follow = true + }, + Modifier.align(Alignment.BottomStart).onSizeChanged { pickerHeight = with(density) { it.height.toDp() } }, + ) + } } } } diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt index 9cdd67cb..5ecfb26e 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt @@ -405,6 +405,14 @@ internal fun ZonesList(zones: ZoneSeconds, maxHr: Int, note: String = stringReso } } +/** The Splits list's rows along [route], one per [Route.legs] kilometre shown: the list and the map's picker share them. */ +internal fun splitRowsFor(summary: PhoneSummary, route: List): List = SummaryCopy.splitRows( + Route.splits(route, summary.pauses), + summary.history, + route.firstOrNull()?.t, + summary.distanceMeters?.takeIf { !summary.distanceFromSteps }, +) + /** * Splits for a GPS workout (each kilometre's time and average heart rate), with the laps under them when any were * marked; laps alone without GPS; sets for strength. Nothing without any of them. With [markFastest] the fastest @@ -416,9 +424,7 @@ internal fun SplitsList(summary: PhoneSummary, liveRoute: List, mar val a = summary.analysis val maxHr = a.maxHeartRate val route = summary.route.ifEmpty { liveRoute.filter { it.t in a.shownStart..a.end } } - val rows = remember(route, summary) { SummaryCopy.splitRows( - Route.splits(route, summary.pauses), summary.history, route.firstOrNull()?.t, summary.distanceMeters?.takeIf { !summary.distanceFromSteps }, - ) } + val rows = remember(route, summary) { splitRowsFor(summary, route) } val laps = summary.laps.takeIf { it.size > 1 }.orEmpty() val sets = summary.sets.filter { it.end != null } // Each row's heart takes the zone its average heart rate sat in. diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/KmMarkers.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/KmMarkers.kt new file mode 100644 index 00000000..519c2a5c --- /dev/null +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/KmMarkers.kt @@ -0,0 +1,43 @@ +package org.openstrap.app.ui.glow + +import android.graphics.Bitmap +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Typeface +import org.openstrap.app.data.Route + +/** The marker number's size, and a smaller one so three digits still sit inside the ring. */ +private const val KM_TEXT_DP = 11f +private const val KM_TEXT_3_DIGITS_DP = 8f + +/** Each marker a Point feature whose `icon` names its image, `km-`, added to the style by [WorkoutMap]. */ +internal fun kmMarkerFeatures(markers: List>): String = + markers.joinToString(",", """{"type":"FeatureCollection","features":[""", "]}") { (km, p) -> + """{"type":"Feature","geometry":{"type":"Point","coordinates":[${coord(p)}]},"properties":{"icon":"km-$km"}}""" + } + +/** + * Kilometre [km]'s marker: a 22 dp dark circle, as the start dot, ringed in white, its number in bold white. A bitmap, + * not a map text label, since a label needs a font from the tile host and Route only makes no requests. + */ +internal fun kmMarkerBitmap(km: Int, density: Float): Bitmap { + val size = (22 * density).toInt() + val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888) + val canvas = Canvas(bitmap) + val c = size / 2f + val ring = 2 * density + val paint = Paint(Paint.ANTI_ALIAS_FLAG) + paint.color = 0xFF121316.toInt() + canvas.drawCircle(c, c, c - ring / 2, paint) + paint.style = Paint.Style.STROKE + paint.strokeWidth = ring + paint.color = android.graphics.Color.WHITE + canvas.drawCircle(c, c, c - ring / 2, paint) + paint.style = Paint.Style.FILL + paint.typeface = Typeface.DEFAULT_BOLD + paint.textAlign = Paint.Align.CENTER + val label = km.toString() + paint.textSize = (if (label.length > 2) KM_TEXT_3_DIGITS_DP else KM_TEXT_DP) * density + canvas.drawText(label, c, c - (paint.descent() + paint.ascent()) / 2, paint) + return bitmap +} diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt new file mode 100644 index 00000000..3fa8b36c --- /dev/null +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt @@ -0,0 +1,47 @@ +package org.openstrap.app.ui.glow + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.lazy.itemsIndexed +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.semantics.selected +import androidx.compose.ui.semantics.semantics +import androidx.compose.ui.unit.dp +import org.openstrap.app.ui.components.pressClickable +import org.openstrap.app.ui.theme.ControlSurface +import org.openstrap.app.ui.workout.SplitRow + +/** + * The Splits list's rows as chips along the full-screen map, name over time; the [selected] one lit white. Tapping a + * chip selects it, tapping the selected one clears it ([onSelect] null). + */ +// The rows are remembered once per summary, so a stable list type wouldn't let this skip any more often. +@Suppress("UnstableCollections", "ComposeUnstableCollections") +@Composable +internal fun SplitPicker(rows: List, selected: Int?, onSelect: (Int?) -> Unit, modifier: Modifier = Modifier) { + LazyRow(modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) { + itemsIndexed(rows) { i, row -> + val on = i == selected + val ink = if (on) ControlSurface else Color.White + Column( + Modifier.clip(CircleShape).background(if (on) Color.White else ControlSurface) + .pressClickable({ onSelect(if (on) null else i) }, CircleShape) + .semantics { this.selected = on } + .padding(horizontal = 16.dp, vertical = 6.dp), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Text(row.name, color = ink, style = GlowType.body, maxLines = 1) + Text(row.time, color = ink.copy(alpha = GlowType.SECONDARY_ALPHA), style = GlowType.caption, maxLines = 1) + } + } + } +} diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt index 5dcaca2b..6a76181b 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt @@ -36,6 +36,7 @@ import org.maplibre.android.style.layers.CircleLayer import org.maplibre.android.style.layers.LineLayer import org.maplibre.android.style.layers.Property import org.maplibre.android.style.layers.PropertyFactory +import org.maplibre.android.style.layers.SymbolLayer import org.maplibre.android.style.sources.GeoJsonSource import org.openstrap.app.data.Route import org.openstrap.app.ui.workout.ZONE_COLORS @@ -56,8 +57,11 @@ private const val BLANK_STYLE = """{"version":8,"sources":{},"layers":[{"id":"bg * line's end, ringed in [hereColor] when given; the start is a hollow dot. [routeOnly] loads no map tiles: the tile * server never learns where the map is. While [follow], the camera fits the whole route as it grows inside * [fitPadding] (clear of what's drawn over the map), or centres on the dot until then; a drag on the map calls - * [onPanned], so the caller can stop following. + * [onPanned], so the caller can stop following. [kmMarkers] puts a numbered circle at each kilometre's end; a + * [highlight] of two or more points is drawn with a white casing under the line, and fitted instead of the route. */ +// Callers remember their lists, so a stable list type wouldn't let this skip any more often. +@Suppress("UnstableCollections", "ComposeUnstableCollections") @Composable fun WorkoutMap( stretches: List, Int>>, routeOnly: Boolean, modifier: Modifier = Modifier, here: Route.Point? = null, @@ -67,6 +71,8 @@ fun WorkoutMap( hereColor: Color? = null, follow: Boolean = true, onPanned: () -> Unit = {}, + kmMarkers: List> = emptyList(), + highlight: List = emptyList(), ) { // A preview or a layout test has no native map library: the route only map's black stands in for it. if (LocalInspectionMode.current) { @@ -91,10 +97,7 @@ fun WorkoutMap( m.setMaxZoomPreference(MAX_ZOOM) // MapLibre's licence doesn't ask for its logo; the ⓘ stays, for the OpenStreetMap credit the tiles need. m.uiSettings.isLogoEnabled = false - // In the bottom-right corner, inset to clear the card's rounded edge. - val inset = (18 * context.resources.displayMetrics.density).toInt() m.uiSettings.attributionGravity = android.view.Gravity.BOTTOM or android.view.Gravity.END - m.uiSettings.setAttributionMargins(0, 0, inset, with(density) { creditBottom.roundToPx() }) m.addOnCameraMoveStartedListener { reason -> if (reason == MapLibreMap.OnCameraMoveStartedListener.REASON_API_GESTURE) panned() } @@ -118,6 +121,11 @@ fun WorkoutMap( view.onDestroy() } } + // In the bottom-right corner, inset to clear the card's rounded edge; set again when what's under it changes height. + LaunchedEffect(map, creditBottom) { + val inset = (18 * context.resources.displayMetrics.density).toInt() + map?.uiSettings?.setAttributionMargins(0, 0, inset, with(density) { creditBottom.roundToPx() }) + } LaunchedEffect(map, routeOnly) { val m = map ?: return@LaunchedEffect style = null @@ -126,6 +134,8 @@ fun WorkoutMap( s.addSource(GeoJsonSource(SOURCE, geoJson(emptyList()))) s.addSource(GeoJsonSource(HERE, geoJson(emptyList()))) s.addSource(GeoJsonSource(START, geoJson(emptyList()))) + s.addSource(GeoJsonSource(KM_SRC, geoJson(emptyList()))) + s.addSource(GeoJsonSource(HIGHLIGHT_SRC, geoJson(emptyList()))) s.addLayer( CircleLayer(START_DOT, START).withProperties( PropertyFactory.circleRadius(5f), @@ -142,6 +152,22 @@ fun WorkoutMap( PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND), ), ) + s.addLayerBelow( + LineLayer(HIGHLIGHT_LINE, HIGHLIGHT_SRC).withProperties( + PropertyFactory.lineColor(Color.White.toArgb()), + PropertyFactory.lineWidth(HIGHLIGHT_WIDTH), + PropertyFactory.lineCap(Property.LINE_CAP_ROUND), + PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND), + ), + LINE, + ) + s.addLayer( + SymbolLayer(KM_LAYER, KM_SRC).withProperties( + PropertyFactory.iconImage(Expression.get("icon")), + PropertyFactory.iconAllowOverlap(true), + PropertyFactory.iconIgnorePlacement(true), + ), + ) s.addLayer( CircleLayer(HALO, HERE).withProperties( PropertyFactory.circleRadius(18f), @@ -168,7 +194,12 @@ fun WorkoutMap( ).toTypedArray(), ) } - LaunchedEffect(style, stretches, here, follow) { + // Again for each new style: switching Route only replaces the style, and its images with it. + LaunchedEffect(style, kmMarkers) { style?.showKmMarkers(kmMarkers, density.density) } + LaunchedEffect(style, highlight) { + style?.getSourceAs(HIGHLIGHT_SRC)?.setGeoJson(highlightGeoJson(highlight)) + } + LaunchedEffect(style, stretches, here, follow, highlight) { val s = style ?: return@LaunchedEffect s.getSourceAs(SOURCE)?.setGeoJson(geoJson(stretches)) val last = here ?: stretches.lastOrNull()?.first?.lastOrNull() @@ -176,8 +207,9 @@ fun WorkoutMap( val all = stretches.flatMap { it.first } s.getSourceAs(START)?.setGeoJson(point(all.firstOrNull()?.takeIf { all.size >= 2 })) if (!follow) return@LaunchedEffect - if (all.size >= 2) { - val bounds = LatLngBounds.Builder().includes(all.map { LatLng(it.lat, it.lon) }).build() + val fit = fitTo(highlight, all) + if (fit.size >= 2) { + val bounds = LatLngBounds.Builder().includes(fit.map { LatLng(it.lat, it.lon) }).build() val px = with(density) { listOf(fitPadding.calculateLeftPadding(LayoutDirection.Ltr), fitPadding.calculateTopPadding(), fitPadding.calculateRightPadding(LayoutDirection.Ltr), fitPadding.calculateBottomPadding()).map { it.roundToPx() } } runCatching { map?.easeCamera(CameraUpdateFactory.newLatLngBounds(bounds, px[0], px[1], px[2], px[3])) } } else if (last != null) { @@ -197,13 +229,37 @@ private const val DOT = "here-dot" private const val HALO = "here-halo" private const val START = "start" private const val START_DOT = "start-dot" +private const val KM_SRC = "km" +private const val KM_LAYER = "km-markers" +private const val HIGHLIGHT_SRC = "highlight" +private const val HIGHLIGHT_LINE = "highlight-line" + +/** Twice the route line's width, so the casing shows on both sides of it. */ +private const val HIGHLIGHT_WIDTH = 10f + +/** Each marker's image, then the markers: the style has no images of its own, and a new style drops added ones. */ +private fun Style.showKmMarkers(markers: List>, density: Float) { + markers.forEach { (km, _) -> addImage("km-$km", kmMarkerBitmap(km, density)) } + getSourceAs(KM_SRC)?.setGeoJson(kmMarkerFeatures(markers)) +} /** One point as GeoJSON, or nothing. */ private fun point(p: Route.Point?): String = p?.let { """{"type":"Feature","geometry":{"type":"Point","coordinates":[${coord(it)}]},"properties":{}}""" } ?: """{"type":"FeatureCollection","features":[]}""" -private fun coord(p: Route.Point) = String.format(Locale.ROOT, "%.7f,%.7f", p.lon, p.lat) +internal fun coord(p: Route.Point) = String.format(Locale.ROOT, "%.7f,%.7f", p.lon, p.lat) + +/** What the camera fits: the [highlight] when it can be drawn, else the whole route. */ +private fun fitTo(highlight: List, all: List) = if (highlight.size >= 2) highlight else all + +/** [points] as one LineString feature, or none under two points. */ +internal fun highlightGeoJson(points: List): String = if (points.size < 2) { + """{"type":"FeatureCollection","features":[]}""" +} else { + """{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[""" + + points.joinToString(",") { "[${coord(it)}]" } + "]}}]}" +} /** Each stretch a LineString feature with its zone's colour (grey without heart rate). */ private fun geoJson(stretches: List, Int>>): String = buildString { diff --git a/app/src/test/kotlin/org/openstrap/app/data/RouteTest.kt b/app/src/test/kotlin/org/openstrap/app/data/RouteTest.kt index 6eb73866..fa0e3bce 100644 --- a/app/src/test/kotlin/org/openstrap/app/data/RouteTest.kt +++ b/app/src/test/kotlin/org/openstrap/app/data/RouteTest.kt @@ -74,6 +74,36 @@ class RouteTest { assertTrue(s[2].meters < 1000) } + @Test + fun `legs cut the track at each kilometre`() { + val legs = Route.legs(run(1200)) + assertEquals(4, legs.size) + for (i in 0..2) assertEquals(1000.0, legs[i].points.zipWithNext().sumOf { (a, b) -> Route.meters(a, b) }, 15.0) + for (i in 0 until legs.lastIndex) assertEquals(legs[i].points.last(), legs[i + 1].points.first()) + } + + @Test + fun `legs and splits agree`() { + assertEquals(Route.splits(run(1200)), Route.legs(run(1200)).map { it.split }) + } + + @Test + fun `a run under a kilometre is one part leg`() { + val legs = Route.legs(run(100)) + assertEquals(1, legs.size) + assertTrue(legs[0].split.meters < 1000.0) + } + + @Test + fun `a pause stays out of a leg's metres`() { + val pauses = listOf(500L..600L) + val legs = Route.legs(run(1200), pauses) + val leg = legs.single { it.points.first().t < 550 && it.points.last().t > 550 } + assertEquals(1000.0, leg.split.meters, 15.0) + val whole = Route.legs(run(1200)).sumOf { it.split.meters } + assertEquals(whole - 300.0, legs.sumOf { it.split.meters }, 15.0) + } + @Test fun currentPace() { assertEquals(333.0, Route.currentPace(run(100))!!, 2.0) diff --git a/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt index 44c1d116..c60b68f0 100644 --- a/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt +++ b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt @@ -3,6 +3,8 @@ package org.openstrap.app.ui.glow import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.ui.platform.LocalInspectionMode import androidx.compose.ui.test.assertCountEquals +import androidx.compose.ui.test.assertIsNotSelected +import androidx.compose.ui.test.assertIsSelected import androidx.compose.ui.test.onAllNodesWithText import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithText @@ -32,14 +34,16 @@ class FullScreenRouteMapTest { private val start = 1_792_000_000L - private fun text(id: Int) = ApplicationProvider.getApplicationContext().getString(id) + private val app get() = ApplicationProvider.getApplicationContext() - /** A 3 m/s run east along the equator, a fix a second. */ - private fun summary(): PhoneSummary { - val w = AppWorkout(start, start + 40, 1) - val route = (0..40).map { Route.Point(start + it, 0.0, it * 3.0 / 111_195.0, 5f) } + private fun text(id: Int) = app.getString(id) + + /** A 3 m/s run east along the equator, a fix a second, [seconds] long. */ + private fun summary(seconds: Int = 40): PhoneSummary { + val w = AppWorkout(start, start + seconds, 1) + val route = (0..seconds).map { Route.Point(start + it, 0.0, it * 3.0 / 111_195.0, 5f) } val analysis = WorkoutRecorder.analyse(w, emptyList(), 190, HeartZones.STANDARD) - return PhoneSummary(analysis, emptyList(), start, start + 40, null, route = route) + return PhoneSummary(analysis, emptyList(), start, start + seconds, null, route = route) } private fun show(content: @androidx.compose.runtime.Composable () -> Unit) { @@ -71,4 +75,25 @@ class FullScreenRouteMapTest { rules.compose.onNodeWithContentDescription(text(R.string.glow_summary_map_open)).performClick() assertEquals(1, opened) } + + @Test fun `the picker lists each kilometre and the last part`() { + show { FullScreenRouteMapContent(summary(seconds = 1167)) {} } + for (km in 1..3) rules.compose.onNodeWithText(app.getString(R.string.workout_summary_split_km, km)).assertExists() + val last = text(R.string.workout_summary_split_last).substringBefore('%') + rules.compose.onNodeWithText(last, substring = true).assertExists() + } + + @Test fun `tapping a split selects it and tapping it again clears it`() { + show { FullScreenRouteMapContent(summary(seconds = 1167)) {} } + val km2 = rules.compose.onNodeWithText(app.getString(R.string.workout_summary_split_km, 2)) + km2.performClick() + km2.assertIsSelected() + km2.performClick() + km2.assertIsNotSelected() + } + + @Test fun `a run under a kilometre has no km chips`() { + show { FullScreenRouteMapContent(summary(seconds = 134)) {} } + rules.compose.onAllNodesWithText(app.getString(R.string.workout_summary_split_km, 1)).assertCountEquals(0) + } } diff --git a/app/src/test/kotlin/org/openstrap/app/ui/glow/KmMarkersTest.kt b/app/src/test/kotlin/org/openstrap/app/ui/glow/KmMarkersTest.kt new file mode 100644 index 00000000..8c382127 --- /dev/null +++ b/app/src/test/kotlin/org/openstrap/app/ui/glow/KmMarkersTest.kt @@ -0,0 +1,50 @@ +package org.openstrap.app.ui.glow + +import org.json.JSONObject +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.openstrap.app.data.Route +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.GraphicsMode + +/** The full-screen map's km markers and split highlight, as GeoJSON and bitmaps. */ +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [35]) +@GraphicsMode(GraphicsMode.Mode.NATIVE) +class KmMarkersTest { + private val p1 = Route.Point(0, 1.5, 10.25, 5f) + private val p2 = Route.Point(1, 1.6, 10.35, 5f) + + @Test fun `features carry the km as an icon name`() { + val features = JSONObject(kmMarkerFeatures(listOf(1 to p1, 2 to p2))).getJSONArray("features") + assertEquals(2, features.length()) + assertEquals("km-1", features.getJSONObject(0).getJSONObject("properties").getString("icon")) + assertEquals("km-2", features.getJSONObject(1).getJSONObject("properties").getString("icon")) + val coordinates = features.getJSONObject(0).getJSONObject("geometry").getJSONArray("coordinates") + assertEquals(10.25, coordinates.getDouble(0), 1e-9) + assertEquals(1.5, coordinates.getDouble(1), 1e-9) + } + + @Test fun `a marker bitmap is square, sized by density, and drawn`() { + val b = kmMarkerBitmap(7, 2f) + assertEquals(44, b.width) + assertEquals(44, b.height) + assertNotEquals(0, b.getPixel(22, 22) ushr 24) + } + + @Test fun `three digits still fit`() { + val b = kmMarkerBitmap(123, 2f) + assertEquals(44, b.width) + assertEquals(44, b.height) + } + + @Test fun `highlight needs two points`() { + assertEquals(0, JSONObject(highlightGeoJson(emptyList())).getJSONArray("features").length()) + val one = JSONObject(highlightGeoJson(listOf(p1, p2))).getJSONArray("features") + assertEquals(1, one.length()) + assertEquals("LineString", one.getJSONObject(0).getJSONObject("geometry").getString("type")) + } +} From f2cd5318360f9d7928a3e3f11f32c55f3ad472fb Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 04/22] fix: move splitRowsFor next to the split picker Co-Authored-By: Claude Sonnet 5.5 --- .../org/openstrap/app/ui/glow/GlowWorkoutSummary.kt | 8 -------- .../kotlin/org/openstrap/app/ui/glow/SplitPicker.kt | 11 +++++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt index 5ecfb26e..328b09f3 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/GlowWorkoutSummary.kt @@ -405,14 +405,6 @@ internal fun ZonesList(zones: ZoneSeconds, maxHr: Int, note: String = stringReso } } -/** The Splits list's rows along [route], one per [Route.legs] kilometre shown: the list and the map's picker share them. */ -internal fun splitRowsFor(summary: PhoneSummary, route: List): List = SummaryCopy.splitRows( - Route.splits(route, summary.pauses), - summary.history, - route.firstOrNull()?.t, - summary.distanceMeters?.takeIf { !summary.distanceFromSteps }, -) - /** * Splits for a GPS workout (each kilometre's time and average heart rate), with the laps under them when any were * marked; laps alone without GPS; sets for strength. Nothing without any of them. With [markFastest] the fastest diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt index 3fa8b36c..88a53250 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/SplitPicker.kt @@ -16,9 +16,12 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.semantics.selected import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp +import org.openstrap.app.data.Route import org.openstrap.app.ui.components.pressClickable import org.openstrap.app.ui.theme.ControlSurface +import org.openstrap.app.ui.workout.PhoneSummary import org.openstrap.app.ui.workout.SplitRow +import org.openstrap.app.ui.workout.SummaryCopy /** * The Splits list's rows as chips along the full-screen map, name over time; the [selected] one lit white. Tapping a @@ -45,3 +48,11 @@ internal fun SplitPicker(rows: List, selected: Int?, onSelect: (Int?) } } } + +/** The Splits list's rows along [route], one per [Route.legs] kilometre shown: the list and the map's picker share them. */ +internal fun splitRowsFor(summary: PhoneSummary, route: List): List = SummaryCopy.splitRows( + Route.splits(route, summary.pauses), + summary.history, + route.firstOrNull()?.t, + summary.distanceMeters?.takeIf { !summary.distanceFromSteps }, +) From 871ca0eef8a6863fc07863c7339031cadc2feb5f Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 05/22] test: a run under a kilometre shows only its last-part chip Co-Authored-By: Claude Sonnet 5.5 --- .../org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt index c60b68f0..ad9a9022 100644 --- a/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt +++ b/app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapTest.kt @@ -92,8 +92,13 @@ class FullScreenRouteMapTest { km2.assertIsNotSelected() } - @Test fun `a run under a kilometre has no km chips`() { + @Test fun `a run under a kilometre shows only its last-part chip`() { show { FullScreenRouteMapContent(summary(seconds = 134)) {} } rules.compose.onAllNodesWithText(app.getString(R.string.workout_summary_split_km, 1)).assertCountEquals(0) + val chip = rules.compose.onNodeWithText(text(R.string.workout_summary_split_last).substringBefore('%'), substring = true) + chip.performClick() + chip.assertIsSelected() + chip.performClick() + chip.assertIsNotSelected() } } From 0bff889a6c11bd5d8ccf5970aa69f954d88ede74 Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 06/22] fix: refit the route when the map's padding changes Co-Authored-By: Claude Sonnet 5.5 --- app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt index 6a76181b..495dd9ea 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/WorkoutMap.kt @@ -199,7 +199,7 @@ fun WorkoutMap( LaunchedEffect(style, highlight) { style?.getSourceAs(HIGHLIGHT_SRC)?.setGeoJson(highlightGeoJson(highlight)) } - LaunchedEffect(style, stretches, here, follow, highlight) { + LaunchedEffect(style, stretches, here, follow, highlight, fitPadding) { val s = style ?: return@LaunchedEffect s.getSourceAs(SOURCE)?.setGeoJson(geoJson(stretches)) val last = here ?: stretches.lastOrNull()?.first?.lastOrNull() From 48b7a959947400ea6d5835445d70911da95c7d45 Mon Sep 17 00:00:00 2001 From: Ricardo Ezequiel <106978749+ricaezejo@users.noreply.github.com> Date: Fri, 6 Nov 2026 11:38:03 +0100 Subject: [PATCH 07/22] fix: show the full-screen route map in place so it survives rotation Co-Authored-By: Claude Sonnet 5.5 --- .../app/ui/glow/FullScreenRouteMap.kt | 24 +++-- .../app/ui/glow/GlowWorkoutScreen.kt | 7 +- .../app/ui/glow/GlowWorkoutSummary.kt | 8 +- .../openstrap/app/ui/glow/SummarySections.kt | 9 +- .../ui/glow/FullScreenRouteMapRotationTest.kt | 92 +++++++++++++++++++ 5 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 app/src/test/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMapRotationTest.kt diff --git a/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt index 5bec7385..edaf240e 100644 --- a/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt +++ b/app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt @@ -1,5 +1,6 @@ package org.openstrap.app.ui.glow +import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues @@ -10,6 +11,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawing import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -22,8 +24,6 @@ import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.compose.ui.window.Dialog -import androidx.compose.ui.window.DialogProperties import org.openstrap.app.R import org.openstrap.app.data.Route import org.openstrap.app.ui.dashboard.LocalHeartZones @@ -38,17 +38,23 @@ internal fun rememberZoneStretches(summary: PhoneSummary): List