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
21 changes: 21 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,3 +1033,24 @@ and each one fails silently if broken:
writing next month would then echo.

It is exclusive with a paired ring: a `DeviceIdentified` turns it off.

## Every UI string goes through `tr()`, and the English text is the key

**The app speaks English and Brazilian Portuguese (Settings → Language, `ui/i18n/L10n.kt`).** There
are no string resources for UI text: a composable writes `Text(tr("Save"))`, and `tr` looks the
English up in `assets/i18n/pt-BR.json`, falling back to the English when there is no entry. So:

- **New UI text: wrap it in `tr()` and add the pt-BR entry to the catalog in the same change.** An
unwrapped string, or a wrapped one with no entry, silently stays English for Portuguese users.
Rewording an English string orphans its translation the same way; update the key too.
- **Translate where text is shown, never where a value is defined.** A literal that is also
*compared* (`zone.label == "High"`, a `when` over labels) must stay English; wrap the display site
instead (`Text(tr(zone.label))`). `MetricThresholds` and `HeartRateZones` labels work this way.
- **Not inside an enum constructor or an object-level `val`:** those evaluate once, so a language
change wouldn't show until the process restarts. Use a getter (`val label get() = tr(en)`).
- **Never date patterns or format keys.** `tr("EEE d MMM")` would let a translation break parsing.
Dates already localise through the default `Locale`, which `L10n` sets.
- A string built by a template (`"Day $n"`) can't be a key. Split it into a translated part and the
value, or leave it English. Many still are; templates and service-layer text (insights,
notifications) are the known gaps.
- The coach answers in the app's language through `L10n.coachInstruction()`, appended to its prompts.
1,025 changes: 1,025 additions & 0 deletions app/src/main/assets/i18n/pt-BR.json

Large diffs are not rendered by default.

39 changes: 30 additions & 9 deletions app/src/main/java/com/pulseloop/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -42,6 +44,11 @@ import kotlinx.coroutines.launch
*/
class MainActivity : ComponentActivity() {

// Settings → Language: Android resources and system UI follow the app's language.
override fun attachBaseContext(newBase: android.content.Context) {
super.attachBaseContext(com.pulseloop.ui.i18n.L10n.wrap(newBase))
}

// Request multiple permissions at once on Android 12+
private val blePermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
Expand Down Expand Up @@ -82,15 +89,29 @@ class MainActivity : ComponentActivity() {
// (under the status bar, above the navigation bar) rather than at the window edge, where
// the bars covered it. The bars' insets are consumed here, so nothing inside pads for
// them a second time.
Box(
Modifier
.fillMaxSize()
.background(PulseColors.background)
.windowInsetsPadding(WindowInsets.systemBars.union(WindowInsets.displayCutout))
.border(4.dp, PulseColors.frame)
.padding(4.dp),
) {
PulseLoopApp()
// Tatá's Easter egg (ui/theme/FairyMode.kt): the profile's name decides the palette.
val profile by androidx.compose.runtime.remember {
com.pulseloop.data.PulseLoopDatabase.getInstance(applicationContext).userProfileDao().getFlow()
}.collectAsState(initial = null)
androidx.compose.runtime.LaunchedEffect(profile?.name) {
if (profile != null) com.pulseloop.ui.theme.FairyMode.onProfileName(profile?.name)
}
// The frame flows from mint to pink rather than snapping.
val frame by androidx.compose.animation.animateColorAsState(
PulseColors.frame, androidx.compose.animation.core.tween(1200), label = "frame",
)
Box(Modifier.fillMaxSize()) {
Box(
Modifier
.fillMaxSize()
.background(PulseColors.background)
.windowInsetsPadding(WindowInsets.systemBars.union(WindowInsets.displayCutout))
.border(4.dp, frame)
.padding(4.dp),
) {
PulseLoopApp()
}
com.pulseloop.ui.components.FairyTransformOverlay()
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/pulseloop/PulseLoopApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class PulseLoopApplication : Application() {
super.onCreate()
CrashLogger.install(this)
com.pulseloop.service.DrinkPrefs.init(this)
com.pulseloop.ui.theme.FairyMode.init(this)
com.pulseloop.ui.i18n.L10n.init(this)
com.pulseloop.health.source.HealthConnectSource.isEnabled(this) // warms [HealthConnectSource.enabledNow]
// Application-scoped so capture runs whether or not the Debug screen is open.
DiagnosticsSubscriber(PulseLoopDatabase.getInstance(this)).start(appScope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ package com.pulseloop.coach.context
* System + developer prompts for the coach.
*/
object CoachPromptBuilder {
val systemPrompt = """
/** The prompt, plus "reply in Portuguese" while the app is in Portuguese (Settings → Language). */
val systemPrompt: String get() = baseSystemPrompt + com.pulseloop.ui.i18n.L10n.coachInstruction()

private val baseSystemPrompt = """
You are PulseLoop Coach, a transparent, evidence-grounded health and fitness coach for a smart-ring app.

You help users understand their own ring data: steps, distance, calories, active minutes, heart rate, SpO2, sleep duration, and sleep stages. You can also set goals, log corrections, take measurements, save notes, run simple analyses, and generate charts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object CoachSummaryGenerator {
if (!flags.coachEnabled || apiKey.isBlank()) return@withContext fallback
try {
val input = JsonArray(listOf(
message("system", CoachSummaryPromptBuilder.systemPrompt(kind)),
message("system", CoachSummaryPromptBuilder.systemPrompt(kind) + com.pulseloop.ui.i18n.L10n.coachInstruction()),
message("developer", CoachSummaryPromptBuilder.developerMessage(contextJSON, angle, recentTexts)),
))
val textFormat = JsonObject(mapOf(
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/pulseloop/data/dao/Daos.kt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ interface UserProfileDao {
@Query("SELECT * FROM user_profiles LIMIT 1")
suspend fun get(): UserProfileEntity?

@Query("SELECT * FROM user_profiles LIMIT 1")
fun getFlow(): kotlinx.coroutines.flow.Flow<UserProfileEntity?>

@Upsert
suspend fun upsert(profile: UserProfileEntity)
}
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/com/pulseloop/ui/PulseLoopApp.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui

import com.pulseloop.ui.i18n.tr

import android.content.res.Configuration
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -318,11 +320,11 @@ fun PulseLoopApp() {
}

val tabs = listOf(
Tab("today", "Today", Icons.Filled.Adjust, Icons.Outlined.Adjust),
Tab("vitals", "Vitals", Icons.Filled.Favorite, Icons.Outlined.FavoriteBorder),
Tab("activity", "Activity", Icons.Filled.MonitorHeart, Icons.Outlined.MonitorHeart),
Tab("sleep", "Sleep", Icons.Filled.Bedtime, Icons.Outlined.Bedtime),
Tab("coach", "Coach", Icons.Filled.AutoAwesome, Icons.Outlined.AutoAwesome),
Tab("today", tr("Today"), Icons.Filled.Adjust, Icons.Outlined.Adjust),
Tab("vitals", tr("Vitals"), Icons.Filled.Favorite, Icons.Outlined.FavoriteBorder),
Tab("activity", tr("Activity"), Icons.Filled.MonitorHeart, Icons.Outlined.MonitorHeart),
Tab("sleep", tr("Sleep"), Icons.Filled.Bedtime, Icons.Outlined.Bedtime),
Tab("coach", tr("Coach"), Icons.Filled.AutoAwesome, Icons.Outlined.AutoAwesome),
)

// ── Self-update: release-only. Checked on every return to foreground (ON_START also
Expand Down Expand Up @@ -445,7 +447,7 @@ fun PulseLoopApp() {
batteryPercent = ble.batteryPercent ?: storedDevice?.batteryPercent,
onOpenSettings = { navController.navigate("settings") },
idle = ble.idleSince != null,
sourceLabel = hcSource?.let { com.pulseloop.health.source.HealthConnectSource.label(context, it) + " · Health Connect" },
sourceLabel = hcSource?.let { com.pulseloop.health.source.HealthConnectSource.label(context, it) + tr(" · Health Connect") },
)
// Thin sync-progress accent under the greeting while history streams in.
val syncPct = coordinator.syncProgress.collectAsState().value
Expand Down Expand Up @@ -668,6 +670,9 @@ fun PulseLoopApp() {
onCoach = discussMeal,
)
}
paddedComposable("settings/language") {
LanguageSettingsScreen(onBack = { navController.popBackStack() })
}
paddedComposable("settings/about") {
AboutSettingsScreen(
onOpenDebug = { navController.navigate("debug") },
Expand Down Expand Up @@ -759,7 +764,7 @@ fun PulseLoopApp() {
}
}
RecordScreen(
activityName = workoutState.activeSession?.type ?: "Workout",
activityName = workoutState.activeSession?.type ?: tr("Workout"),
elapsedSeconds = workoutState.elapsedSeconds,
distanceMeters = workoutState.distanceMeters,
heartRate = workoutState.latestHeartRate,
Expand Down
40 changes: 21 additions & 19 deletions app/src/main/java/com/pulseloop/ui/components/ActivityMeta.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui.components

import com.pulseloop.ui.i18n.tr

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.DirectionsBike
import androidx.compose.material.icons.automirrored.filled.DirectionsRun
Expand All @@ -23,29 +25,29 @@ object ActivityMeta {
val ORDER = listOf("walk", "run", "cycle", "gym", "squash", "sport", "yoga", "dance", "hike", "other")

fun label(type: String): String = when (type) {
"walk" -> "Walking"
"run" -> "Running"
"cycle" -> "Cycling"
"gym" -> "Gym"
"squash" -> "Squash"
"sport" -> "Sport"
"yoga" -> "Yoga"
"dance" -> "Dance"
"hike" -> "Hiking"
"walk" -> tr("Walking")
"run" -> tr("Running")
"cycle" -> tr("Cycling")
"gym" -> tr("Gym")
"squash" -> tr("Squash")
"sport" -> tr("Sport")
"yoga" -> tr("Yoga")
"dance" -> tr("Dance")
"hike" -> tr("Hiking")
else -> type.replaceFirstChar { it.uppercase() }
}

fun helper(type: String): String = when (type) {
"walk" -> "Casual or brisk walking"
"run" -> "Outdoor or treadmill runs"
"cycle" -> "Road, trail, or stationary"
"gym" -> "Strength or circuit training"
"squash" -> "Court sessions"
"sport" -> "Team or racket sports"
"yoga" -> "Flow, stretch, or breathwork"
"dance" -> "Studio, cardio, or freestyle"
"hike" -> "Trails and elevation"
else -> "Anything else"
"walk" -> tr("Casual or brisk walking")
"run" -> tr("Outdoor or treadmill runs")
"cycle" -> tr("Road, trail, or stationary")
"gym" -> tr("Strength or circuit training")
"squash" -> tr("Court sessions")
"sport" -> tr("Team or racket sports")
"yoga" -> tr("Flow, stretch, or breathwork")
"dance" -> tr("Studio, cardio, or freestyle")
"hike" -> tr("Trails and elevation")
else -> tr("Anything else")
}

fun icon(type: String): ImageVector = when (type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui.components

import com.pulseloop.ui.i18n.tr

import com.pulseloop.ui.theme.trackBrush
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.size
Expand Down Expand Up @@ -54,7 +56,7 @@ fun ActivityRings(
labels: List<String> = emptyList(),
) {
// Drawn arcs say nothing to TalkBack; speak each ring's share of its goal instead.
val description = "Goal progress: " + rings.mapIndexed { i, ring ->
val description = tr("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(", ")
Expand Down
20 changes: 11 additions & 9 deletions app/src/main/java/com/pulseloop/ui/components/AppChrome.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui.components

import com.pulseloop.ui.i18n.tr

import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
Expand Down Expand Up @@ -78,13 +80,13 @@ fun AppHeader(
idle = idle,
sourceLabel = sourceLabel,
modifier = Modifier.clickable(
onClickLabel = "Open ring settings",
onClickLabel = tr("Open ring settings"),
role = Role.Button,
onClick = onOpenSettings,
),
)
IconButton(onClick = onOpenSettings) {
Icon(Icons.Outlined.Settings, "Settings", tint = PulseColors.textSecondary)
Icon(Icons.Outlined.Settings, tr("Settings"), tint = PulseColors.textSecondary)
}
}
}
Expand Down Expand Up @@ -115,11 +117,11 @@ fun ConnectionStatusPill(
val label = sourceLabel ?: when (state) {
RingConnectionState.CONNECTED ->
if (batteryPercent != null && batteryPercent > 0) "Connected · $batteryPercent%" else "Connected"
RingConnectionState.CONNECTING, RingConnectionState.RECONNECTING -> "Connecting…"
RingConnectionState.FAILED -> "Sync failed"
RingConnectionState.CONNECTING, RingConnectionState.RECONNECTING -> tr("Connecting…")
RingConnectionState.FAILED -> tr("Sync failed")
else -> if (idleNow) {
if (batteryPercent != null && batteryPercent > 0) "Idle · $batteryPercent%" else "Idle"
} else "Disconnected"
} else tr("Disconnected")
}
// Only run the transition while pulsing: an infinite 1f→1f animation still ticks every frame.
val pulse = if (isPulsing) {
Expand Down Expand Up @@ -159,10 +161,10 @@ fun ConnectionStatusPill(

/** Time-of-day greeting, mirroring RootViews.swift `greetingForHour()`. */
fun greetingForHour(): String = when (Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
in 5..11 -> "Good morning"
in 12..16 -> "Good afternoon"
in 17..21 -> "Good evening"
else -> "Good night"
in 5..11 -> tr("Good morning")
in 12..16 -> tr("Good afternoon")
in 17..21 -> tr("Good evening")
else -> tr("Good night")
}

/**
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/pulseloop/ui/components/Charts.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui.components

import com.pulseloop.ui.i18n.tr

import com.pulseloop.ui.theme.PulseColors
import com.pulseloop.ui.theme.ditherBrush
import com.pulseloop.ui.theme.drawDitherFade
Expand Down Expand Up @@ -309,7 +311,7 @@ fun TrendChart(
// 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)}, " +
"${title ?: tr("Chart")}: latest ${v(points.lastIndex)}, " +
"range ${valueFormatter(points.min())}–${valueFormatter(points.max())}, ${points.size} readings"
}

Expand Down Expand Up @@ -586,7 +588,7 @@ fun TrendChart(
IconButton(onClick = { zoom = 1f; windowStart = 0f }) {
Icon(
Icons.Filled.Refresh,
contentDescription = "Reset zoom",
contentDescription = tr("Reset zoom"),
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pulseloop.ui.components

import com.pulseloop.ui.i18n.tr

import com.pulseloop.ui.theme.dither
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand Down Expand Up @@ -80,7 +82,7 @@ fun DeviceHeroCard(
Row(
Modifier
.fillMaxWidth()
.clickable(onClickLabel = "Open ring settings", role = Role.Button, onClick = onOpenWearable),
.clickable(onClickLabel = tr("Open ring settings"), role = Role.Button, onClick = onOpenWearable),
horizontalArrangement = Arrangement.spacedBy(16.dp),
) {
RingArtView(
Expand Down
Loading
Loading