Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/
app/.DS_Store
gradle/.DS_Store
.DS_Store
.kotlin/
13 changes: 9 additions & 4 deletions app/src/main/java/com/pulseloop/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class MainActivity : ComponentActivity() {

CoachNotifications.createChannel(this)
com.pulseloop.notifications.BatteryNotifications.createChannel(this)
requestAllPermissions()
// Ask once per launch, not on every resume: a dismissed dialog resumes the activity, and
// re-asking from onResume reopened the same prompt straight away.
if (savedInstanceState == null) requestAllPermissions()

setContent {
// GMind brand frame: a 4dp mint border round the app, drawn inside the system bars
Expand All @@ -100,8 +102,7 @@ class MainActivity : ComponentActivity() {

override fun onResume() {
super.onResume()
// Re-request on resume in case user granted in Settings
requestAllPermissions()
// Only re-check here, in case the user granted from system Settings while away.
if (hasAllBlePermissions() && hasNotificationPermission()) {
CoachNotifications.schedule(this)
}
Expand Down Expand Up @@ -221,7 +222,11 @@ class MainActivity : ComponentActivity() {
val missing = mutableListOf<String>()

// BLE / Location — GPS tracking needs location on all API levels
if (!hasFineLocation()) missing.add(Manifest.permission.ACCESS_FINE_LOCATION)
// Android 12+ ignores a fine-only request; coarse has to be asked for alongside it.
if (!hasFineLocation()) {
missing.add(Manifest.permission.ACCESS_FINE_LOCATION)
missing.add(Manifest.permission.ACCESS_COARSE_LOCATION)
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (!hasBleScan()) missing.add(Manifest.permission.BLUETOOTH_SCAN)
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/pulseloop/service/LiveWorkoutManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ class LiveWorkoutManager(
refreshNotification()
}

// UI entry points for the record screen's buttons. They run on this manager's own scope, which
// outlives the screen: finishing pops the record route, and a screen-scoped launch was cancelled
// mid Strava upload. A tap landing while the previous one is still writing is dropped, so a
// double tap on Finish can't credit the workout twice. Main-confined, so the flag needs no lock.
private var uiActionInFlight = false

fun pauseFromUi(session: ActivitySessionEntity) = launchUiAction { pause(session) }
fun resumeFromUi(session: ActivitySessionEntity) = launchUiAction { resume(session) }
fun finishFromUi(session: ActivitySessionEntity) = launchUiAction { finish(session) }

private fun launchUiAction(action: suspend () -> Unit) {
if (uiActionInFlight) return
uiActionInFlight = true
scope.launch {
try { action() } finally { uiActionInFlight = false }
}
}

suspend fun finish(session: ActivitySessionEntity) {
gps.stop()
polling.stop()
Expand Down
48 changes: 23 additions & 25 deletions app/src/main/java/com/pulseloop/ui/PulseLoopApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -375,19 +379,6 @@ fun PulseLoopApp() {
val navBackStackEntry by navController.currentBackStackEntryAsState()
val route = navBackStackEntry?.destination?.route
val onTabRoute = route in tabRoutes
if (onTabRoute && isLandscape) {
// Edge-to-edge draws content under the transparent status bar. In landscape the
// tabs render no full header, so without a backdrop scrolled content (chat
// bubbles, charts) bleeds through the status bar. Keep a status-bar-height glass
// strip so the status bar stays legible on every tab — matching the landscape
// bottom bar's glass — while content still scrolls under it.
Box(
Modifier
.fillMaxWidth()
.hazeEffect(state = hazeState, style = glassStyle)
.windowInsetsPadding(WindowInsets.statusBars),
)
}
if (onTabRoute && !isLandscape) {
Column(
Modifier
Expand Down Expand Up @@ -430,7 +421,9 @@ fun PulseLoopApp() {
}
} else {
val ble by bleClient.state.collectAsState()
val storedDevice by db.deviceDao().currentFlow()
// remember the Flow: this lambda recomposes on every BLE state change, and a
// fresh Flow resubscribes from `null`, blinking the pill.
val storedDevice by remember(db) { db.deviceDao().currentFlow() }
.collectAsState(initial = null)
// Prefer live BLE state; fall back to the stored device so demo data
// shows its ring instead of a permanently blank pill (RootViews.swift).
Expand Down Expand Up @@ -491,7 +484,13 @@ fun PulseLoopApp() {
) {
tabs.forEach { tab ->
val selected = isSelected(tab)
IconButton(onClick = { onTab(tab) }) {
IconButton(
onClick = { onTab(tab) },
modifier = Modifier.semantics {
this.selected = selected
role = Role.Tab
},
) {
Icon(
if (selected) tab.selectedIcon else tab.unselectedIcon,
contentDescription = tab.label,
Expand All @@ -515,7 +514,8 @@ fun PulseLoopApp() {
icon = {
Icon(
if (selected) tab.selectedIcon else tab.unselectedIcon,
contentDescription = tab.label,
// The item's label already names the tab.
contentDescription = null,
)
},
label = { Text(tab.label) },
Expand Down Expand Up @@ -744,19 +744,17 @@ fun PulseLoopApp() {
hrZone = workoutState.hrZone,
units = apiKeyStore.resolvedUnitSystem,
onPause = {
workoutState.activeSession?.let { kotlinx.coroutines.runBlocking { liveWorkout.pause(it) } }
workoutState.activeSession?.let { liveWorkout.pauseFromUi(it) }
},
onResume = {
workoutState.activeSession?.let { kotlinx.coroutines.runBlocking { liveWorkout.resume(it) } }
workoutState.activeSession?.let { liveWorkout.resumeFromUi(it) }
},
onFinish = {
workoutState.activeSession?.let {
kotlinx.coroutines.runBlocking { liveWorkout.finish(it) }
// Land on the summary (iOS RecordSummaryView), replacing the live screen.
navController.navigate("activity_detail/${it.id}") {
popUpTo("record") { inclusive = true }
}
}
// No runBlocking on the main thread. The finishedSessionId effect above lands
// on the summary (iOS RecordSummaryView) once the finish is written; with no
// session there is nothing to finish, so just leave.
workoutState.activeSession?.let { liveWorkout.finishFromUi(it) }
?: navController.popBackStack()
},
)
}
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/java/com/pulseloop/ui/components/A11y.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pulseloop.ui.components

import android.provider.Settings
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.selection.toggleable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp

/**
* Makes a label + [androidx.compose.material3.Switch] row one control: the whole row toggles, and
* TalkBack reads the label with the state ("Athlete mode, off, switch") instead of a bare
* "off, switch". Give the row's Switch `onCheckedChange = null` so it is only the indicator.
*/
fun Modifier.switchRow(
checked: Boolean,
enabled: Boolean = true,
onCheckedChange: (Boolean) -> Unit,
): Modifier = heightIn(min = 48.dp).toggleable(
value = checked,
enabled = enabled,
role = Role.Switch,
onValueChange = onCheckedChange,
)

/**
* True when the user turned animations off (Settings › Accessibility › Remove animations, which
* sets the animator duration scale to 0). Looping decoration should hold still then.
*/
@Composable
fun rememberReduceMotion(): Boolean {
val resolver = LocalContext.current.contentResolver
return remember(resolver) {
Settings.Global.getFloat(resolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f
}
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/pulseloop/ui/components/ActivityRings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

Expand Down Expand Up @@ -48,8 +50,15 @@ fun ActivityRings(
/** Gap between concentric rings. */
ringSpacing: Dp = 5.dp,
trackColor: Color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.10f),
/** Spoken name per ring, in [rings] order (e.g. "steps"); unnamed rings read as "ring N". */
labels: List<String> = emptyList(),
) {
Canvas(modifier.size(size)) {
// Drawn arcs say nothing to TalkBack; speak each ring's share of its goal instead.
val description = "Goal progress: " + rings.mapIndexed { i, ring ->
val name = labels.getOrNull(i) ?: "ring ${i + 1}"
if (ring.value == null) "$name unavailable" else "$name ${(ring.progress * 100).toInt()}%"
}.joinToString(", ")
Canvas(modifier.size(size).clearAndSetSemantics { contentDescription = description }) {
val strokePx = strokeWidth.toPx()
val spacingPx = ringSpacing.toPx()
val stroke = Stroke(width = strokePx, cap = StrokeCap.Round)
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/java/com/pulseloop/ui/components/AppChrome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -73,7 +74,11 @@ fun AppHeader(
state = state,
batteryPercent = batteryPercent,
idle = idle,
modifier = Modifier.clickable(onClick = onOpenSettings),
modifier = Modifier.clickable(
onClickLabel = "Open ring settings",
role = Role.Button,
onClick = onOpenSettings,
),
)
IconButton(onClick = onOpenSettings) {
Icon(Icons.Outlined.Settings, "Settings", tint = PulseColors.textSecondary)
Expand All @@ -95,7 +100,9 @@ fun ConnectionStatusPill(
idle: Boolean = false,
) {
val idleNow = idle && state == RingConnectionState.DISCONNECTED
val isPulsing = state == RingConnectionState.CONNECTING || state == RingConnectionState.RECONNECTING
// Holds still under "Remove animations"; the label already says "Connecting…".
val isPulsing = (state == RingConnectionState.CONNECTING || state == RingConnectionState.RECONNECTING) &&
!rememberReduceMotion()
val dotColor = when (state) {
RingConnectionState.CONNECTED -> PulseColors.success
RingConnectionState.CONNECTING, RingConnectionState.RECONNECTING -> PulseColors.accent
Expand All @@ -110,12 +117,15 @@ fun ConnectionStatusPill(
if (batteryPercent != null && batteryPercent > 0) "Idle · $batteryPercent%" else "Idle"
} else "Disconnected"
}
val pulse by rememberInfiniteTransition(label = "pill").animateFloat(
initialValue = 1f,
targetValue = if (isPulsing) 0.35f else 1f,
animationSpec = infiniteRepeatable(tween(800), RepeatMode.Reverse),
label = "pillDot",
)
// Only run the transition while pulsing: an infinite 1f→1f animation still ticks every frame.
val pulse = if (isPulsing) {
rememberInfiniteTransition(label = "pill").animateFloat(
initialValue = 1f,
targetValue = 0.35f,
animationSpec = infiniteRepeatable(tween(800), RepeatMode.Reverse),
label = "pillDot",
).value
} else 1f

Row(
modifier = modifier
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/pulseloop/ui/components/Charts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.graphics.drawscope.clipRect
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.drawText
import androidx.compose.ui.text.font.FontWeight
Expand Down Expand Up @@ -261,6 +263,8 @@ fun TrendChart(
/** The user's own usual range, shaded behind the line (service/UsualRange). */
usualRange: ClosedFloatingPointRange<Double>? = null,
usualColor: Color = color,
/** Spoken name for the chart's TalkBack summary (e.g. "Heart Rate"). */
title: String? = null,
) {
if (points.isEmpty()) return

Expand Down Expand Up @@ -302,6 +306,12 @@ fun TrendChart(
var scrubX by remember(points) { mutableStateOf<Float?>(null) }
var plotLeftPx by remember { mutableStateOf(0f) }
var plotRightPx by remember { mutableStateOf(0f) }
// TalkBack can't scrub; give it the shape of the data in one sentence instead.
val summary = remember(points, secondary, title) {
fun v(i: Int) = valueFormatter(points[i]) + (secondary.getOrNull(i)?.let { "/" + valueFormatter(it) } ?: "")
"${title ?: "Chart"}: latest ${v(points.lastIndex)}, " +
"range ${valueFormatter(points.min())}–${valueFormatter(points.max())}, ${points.size} readings"
}

Column(modifier = modifier) {
// Legend row (for dual-series)
Expand All @@ -315,7 +325,7 @@ fun TrendChart(
}
}

val canvasModifier = Modifier.fillMaxWidth().height(220.dp).let { base ->
val canvasModifier = Modifier.fillMaxWidth().height(220.dp).semantics { contentDescription = summary }.let { base ->
if (!interactive) base else base.pointerInput(points) {
awaitEachGesture {
val first = awaitFirstDown(requireUnconsumed = false)
Expand Down Expand Up @@ -420,7 +430,7 @@ fun TrendChart(
return best
}

val labelStyle = TextStyle(fontSize = 10.sp, color = axisColor)
val labelStyle = TextStyle(fontSize = 11.sp, color = axisColor)

// No zone-band background: the iOS detail chart plots on a clean card, with the
// zone-split line + the REFERENCE ZONES card carrying the range context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -79,7 +80,7 @@ fun DeviceHeroCard(
Row(
Modifier
.fillMaxWidth()
.clickable(onClick = onOpenWearable),
.clickable(onClickLabel = "Open ring settings", role = Role.Button, onClick = onOpenWearable),
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
RingArtView(
Expand Down Expand Up @@ -145,7 +146,7 @@ fun DeviceHeroCard(
}
Icon(
Icons.AutoMirrored.Filled.KeyboardArrowRight,
contentDescription = "Opens ring settings",
contentDescription = null, // the row's click label says it
modifier = Modifier.size(20.dp),
tint = PulseColors.textMuted,
)
Expand All @@ -162,10 +163,10 @@ fun DeviceHeroCard(
fontWeight = FontWeight.SemiBold,
color = if (status.actionEnabled) PulseColors.accent else PulseColors.textMuted,
modifier = Modifier
.heightIn(min = 44.dp)
.heightIn(min = 48.dp)
.clip(CircleShape)
.then(if (status.actionEnabled) Modifier.dither(PulseColors.accent, 0.18f) else Modifier.background(PulseColors.elevated))
.clickable(enabled = status.actionEnabled) {
.clickable(enabled = status.actionEnabled, role = Role.Button) {
when (status.action) {
DeviceHeroStatus.Action.CONNECT -> onConnect()
DeviceHeroStatus.Action.SET_UP -> onSetUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.foundation.layout.heightIn
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
Expand Down Expand Up @@ -50,7 +51,7 @@ fun PrimaryButton(
Button(
onClick = onClick,
enabled = enabled,
modifier = modifier.fillMaxWidth().height(52.dp),
modifier = modifier.fillMaxWidth().heightIn(min = 52.dp),
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
containerColor = PulseColors.accent,
Expand Down Expand Up @@ -79,7 +80,7 @@ fun SecondaryButton(
enabled = enabled,
modifier = modifier
.fillMaxWidth()
.height(52.dp)
.heightIn(min = 52.dp)
.border(1.dp, PulseColors.borderSubtle, RoundedCornerShape(8.dp)),
shape = RoundedCornerShape(8.dp),
colors = ButtonDefaults.buttonColors(
Expand Down
Loading
Loading