fix lint issues
- Commit
385fdf473ed891e27b33bc4aec9396798d2b5482- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-07 00:46 UTC (2 months ago)
- Parents
df2edbb
Diff
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationServiceController.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationServiceController.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationServiceController.ktnew file mode 100644index 0000000000..d2519c5988--- /dev/null+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationServiceController.kt@@ -0,0 +1,163 @@+package com.vayunmathur.findfamily.util++import android.Manifest+import android.content.Context+import android.content.Intent+import android.content.pm.PackageManager+import androidx.core.content.ContextCompat+import com.vayunmathur.findfamily.data.DirectBootStore+import com.vayunmathur.findfamily.data.FindFamilyRepository+import com.vayunmathur.findfamily.service.SharingTileService+import com.vayunmathur.library.util.DataStoreUtils+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.flow.Flow+import kotlinx.coroutines.flow.flowOf+import kotlinx.coroutines.withContext++/**+ * Single source of truth for whether the [LocationTrackingService] should be+ * running and for (re)starting / stopping it accordingly.+ *+ * The service runs whenever fine (precise) location permission is granted **and**+ * the user hasn't turned tracking off (the [TRACKING_ENABLED_KEY] flag, toggled+ * from the Quick Settings tile — see TrackingTileService). Sharing toggles are+ * enforced inside the heartbeat (we only publish to users with sendingEnabled=true)+ * rather than by stopping the service, so that UWB inbox draining, waypoint+ * entry/exit, low-battery alerts, and receiving peers' locations continue to work+ * even when the user pauses sharing or on fresh install before any contact is added.+ */+object LocationServiceController {++ /** Persisted on/off switch for the whole tracking service (default on). */+ const val TRACKING_ENABLED_KEY = "tracking_enabled"++ /**+ * Persisted on/off switch for publishing this device's location to anyone, toggled+ * from the Quick Settings sharing tile (default on — see SharingTileService).+ *+ * Deliberately separate from the per-person `sendingEnabled` flags so pausing and+ * resuming restores whoever was being shared with, and from [TRACKING_ENABLED_KEY]+ * so the service keeps running: peers' locations, waypoint entry/exit and UWB+ * tracker reporting all continue while sharing is paused.+ */+ const val GLOBAL_SHARING_ENABLED_KEY = "global_sharing_enabled"++ /**+ * Whether this phone acts as a finder for other people's powered-off devices.+ *+ * MANDATORY. There is no toggle: the finder half is part of what the app is, and the+ * Bluetooth permission behind it is now requested on the initial permission screen alongside+ * location. The key is retained only so an existing install's stored value is not orphaned;+ * nothing reads it any more.+ */+ const val CROWD_FINDING_ENABLED_KEY = "crowd_finding_enabled"++ fun hasFineLocationPermission(context: Context): Boolean =+ ContextCompat.checkSelfPermission(+ context,+ Manifest.permission.ACCESS_FINE_LOCATION+ ) == PackageManager.PERMISSION_GRANTED++ /** Whether the user has left tracking enabled. Defaults to true (opt-out, not opt-in). */+ suspend fun isTrackingEnabled(context: Context): Boolean =+ DataStoreUtils.getInstance(context).getBooleanAwait(TRACKING_ENABLED_KEY, true)++ /** Persist the tracking on/off choice and immediately start/stop the service to match. */+ suspend fun setTrackingEnabled(context: Context, enabled: Boolean) {+ DataStoreUtils.getInstance(context).setBoolean(TRACKING_ENABLED_KEY, enabled)+ syncServiceState(context)+ }++ /** Whether outbound sharing is on. Defaults to true (opt-out, not opt-in). */+ suspend fun isGlobalSharingEnabled(context: Context): Boolean =+ DataStoreUtils.getInstance(context).getBooleanAwait(GLOBAL_SHARING_ENABLED_KEY, true)++ /** [isGlobalSharingEnabled] as a stream, for the UI to grey out the per-person switches. */+ fun globalSharingEnabledFlow(context: Context): Flow<Boolean> =+ DataStoreUtils.getInstance(context).booleanFlow(GLOBAL_SHARING_ENABLED_KEY, true)++ /**+ * Persist the outbound-sharing choice. The next heartbeat picks it up; the service+ * itself is left alone, so this never stops receiving or tracker reporting.+ */+ suspend fun setGlobalSharingEnabled(context: Context, enabled: Boolean) {+ DataStoreUtils.getInstance(context).setBoolean(GLOBAL_SHARING_ENABLED_KEY, enabled)+ SharingTileService.requestRefresh(context)+ }++ /** Finding is mandatory: every install acts as a finder, so this is always true. */+ const val CROWD_FINDING_ENABLED = true++ /**+ * [CROWD_FINDING_ENABLED] as a stream. Constant now that finding is mandatory - kept as a+ * Flow so the collector in the service is unchanged, and so a future re-introduction of a+ * user control does not have to re-plumb the call site.+ */+ @Suppress("UNUSED_PARAMETER")+ fun crowdFindingEnabledFlow(context: Context): Flow<Boolean> = flowOf(true)++ suspend fun setCrowdFindingEnabled(context: Context, enabled: Boolean) {+ DataStoreUtils.getInstance(context).setBoolean(CROWD_FINDING_ENABLED_KEY, enabled)+ }++ /**+ * True iff the user is sharing their location with at least one *other*+ * person (the self user is excluded). Reads directly from the DB so the+ * answer is correct regardless of whether the UI/ViewModel is alive.+ */+ suspend fun isSharingEnabled(context: Context): Boolean {+ val ds = DataStoreUtils.getInstance(context)+ val selfId = try { ds.getLongAwait("userid") } catch (_: Exception) { ds.getLong("userid") }+ return FindFamilyRepository.get(context).getAllUsers().any { it.sendingEnabled && it.id != selfId }+ }++ /**+ * Start the service if eligible, otherwise make sure it is stopped. Safe to+ * call from any context (worker, boot, ViewModel, permission refresh, tile).+ * Eligible = fine-location permission granted AND tracking not turned off.+ */+ suspend fun syncServiceState(context: Context) {+ val appContext = context.applicationContext+ val eligible = hasFineLocationPermission(appContext) && isTrackingEnabled(appContext)+ val intent = Intent(appContext, LocationTrackingService::class.java)+ withContext(Dispatchers.Main) {+ if (eligible) {+ try {+ appContext.startForegroundService(intent)+ } catch (_: Exception) {+ }+ } else {+ appContext.stopService(intent)+ }+ }+ }++ /** Unconditionally stop the service. */+ fun stop(context: Context) {+ context.applicationContext.stopService(+ Intent(context.applicationContext, LocationTrackingService::class.java)+ )+ }++ /**+ * Boot-time start for the window before the first unlock.+ *+ * Deliberately does not consult [isTrackingEnabled] — that reads the credential-encrypted+ * DataStore, which is unreadable until the passcode is entered. Eligibility comes from the+ * device-protected mirror instead, and an unseeded mirror means we stay off rather than+ * guess. Never stops the service, since "not eligible yet" here only means "cannot tell".+ */+ suspend fun syncServiceStateLocked(context: Context) {+ val appContext = context.applicationContext+ if (!hasFineLocationPermission(appContext)) return+ if (!DirectBootStore.isSeeded(appContext)) return+ if (!DirectBootStore.isTrackingEnabled(appContext)) return+ withContext(Dispatchers.Main) {+ runCatching {+ appContext.startForegroundService(+ Intent(appContext, LocationTrackingService::class.java)+ )+ }+ }+ }+}
findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.ktindex cdd2e1ee6c..0efa146c27 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/LocationTrackingService.kt@@ -657,154 +657,6 @@ class ServiceRestartWorker( } } -/**- * Single source of truth for whether the [LocationTrackingService] should be- * running and for (re)starting / stopping it accordingly.- *- * The service runs whenever fine (precise) location permission is granted **and**- * the user hasn't turned tracking off (the [TRACKING_ENABLED_KEY] flag, toggled- * from the Quick Settings tile — see TrackingTileService). Sharing toggles are- * enforced inside the heartbeat (we only publish to users with sendingEnabled=true)- * rather than by stopping the service, so that UWB inbox draining, waypoint- * entry/exit, low-battery alerts, and receiving peers' locations continue to work- * even when the user pauses sharing or on fresh install before any contact is added.- */-object LocationServiceController {-- /** Persisted on/off switch for the whole tracking service (default on). */- const val TRACKING_ENABLED_KEY = "tracking_enabled"-- /**- * Persisted on/off switch for publishing this device's location to anyone, toggled- * from the Quick Settings sharing tile (default on — see SharingTileService).- *- * Deliberately separate from the per-person `sendingEnabled` flags so pausing and- * resuming restores whoever was being shared with, and from [TRACKING_ENABLED_KEY]- * so the service keeps running: peers' locations, waypoint entry/exit and UWB- * tracker reporting all continue while sharing is paused.- */- const val GLOBAL_SHARING_ENABLED_KEY = "global_sharing_enabled"-- /**- * Whether this phone acts as a finder for other people's powered-off devices.- *- * MANDATORY. There is no toggle: the finder half is part of what the app is, and the- * Bluetooth permission behind it is now requested on the initial permission screen alongside- * location. The key is retained only so an existing install's stored value is not orphaned;- * nothing reads it any more.- */- const val CROWD_FINDING_ENABLED_KEY = "crowd_finding_enabled"-- fun hasFineLocationPermission(context: Context): Boolean =- ContextCompat.checkSelfPermission(- context,- Manifest.permission.ACCESS_FINE_LOCATION- ) == PackageManager.PERMISSION_GRANTED-- /** Whether the user has left tracking enabled. Defaults to true (opt-out, not opt-in). */- suspend fun isTrackingEnabled(context: Context): Boolean =- DataStoreUtils.getInstance(context).getBooleanAwait(TRACKING_ENABLED_KEY, true)-- /** Persist the tracking on/off choice and immediately start/stop the service to match. */- suspend fun setTrackingEnabled(context: Context, enabled: Boolean) {- DataStoreUtils.getInstance(context).setBoolean(TRACKING_ENABLED_KEY, enabled)- syncServiceState(context)- }-- /** Whether outbound sharing is on. Defaults to true (opt-out, not opt-in). */- suspend fun isGlobalSharingEnabled(context: Context): Boolean =- DataStoreUtils.getInstance(context).getBooleanAwait(GLOBAL_SHARING_ENABLED_KEY, true)-- /** [isGlobalSharingEnabled] as a stream, for the UI to grey out the per-person switches. */- fun globalSharingEnabledFlow(context: Context): Flow<Boolean> =- DataStoreUtils.getInstance(context).booleanFlow(GLOBAL_SHARING_ENABLED_KEY, true)-- /**- * Persist the outbound-sharing choice. The next heartbeat picks it up; the service- * itself is left alone, so this never stops receiving or tracker reporting.- */- suspend fun setGlobalSharingEnabled(context: Context, enabled: Boolean) {- DataStoreUtils.getInstance(context).setBoolean(GLOBAL_SHARING_ENABLED_KEY, enabled)- SharingTileService.requestRefresh(context)- }-- /** Finding is mandatory: every install acts as a finder, so this is always true. */- const val CROWD_FINDING_ENABLED = true-- /**- * [CROWD_FINDING_ENABLED] as a stream. Constant now that finding is mandatory - kept as a- * Flow so the collector in the service is unchanged, and so a future re-introduction of a- * user control does not have to re-plumb the call site.- */- @Suppress("UNUSED_PARAMETER")- fun crowdFindingEnabledFlow(context: Context): Flow<Boolean> = flowOf(true)-- suspend fun setCrowdFindingEnabled(context: Context, enabled: Boolean) {- DataStoreUtils.getInstance(context).setBoolean(CROWD_FINDING_ENABLED_KEY, enabled)- }-- /**- * True iff the user is sharing their location with at least one *other*- * person (the self user is excluded). Reads directly from the DB so the- * answer is correct regardless of whether the UI/ViewModel is alive.- */- suspend fun isSharingEnabled(context: Context): Boolean {- val ds = DataStoreUtils.getInstance(context)- val selfId = try { ds.getLongAwait("userid") } catch (_: Exception) { ds.getLong("userid") }- return FindFamilyRepository.get(context).getAllUsers().any { it.sendingEnabled && it.id != selfId }- }-- /**- * Start the service if eligible, otherwise make sure it is stopped. Safe to- * call from any context (worker, boot, ViewModel, permission refresh, tile).- * Eligible = fine-location permission granted AND tracking not turned off.- */- suspend fun syncServiceState(context: Context) {- val appContext = context.applicationContext- val eligible = hasFineLocationPermission(appContext) && isTrackingEnabled(appContext)- val intent = Intent(appContext, LocationTrackingService::class.java)- withContext(Dispatchers.Main) {- if (eligible) {- try {- appContext.startForegroundService(intent)- } catch (_: Exception) {- }- } else {- appContext.stopService(intent)- }- }- }-- /** Unconditionally stop the service. */- fun stop(context: Context) {- context.applicationContext.stopService(- Intent(context.applicationContext, LocationTrackingService::class.java)- )- }-- /**- * Boot-time start for the window before the first unlock.- *- * Deliberately does not consult [isTrackingEnabled] — that reads the credential-encrypted- * DataStore, which is unreadable until the passcode is entered. Eligibility comes from the- * device-protected mirror instead, and an unseeded mirror means we stay off rather than- * guess. Never stops the service, since "not eligible yet" here only means "cannot tell".- */- suspend fun syncServiceStateLocked(context: Context) {- val appContext = context.applicationContext- if (!hasFineLocationPermission(appContext)) return- if (!DirectBootStore.isSeeded(appContext)) return- if (!DirectBootStore.isTrackingEnabled(appContext)) return- withContext(Dispatchers.Main) {- runCatching {- appContext.startForegroundService(- Intent(appContext, LocationTrackingService::class.java)- )- }- }- }-}- fun ensureSync(context: Context) { startRepeatedTask<ServiceRestartWorker>( context, "Location Sync", 15.minutes,
health/src/main/java/com/vayunmathur/health/ui/NutritionComponents.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/NutritionComponents.kt b/health/src/main/java/com/vayunmathur/health/ui/NutritionComponents.ktnew file mode 100644index 0000000000..7b84cd1509--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/NutritionComponents.kt@@ -0,0 +1,92 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.StrokeCap+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.ui.components.MetricRing+import com.vayunmathur.library.ui.LinearProgressIndicator+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.round++// Nutrition macro/nutrient row components. Split from NutritionPage.kt to keep that file+// under the 350-line UI limit and one public composable per file.++@Composable+internal fun CompactMacroRing(+ label: String,+ value: Double,+ goal: Double,+ unit: String,+ color: Color,+) {+ val progress = (value / goal).toFloat().coerceIn(0f, 1f)+ Column(+ horizontalAlignment = Alignment.CenterHorizontally,+ verticalArrangement = Arrangement.spacedBy(4.dp),+ ) {+ MetricRing(+ progress = progress,+ label = "",+ value = "${value.round(0).toInt()}",+ modifier = Modifier.size(72.dp),+ color = color,+ strokeWidth = 6.dp,+ )+ Text(+ text = label,+ style = MaterialTheme.typography.labelMedium,+ color = color.copy(alpha = 0.95f),+ fontWeight = FontWeight.SemiBold,+ )+ Text(+ text = "${value.round(0).toInt()}/${goal.toInt()}$unit",+ style = MaterialTheme.typography.labelSmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+}++/** Single nutrient row used by NutritionDetailsPage. */+@Composable+internal fun NutrientProgressRow(nutrient: NutrientDV, currentAmount: Double) {+ val progress = (currentAmount / nutrient.dailyValue).toFloat().coerceIn(0f, 1f)+ Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 10.dp)) {+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text(+ text = nutrient.name,+ style = MaterialTheme.typography.bodyLarge,+ modifier = Modifier.weight(1f)+ )+ Text(+ text = "${currentAmount.round(1)} / ${nutrient.dailyValue.round(0).toInt()}${nutrient.unit}",+ style = MaterialTheme.typography.bodySmall,+ color = MaterialTheme.colorScheme.onSurfaceVariant,+ )+ }+ Spacer(Modifier.height(6.dp))+ LinearProgressIndicator(+ progress = { progress },+ modifier = Modifier.fillMaxWidth().height(4.dp),+ color = HealthColors.Nutrition,+ trackColor = HealthColors.Nutrition.copy(alpha = 0.18f),+ strokeCap = StrokeCap.Round,+ )+ }+}
health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt b/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.ktindex 7c17198a36..e86d1a4ae3 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt@@ -286,70 +286,3 @@ fun NutritionScreen(state: NutritionUiState, actions: NutritionActions) { } } }--@Composable-private fun CompactMacroRing(- label: String,- value: Double,- goal: Double,- unit: String,- color: Color,-) {- val progress = (value / goal).toFloat().coerceIn(0f, 1f)- Column(- horizontalAlignment = Alignment.CenterHorizontally,- verticalArrangement = Arrangement.spacedBy(4.dp),- ) {- MetricRing(- progress = progress,- label = "",- value = "${value.round(0).toInt()}",- modifier = Modifier.size(72.dp),- color = color,- strokeWidth = 6.dp,- )- Text(- text = label,- style = MaterialTheme.typography.labelMedium,- color = color.copy(alpha = 0.95f),- fontWeight = FontWeight.SemiBold,- )- Text(- text = "${value.round(0).toInt()}/${goal.toInt()}$unit",- style = MaterialTheme.typography.labelSmall,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )- }-}--/** Single nutrient row used by NutritionDetailsPage. */-@Composable-internal fun NutrientProgressRow(nutrient: NutrientDV, currentAmount: Double) {- val progress = (currentAmount / nutrient.dailyValue).toFloat().coerceIn(0f, 1f)- Column(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 10.dp)) {- Row(- modifier = Modifier.fillMaxWidth(),- horizontalArrangement = Arrangement.SpaceBetween,- verticalAlignment = Alignment.CenterVertically- ) {- Text(- text = nutrient.name,- style = MaterialTheme.typography.bodyLarge,- modifier = Modifier.weight(1f)- )- Text(- text = "${currentAmount.round(1)} / ${nutrient.dailyValue.round(0).toInt()}${nutrient.unit}",- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant,- )- }- Spacer(Modifier.height(6.dp))- LinearProgressIndicator(- progress = { progress },- modifier = Modifier.fillMaxWidth().height(4.dp),- color = HealthColors.Nutrition,- trackColor = HealthColors.Nutrition.copy(alpha = 0.18f),- strokeCap = StrokeCap.Round,- )- }-}
health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.ktindex e6f4641f92..c5de623902 100644--- a/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt@@ -314,49 +314,3 @@ fun SleepStageGraph(record: Record) { } } }--@Composable-fun SleepStageBreakdown(data: SleepData) {- val context = LocalContext.current- val colors = hypnogramColors()- DashboardSection(title = "Stages", accentColor = HealthColors.Sleep) {- Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {- StageRow(- stringResource(R.string.label_awake),- hoursMinutesString(context, data.awakeDurationMillis / 60000),- colors.awake- )- StageRow(- stringResource(R.string.label_rem),- hoursMinutesString(context, data.remDurationMillis / 60000),- colors.rem- )- StageRow(- stringResource(R.string.label_core),- hoursMinutesString(context, data.lightDurationMillis / 60000),- colors.core- )- StageRow(- stringResource(R.string.label_deep),- hoursMinutesString(context, data.deepDurationMillis / 60000),- colors.deep- )- }- }-}--@Composable-fun StageRow(label: String, duration: String, color: Color) {- Row(- Modifier.fillMaxWidth(),- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.SpaceBetween- ) {- Row(verticalAlignment = Alignment.CenterVertically) {- Surface(Modifier.size(12.dp), shape = MaterialTheme.shapes.extraSmall, color = color) {}- Spacer(Modifier.width(12.dp))- Text(label, style = MaterialTheme.typography.bodyLarge)- }- Text(duration, style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Bold)- }-}
health/src/main/java/com/vayunmathur/health/ui/SleepStageComponents.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/SleepStageComponents.kt b/health/src/main/java/com/vayunmathur/health/ui/SleepStageComponents.ktnew file mode 100644index 0000000000..4ef9ffb24e--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/SleepStageComponents.kt@@ -0,0 +1,74 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.R+import com.vayunmathur.health.data.SleepData+import com.vayunmathur.health.ui.components.hypnogramColors+import com.vayunmathur.library.ui.DashboardSection+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text++// Sleep stage breakdown components. Split from SleepDetailsPage.kt to keep that file under+// the 350-line UI limit and one public composable per file.++@Composable+fun SleepStageBreakdown(data: SleepData) {+ val context = LocalContext.current+ val colors = hypnogramColors()+ DashboardSection(title = "Stages", accentColor = HealthColors.Sleep) {+ Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {+ StageRow(+ stringResource(R.string.label_awake),+ hoursMinutesString(context, data.awakeDurationMillis / 60000),+ colors.awake+ )+ StageRow(+ stringResource(R.string.label_rem),+ hoursMinutesString(context, data.remDurationMillis / 60000),+ colors.rem+ )+ StageRow(+ stringResource(R.string.label_core),+ hoursMinutesString(context, data.lightDurationMillis / 60000),+ colors.core+ )+ StageRow(+ stringResource(R.string.label_deep),+ hoursMinutesString(context, data.deepDurationMillis / 60000),+ colors.deep+ )+ }+ }+}++@Composable+fun StageRow(label: String, duration: String, color: Color) {+ Row(+ Modifier.fillMaxWidth(),+ verticalAlignment = Alignment.CenterVertically,+ horizontalArrangement = Arrangement.SpaceBetween+ ) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ Surface(Modifier.size(12.dp), shape = MaterialTheme.shapes.extraSmall, color = color) {}+ Spacer(Modifier.width(12.dp))+ Text(label, style = MaterialTheme.typography.bodyLarge)+ }+ Text(duration, style = MaterialTheme.typography.bodyLarge, fontWeight = FontWeight.Bold)+ }+}