Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ad6ea55
feat: open the route map full screen from a workout's summary
ricaezejo Nov 6, 2026
fae8f49
fix: route card taps open the full-screen map over the live map
ricaezejo Nov 6, 2026
6719a56
feat: km markers and split highlight on the full-screen route map
ricaezejo Nov 6, 2026
f2cd531
fix: move splitRowsFor next to the split picker
ricaezejo Nov 6, 2026
871ca0e
test: a run under a kilometre shows only its last-part chip
ricaezejo Nov 6, 2026
0bff889
fix: refit the route when the map's padding changes
ricaezejo Nov 6, 2026
48b7a95
fix: show the full-screen route map in place so it survives rotation
ricaezejo Nov 6, 2026
cb65e35
refactor: drop the imports the in-place map left unused
ricaezejo Nov 6, 2026
b1ef59b
test: the in-place map gives the tab bar back when it closes
ricaezejo Nov 6, 2026
057a2c5
fix: show the route map in a dialog again, with its state kept by the…
ricaezejo Nov 6, 2026
e5503a5
fix: keep the route map's state in a ViewModel so it survives the por…
ricaezejo Nov 6, 2026
f46d86d
test: make the route map harness's ViewModel dependency explicit
ricaezejo Nov 6, 2026
f1e08ae
style: wrap the route map line past detekt's length limit
ricaezejo Nov 13, 2026
64163b7
fix: translate the full-screen route map's strings into Chinese
ricaezejo Nov 13, 2026
a4bd68d
fix: draw the km marker bitmap with the KTX createBitmap
ricaezejo Nov 13, 2026
c5bb630
feat: write a workout's route as GPX with heart rate
ricaezejo Nov 6, 2026
1276cb9
fix: leave fixes recorded during a pause out of the GPX
ricaezejo Nov 6, 2026
5181d3b
feat: export a workout's route as GPX from the summary
ricaezejo Nov 6, 2026
aa1eff4
fix: baseline the GPX export's IO dispatcher like the share card's
ricaezejo Nov 6, 2026
edbe8db
fix: name the GPX export after unstrap
ricaezejo Nov 9, 2026
dea5823
fix: translate the GPX export's strings into Chinese
ricaezejo Nov 13, 2026
0e730a5
fix: keep only the latest GPX export in the share cache, and name uns…
ricaezejo Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/detekt-baseline-debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<ID>InjectDispatcher:RewardsKeeper.kt:RewardsKeeper$IO</ID>
<ID>InjectDispatcher:ShareScreen.kt:IO</ID>
<ID>InjectDispatcher:StrapService.kt:StrapService$Default</ID>
<ID>InjectDispatcher:SummarySections.kt:IO</ID>
<ID>InjectDispatcher:ZeppCloud.kt:ZeppCloud$IO</ID>
<ID>LambdaParameterEventTrailing:ActivityDetail.kt:onPick: (Int?) -&gt; Unit</ID>
<ID>LambdaParameterEventTrailing:ChooseScreen.kt:onChange: (String) -&gt; Unit</ID>
Expand Down
1 change: 1 addition & 0 deletions app/detekt-baseline-release.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<ID>InjectDispatcher:RewardsKeeper.kt:RewardsKeeper$IO</ID>
<ID>InjectDispatcher:ShareScreen.kt:IO</ID>
<ID>InjectDispatcher:StrapService.kt:StrapService$Default</ID>
<ID>InjectDispatcher:SummarySections.kt:IO</ID>
<ID>InjectDispatcher:ZeppCloud.kt:ZeppCloud$IO</ID>
<ID>LambdaParameterEventTrailing:ActivityDetail.kt:onPick: (Int?) -&gt; Unit</ID>
<ID>LambdaParameterEventTrailing:ChooseScreen.kt:onChange: (String) -&gt; Unit</ID>
Expand Down
23 changes: 16 additions & 7 deletions app/src/main/kotlin/org/openstrap/app/data/Route.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point>, pauses: List<LongRange> = emptyList(), km: Double = 1000.0): List<Split> {
fun splits(points: List<Point>, pauses: List<LongRange> = emptyList(), km: Double = 1000.0): List<Split> =
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<Point>)

/** The kilometres of [splits], each with its stretch of the smoothed track; paused stretches are left out. */
fun legs(points: List<Point>, pauses: List<LongRange> = emptyList(), km: Double = 1000.0): List<Leg> {
val clean = track(points)
val out = mutableListOf<Split>()
var startT = clean.firstOrNull()?.t ?: return out
val out = mutableListOf<Leg>()
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
}

Expand Down Expand Up @@ -408,5 +417,5 @@ object Route {
return out.filter { it.first.size >= 2 }
}

private const val MAX_HR_GAP_S = 30L
const val MAX_HR_GAP_S = 30L
}
36 changes: 36 additions & 0 deletions app/src/main/kotlin/org/openstrap/app/export/GpxShare.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.openstrap.app.export

import android.content.ClipData
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.core.content.FileProvider
import java.io.File

private const val TAG = "GpxShare"

// The FileProvider's authority after the package name, as in the manifest; export/ may not reach ui/ for StoryFiles's copy.
private const val AUTHORITY_SUFFIX = ".share"

/** A workout's GPX as a cached file another app can read for a moment, through the share FileProvider. */
internal object GpxShare {
/** Named like the story picture: after the workout's start (epoch seconds). */
fun fileName(workoutStart: Long) = "unstrap_$workoutStart.gpx"

/** [gpx] written to [fileName] in the share cache, replacing earlier exports; null when it can't be written. Blocks. */
fun forSharing(context: Context, fileName: String, gpx: String): Uri? = runCatching {
val dir = File(context.cacheDir, "share").apply { mkdirs() }
dir.listFiles { f -> f.extension == "gpx" }?.forEach { it.delete() }
val file = File(dir, fileName)
file.writeText(gpx)
FileProvider.getUriForFile(context, context.packageName + AUTHORITY_SUFFIX, file)
}.onFailure { Log.w(TAG, "writing the route to share failed", it) }.getOrNull()

/** Opens the share sheet for [uri]. */
fun send(context: Context, uri: Uri) {
val send = Intent(Intent.ACTION_SEND).setType("application/gpx+xml").putExtra(Intent.EXTRA_STREAM, uri)
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION).also { it.clipData = ClipData.newRawUri(null, uri) }
context.startActivity(Intent.createChooser(send, null))
}
}
61 changes: 61 additions & 0 deletions app/src/main/kotlin/org/openstrap/app/export/GpxWriter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.openstrap.app.export

import org.openstrap.app.data.Route
import java.time.Instant
import java.util.Locale
import kotlin.math.abs

/** A workout's route as GPX 1.1 with Garmin's heart-rate extension, for sharing to other apps. */
object GpxWriter {
/**
* [points] go through [Route.track], the line the map draws; a pause starts a new segment. [heartRate] is (epoch
* seconds, bpm) ascending. `ele` is GPS altitude as recorded (WGS84 ellipsoid, not sea level); Strava and similar
* services re-derive elevation.
*/
fun write(name: String, points: List<Route.Point>, heartRate: List<Pair<Long, Int>>, pauses: List<LongRange> = emptyList()): String {
val times = heartRate.map { it.first }
fun hrAt(t: Long): Int? {
val i = times.binarySearch(t).let { if (it < 0) -it - 1 else it }
val near = listOf(i - 1, i).filter { it in heartRate.indices }
.minByOrNull { abs(heartRate[it].first - t) } ?: return null
return heartRate[near].takeIf { abs(it.first - t) <= Route.MAX_HR_GAP_S }?.second
}
val sb = StringBuilder()
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
sb.append("<gpx version=\"1.1\" creator=\"unstrap\" xmlns=\"http://www.topografix.com/GPX/1/1\" ")
sb.append("xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\">\n")
sb.append("<trk><name>").append(escape(name)).append("</name>\n")
// Fixes strictly inside a pause are left out, so no line runs through it; a pause ends a segment.
var prev: Route.Point? = null
var gap = false
Route.track(points).forEach { p ->
if (pauses.any { p.t > it.first && p.t < it.last }) {
gap = true
return@forEach
}
val last = prev
val pausedBetween = last != null && pauses.any { it.first < p.t && it.last > last.t }
if (last == null || gap || pausedBetween) {
if (last != null) sb.append("</trkseg>\n")
sb.append("<trkseg>\n")
}
prev = p
gap = false
sb.append("<trkpt lat=\"").append(coord(p.lat)).append("\" lon=\"").append(coord(p.lon)).append("\">")
p.altitude?.let { sb.append("<ele>").append(String.format(Locale.ROOT, "%.1f", it)).append("</ele>") }
sb.append("<time>").append(Instant.ofEpochSecond(p.t)).append("</time>")
hrAt(p.t)?.let {
sb.append("<extensions><gpxtpx:TrackPointExtension><gpxtpx:hr>").append(it)
sb.append("</gpxtpx:hr></gpxtpx:TrackPointExtension></extensions>")
}
sb.append("</trkpt>\n")
}
if (prev != null) sb.append("</trkseg>\n")
sb.append("</trk>\n</gpx>\n")
return sb.toString()
}

private fun coord(v: Double) = String.format(Locale.ROOT, "%.7f", v)

private fun escape(s: String) = s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")
}
112 changes: 112 additions & 0 deletions app/src/main/kotlin/org/openstrap/app/ui/glow/FullScreenRouteMap.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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.asPaddingValues
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.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
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.platform.LocalView
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 androidx.compose.ui.window.DialogWindowProvider
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<Pair<List<Route.Point>, 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 rail, the panes and the bars; Back or [onClose] closes it. */
@Composable
internal fun FullScreenRouteMap(summary: PhoneSummary, model: RouteMapModel, onClose: () -> Unit) {
Dialog(
onDismissRequest = onClose,
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
) {
NoWindowAnimation()
FullScreenRouteMapContent(summary, model, onClose)
}
}

/** A rotation builds the dialog again, so its window's entrance animation would show the map popping open once more. */
@Composable
private fun NoWindowAnimation() {
val window = (LocalView.current.parent as? DialogWindowProvider)?.window
SideEffect { window?.setWindowAnimations(-1) }
}

/**
* The map and its pills: 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. 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, model: RouteMapModel, onClose: () -> Unit) {
val stretches = rememberZoneStretches(summary)
val routeOnly = model.routeOnly
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) }
val selected = model.selected
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(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
IconPill(stringResource(routeOnlyLabel), { model.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))
if (rows.isNotEmpty()) {
SplitPicker(
rows,
selected,
onSelect = {
model.selected = it
follow = true
},
Modifier.align(Alignment.BottomStart).onSizeChanged { pickerHeight = with(density) { it.height.toDp() } },
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import org.openstrap.app.presentation.Ranges
import androidx.activity.compose.BackHandler
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -175,12 +176,14 @@ private fun PastSummary(
dayActiveKcal: Float?,
onOpenDay: (() -> Unit)?,
foundTag: Boolean,
routeMap: RouteMapModel = viewModel(),
) {
val heartZones = LocalHeartZones.current
val a = summary.analysis
val w = a.workout
val list = rememberLazyListState()
var info by rememberSaveable { mutableStateOf(false) }
if (routeMap.isOpen(w.start)) FullScreenRouteMap(summary, routeMap) { routeMap.close() }
val others = remember(workouts, w.start) { workouts.filter { it.workout.start != w.start }.sortedByDescending { it.workout.start } }
val usual = remember(others) { Workouts.usualLoad(others.map { it.workout.trainingLoad }) }
val family = org.openstrap.app.ui.workout.FamilySummary.familyOf(w.sportType, summary.structure)
Expand Down Expand Up @@ -210,7 +213,10 @@ private fun PastSummary(
else SummaryHero(h.value, h.unit, h.figures, WorkoutDetailCopy.sentence(w.sportType, a.activeSeconds, w.trainingLoad, usual, zones.toList()), h.line)
}
SummaryHeroCard(hero, mainZoneColor(zones, familyColor(family)), Workouts.effort(w.trainingLoad, usual))
FamilySection(family, summary, emptyList(), others, weekStarts, heartLine = false)
FamilySection(
family, summary, emptyList(), others, weekStarts, heartLine = false,
onOpenMap = { routeMap.open(w.start) },
)
// Always there, even before any heart rate, since it holds Trim.
HeartRateCard(a, trim)
val facts = WorkoutDetailCopy.facts(
Expand Down
Loading