Modern Apps git

← Modern-Apps.git

health: dialog routes and screenshot coverage for lint

Commit
ad28615ae05d4046e5acdc4c4a8a0ebb82b22d6e
Author
Vayun Mathur <[email protected]>
When
2026-12-02 00:25 UTC (4 days ago)
Parents
d688b46
DialogAsRoute (11 errors): eight calls become dialog routes --
LogBodyMetricDialog(config), LogHydrationDialog, LogMealDialog,
SocialHistoryAnswerDialog(loinc), PregnancyStatusDialog,
SmokingStatusDialog, AddIngredientDialog and
RenameIngredientDialog(id) -- each a DialogPage() entry in
NavigationEntries pushed from the click, with stateless content
under ui/dialogs/ (LogBodyMetricDialogContent,
LogHydrationDialogContent, AboutYouOptionDialog,
RenameIngredientDialogContent; AnswerPickerDialog and the search
dialog are rendered unconditionally by their entries). BodyPage
sheds its pending-config state for a stateless BodyScreen; the
AboutYou section and RecipeManagement page shed their show/pending
state the same way. RecipeEditorPage keeps its two dialogs under a
DIALOG LOCAL EXCEPTION: the search -> quantity chain passes a
non-serializable Ingredient/ServingUnit between steps and mutates
the editor-local, identity-matched draft list, with no route/result
shape for Ingredient yet.

RouteScreenshotCoverage (17 errors): real previews with fixed
fixtures for Body (new BodyScreen), NutritionFullBreakdown (new
NutritionBreakdownContent), RecipeManagement (RecipesList slice),
RecipeEditor (new RecipeEditorContent), SleepDetails (new
SleepDayContent), ExerciseDetails (new ExerciseDetailsContent),
MedicalDatePicker and MedicalTimePicker (shared library pickers at
a fixed date/time with a throwaway nav-result registry), plus the
six simple new dialog routes; existing captures renamed to the
detector keys (2-nutrition-details, 3/4/5-bar-chart-details...).
Nine routes are exempted in Route.kt with per-route reasons --
Medical, the five MedicalViewModel-draft editors, CatalogPicker,
LogMealDialog and AddIngredientDialog read ViewModel drafts/flows
with no stateless Layoutlib slice -- and the regenerated
docs/structure/exceptions.tsv inventory is included. Tests adapted
to the route-request contract (AboutYouDialogs, ChartDrawAndRecipe-
Edit, MoreUiActions, NutritionPageBinding assert the pushed route).

Verified: ./gradlew :health:lint :health:lintVitalRelease
:health:testDevUnitTest :health:compileReleaseKotlin all green
(658 unit tests, 0 failures); :health:compileDevScreenshotTestKotlin
and :health:updateDevScreenshotTest green (all 22 previews render).
health/AGENTS.md updated for Route.kt, the dialog routes, the new
screens/dialog contents and screenshot coverage.

Diff

docs/structure/exceptions.tsv
diff --git a/docs/structure/exceptions.tsv b/docs/structure/exceptions.tsvindex 5d0e961021..dcc3d475bb 100644--- a/docs/structure/exceptions.tsv+++ b/docs/structure/exceptions.tsv@@ -80,6 +80,15 @@ SCREENSHOT_COVERAGE	contacts/src/main/java/com/vayunmathur/contacts/Route.kt	Imp SCREENSHOT_COVERAGE	contacts/src/main/java/com/vayunmathur/contacts/Route.kt	InsertOrEditContact: editor reads ViewModel + contacts-provider state; no stateless slice for Layoutlib	1 SCREENSHOT_COVERAGE	contacts/src/main/java/com/vayunmathur/contacts/Route.kt	RenameAccountDialog: dialog renames through the ViewModel account framework; no stateless slice	1 SCREENSHOT_COVERAGE	contacts/src/main/java/com/vayunmathur/contacts/Route.kt	Settings: settings page reads ViewModel account/provider flows; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	AddIngredientDialog: dialog searches the bundled food database and remote API through the ViewModel; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	CatalogPicker: picker searches MedicalViewModel catalog flows (CVX/RxNorm/LOINC) and writes the draft; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	EditAllergy: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	EditCondition: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	EditLabResult: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	EditMedication: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	EditVaccination: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	LogMealDialog: dialog lists ViewModel recipe/ingredient flows and logs through the ViewModel; no stateless slice for Layoutlib	1+SCREENSHOT_COVERAGE	health/src/main/java/com/vayunmathur/health/Route.kt	Medical: medical page reads MedicalViewModel record flows and Health Connect/PHR state; no stateless slice for Layoutlib	1 SCREENSHOT_COVERAGE	notes/src/main/java/com/vayunmathur/notes/Route.kt	ExternalNote: external note opens a shared/dropped file URI through the ViewModel; no stateless slice for Layoutlib	1 SCREENSHOT_COVERAGE	notes/src/main/java/com/vayunmathur/notes/Route.kt	InkEditor: ink editor draws on Room-backed block state with a stylus canvas; no stateless slice for Layoutlib	1 TOAST	share/src/main/java/com/vayunmathur/share/platform/receive/ShareSaveActivity.kt	no UI to host a snackbar.	1
health/AGENTS.md
diff --git a/health/AGENTS.md b/health/AGENTS.mdindex e74061e680..7e077f9b36 100644--- a/health/AGENTS.md+++ b/health/AGENTS.md@@ -5,7 +5,7 @@ _Install: ./install health (dev by default)._ - Gradle: :health / dir: health/ - Package roots present: ui, data, domain, platform, service, notifications-- Entry files: MainActivity.kt (no Route.kt — Today-dashboard + record pages flow)+- Entry files: MainActivity.kt, Route.kt (sealed nav destinations incl. DialogPage dialog routes), Navigation.kt + ui/NavigationEntries.kt - Deps: :library:room - Metadata: metadata_data/health.md (present) - Rust: no / screenshotTest: yes@@ -16,7 +16,7 @@ _Install: ./install health (dev by default)._ - Per-metric dashboards with charts/history (`GenericLineChart`/`GenericBarChart`, hypnogram for sleep) - Medications with dose schedules + exact reminders (`DoseScheduler`, `DoseSoundService`, boot-rescheduled); vaccinations from bundled CVX, drugs from RxNorm; card attachments (PDF/photo) - Food logging against a bundled database + search API; AI insights via the on-device OpenAssistant model; file export-**Architecture / data-flow:** `ui/` Today + record pages → `platform/MedicalViewModel` (+ per-area `Medical*Ops`) → `data/HealthRepository` over Room (`Record`, `MedicationSchedule`, `MedicalRecords`) synced with Health Connect; `domain/` holds pure FHIR (Observations, Medication, Immunization, Allergy/Condition) + `DoseSchedule`; reminders flow `DoseScheduler` → receivers → `DoseReminderActivity` + `service/DoseSoundService`.+**Architecture / data-flow:** Dialogs that act on a record/metric are `Route.…Dialog` destinations (`DialogPage()` entries in `ui/NavigationEntries.kt`) pushed from clicks, with stateless content under `ui/dialogs/`; the ingredient search→quantity chain in `RecipeEditorPage` is the one local exception (see its `DIALOG LOCAL EXCEPTION` marker). Screenshot coverage lives in `src/screenshotTest` `MetadataPreviews` (stateless screens: Today/Nutrition/Body/metric detail/nutrition breakdown/recipe list+editor/sleep/exercise + date-time and simple dialog routes); VM-draft routes are exempted per-route in `Route.kt`. `ui/` Today + record pages → `platform/MedicalViewModel` (+ per-area `Medical*Ops`) → `data/HealthRepository` over Room (`Record`, `MedicationSchedule`, `MedicalRecords`) synced with Health Connect; `domain/` holds pure FHIR (Observations, Medication, Immunization, Allergy/Condition) + `DoseSchedule`; reminders flow `DoseScheduler` → receivers → `DoseReminderActivity` + `service/DoseSoundService`. **Entry points + reading order:** `MainActivity.kt` → `ui/TodayPage.kt` → `platform/MedicalViewModel.kt` → `data/HealthRepository.kt` → `domain/FhirRecords.kt` → `platform/DoseScheduler.kt`. **Gotchas:** - Day views use half-open local-calendar ranges (`HealthChartData.dayRange`, DAO `startTime in [start, end)`, bucketed by start): DST days are 23/25h, midnight point records belong to the new day, and intervals crossing midnight count on their start day. Day-tab line metrics average their hourly averages; bar metrics sum their hourly sums; basal metabolic rate (stored kcal/day) is an averaged line metric, while Today hydration converts stored litres to ml. Month/year tabs bucket bar metrics into weekly/monthly sums: their per-day average divides the period total by the calendar days in the month/year, and a history row's goal is the daily goal scaled by the days its bucket covers (line metrics keep averaging and comparing bucket averages directly).@@ -25,8 +25,10 @@ _Install: ./install health (dev by default)._ - Dose reminders need the boot path re-armed like clock alarms; sound runs through a foreground service  ## Key files-### Root — entry (no Route.kt)+### Root — entry - com/vayunmathur/health/MainActivity.kt+- com/vayunmathur/health/Route.kt+- com/vayunmathur/health/Navigation.kt ### data/ — Room entities + repository - com/vayunmathur/health/data/HealthRepository.kt - com/vayunmathur/health/data/Record.kt@@ -72,6 +74,12 @@ _Install: ./install health (dev by default)._ - com/vayunmathur/health/util/FoodSearchAPI.kt - com/vayunmathur/health/util/Utils.kt ### ui/ + ui/components/ — Today, records, charts, logging+- com/vayunmathur/health/ui/NavigationEntries.kt+- com/vayunmathur/health/ui/BodyScreen.kt+- com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.kt+- com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.kt+- com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.kt+- com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.kt - com/vayunmathur/health/ui/TodayPage.kt - com/vayunmathur/health/ui/TodayHero.kt - com/vayunmathur/health/ui/RecordsPage.kt
health/src/main/java/com/vayunmathur/health/Route.kt
diff --git a/health/src/main/java/com/vayunmathur/health/Route.kt b/health/src/main/java/com/vayunmathur/health/Route.ktindex a909ac5d30..5a40fbd630 100644--- a/health/src/main/java/com/vayunmathur/health/Route.kt+++ b/health/src/main/java/com/vayunmathur/health/Route.kt@@ -6,6 +6,15 @@ import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalTime import kotlinx.serialization.Serializable +// SCREENSHOT COVERAGE EXCEPTION: Medical: medical page reads MedicalViewModel record flows and Health Connect/PHR state; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: EditVaccination: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: EditMedication: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: EditAllergy: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: EditCondition: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: EditLabResult: form edits a MedicalViewModel draft loaded from Room/Health Connect; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: CatalogPicker: picker searches MedicalViewModel catalog flows (CVX/RxNorm/LOINC) and writes the draft; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: LogMealDialog: dialog lists ViewModel recipe/ingredient flows and logs through the ViewModel; no stateless slice for Layoutlib+// SCREENSHOT COVERAGE EXCEPTION: AddIngredientDialog: dialog searches the bundled food database and remote API through the ViewModel; no stateless slice for Layoutlib /** Contract for route. */ @Serializable sealed interface Route: NavKey {@@ -98,4 +107,36 @@ sealed interface Route: NavKey {     /** The shared time picker, for dose reminder times. */     @Serializable     data class MedicalTimePicker(val key: String, val initialTime: LocalTime): Route++    /** Dialog destination for logging one body-composition metric. */+    @Serializable+    data class LogBodyMetricDialog(val config: HealthMetricConfig): Route++    /** Dialog destination for logging hydration. */+    @Serializable+    data object LogHydrationDialog: Route++    /** Dialog destination for logging a meal. */+    @Serializable+    data object LogMealDialog: Route++    /** Dialog destination for answering the social-history question with this LOINC code. */+    @Serializable+    data class SocialHistoryAnswerDialog(val loinc: String): Route++    /** Dialog destination for picking the pregnancy status. */+    @Serializable+    data object PregnancyStatusDialog: Route++    /** Dialog destination for picking the smoking status. */+    @Serializable+    data object SmokingStatusDialog: Route++    /** Dialog destination for searching an ingredient to add to the managed ingredients list. */+    @Serializable+    data object AddIngredientDialog: Route++    /** Dialog destination for renaming the managed ingredient with this id. */+    @Serializable+    data class RenameIngredientDialog(val ingredientId: String): Route }
health/src/main/java/com/vayunmathur/health/ui/BodyLoggingDialog.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/BodyLoggingDialog.kt b/health/src/main/java/com/vayunmathur/health/ui/BodyLoggingDialog.ktindex 9759c695f7..584603cce2 100644--- a/health/src/main/java/com/vayunmathur/health/ui/BodyLoggingDialog.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/BodyLoggingDialog.kt@@ -1,26 +1,15 @@ package com.vayunmathur.health.ui -import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.text.KeyboardOptions-import com.vayunmathur.library.ui.R as UiR-import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.OutlinedTextField-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.text.input.KeyboardType-import com.vayunmathur.health.R import com.vayunmathur.health.domain.Centimeters import com.vayunmathur.health.domain.Kilograms import com.vayunmathur.health.domain.Percent import com.vayunmathur.health.platform.HealthViewModel+import com.vayunmathur.health.ui.dialogs.LogBodyMetricDialogContent import java.time.Instant  /**@@ -37,49 +26,29 @@ fun LogBodyMetricDialog(     onDismiss: () -> Unit, ) {     var valueStr by remember { mutableStateOf("") }-    val value = valueStr.toDoubleOrNull()-    val isValid = value != null && value > 0--    AlertDialog(-        onDismissRequest = onDismiss,-        title = { Text(stringResource(R.string.log_body_metric, stringResource(config.titleRes))) },-        text = {-            OutlinedTextField(-                value = valueStr,-                onValueChange = { valueStr = it },-                label = { Text(stringResource(config.titleRes)) },-                suffix = { Text(config.unit) },-                singleLine = true,-                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),-                modifier = Modifier.fillMaxWidth(),-            )-        },-        confirmButton = {-            Button(-                enabled = isValid,-                onClick = {-                    if (value != null) {-                        // Typed seam: the entered unit is stated in the type, and the-                        // cm→m height conversion lives in Centimeters.toMeters().-                        when (config) {-                            HealthMetricConfig.HEIGHT -> viewModel.logHeight(Centimeters(value), Instant.now())-                            HealthMetricConfig.WEIGHT -> viewModel.logWeight(Kilograms(value), Instant.now())-                            HealthMetricConfig.BODY_FAT -> viewModel.logBodyFat(Percent(value), Instant.now())-                            HealthMetricConfig.LEAN_BODY_MASS ->-                                viewModel.logLeanBodyMass(Kilograms(value), Instant.now())-                            HealthMetricConfig.BONE_MASS -> viewModel.logBoneMass(Kilograms(value), Instant.now())-                            HealthMetricConfig.BODY_WATER_MASS ->-                                viewModel.logBodyWaterMass(Kilograms(value), Instant.now())-                            else -> {-                                @Suppress("DEPRECATION")-                                viewModel.logBodyMetric(config.recordType, value, Instant.now())-                            }-                        }-                        onDismiss()-                    }-                },-            ) { Text(stringResource(UiR.string.save)) }+    LogBodyMetricDialogContent(+        config = config,+        value = valueStr,+        onValueChange = { valueStr = it },+        onConfirm = { value ->+            // Typed seam: the entered unit is stated in the type, and the+            // cm→m height conversion lives in Centimeters.toMeters().+            when (config) {+                HealthMetricConfig.HEIGHT -> viewModel.logHeight(Centimeters(value), Instant.now())+                HealthMetricConfig.WEIGHT -> viewModel.logWeight(Kilograms(value), Instant.now())+                HealthMetricConfig.BODY_FAT -> viewModel.logBodyFat(Percent(value), Instant.now())+                HealthMetricConfig.LEAN_BODY_MASS ->+                    viewModel.logLeanBodyMass(Kilograms(value), Instant.now())+                HealthMetricConfig.BONE_MASS -> viewModel.logBoneMass(Kilograms(value), Instant.now())+                HealthMetricConfig.BODY_WATER_MASS ->+                    viewModel.logBodyWaterMass(Kilograms(value), Instant.now())+                else -> {+                    @Suppress("DEPRECATION")+                    viewModel.logBodyMetric(config.recordType, value, Instant.now())+                }+            }+            onDismiss()         },-        dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) } },+        onDismiss = onDismiss,     ) }
health/src/main/java/com/vayunmathur/health/ui/BodyPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/BodyPage.kt b/health/src/main/java/com/vayunmathur/health/ui/BodyPage.ktindex 325dadfb27..c582feed5a 100644--- a/health/src/main/java/com/vayunmathur/health/ui/BodyPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/BodyPage.kt@@ -1,49 +1,14 @@ package com.vayunmathur.health.ui -import androidx.compose.foundation.layout.Arrangement-import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.ExperimentalMaterial3ExpressiveApi-import com.vayunmathur.library.ui.FloatingActionButtonMenu-import com.vayunmathur.library.ui.FloatingActionButtonMenuItem-import com.vayunmathur.library.ui.LazyListScaffold-import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.ToggleFloatingActionButton import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier-import androidx.compose.ui.res.stringResource-import androidx.compose.ui.unit.dp-import com.vayunmathur.health.R import com.vayunmathur.health.Route-import com.vayunmathur.health.data.RecordType-import com.vayunmathur.health.ui.components.MetricRow-import com.vayunmathur.library.ui.DashboardSection-import com.vayunmathur.library.ui.DashboardSectionDivider import com.vayunmathur.health.platform.HealthViewModel import com.vayunmathur.health.platform.MainPageMetrics-import com.vayunmathur.library.ui.IconAdd-import com.vayunmathur.library.ui.IconBodySystem-import com.vayunmathur.library.ui.IconClose import com.vayunmathur.library.util.NavBackStack-import com.vayunmathur.library.util.sharedText-import com.vayunmathur.library.util.round -private val bodyMetricConfigs = listOf(-    HealthMetricConfig.WEIGHT,-    HealthMetricConfig.HEIGHT,-    HealthMetricConfig.BODY_FAT,-    HealthMetricConfig.LEAN_BODY_MASS,-    HealthMetricConfig.BONE_MASS,-    HealthMetricConfig.BODY_WATER_MASS,-)--@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class) @Composable fun BodyPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {     val metrics: MainPageMetrics by viewModel.mainPageMetrics.collectAsState()@@ -52,109 +17,9 @@ fun BodyPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {         viewModel.loadMainPageMetrics()     } -    var fabExpanded by remember { mutableStateOf(false) }-    var dialogConfig by remember { mutableStateOf<HealthMetricConfig?>(null) }--    dialogConfig?.let { config ->-        LogBodyMetricDialog(-            viewModel = viewModel,-            config = config,-            onDismiss = { dialogConfig = null },-        )-    }--    LazyListScaffold(-        floatingActionButton = {-            FloatingActionButtonMenu(-                expanded = fabExpanded,-                button = {-                    ToggleFloatingActionButton(fabExpanded, { fabExpanded = it }) {-                        val tint = MaterialTheme.colorScheme.onPrimaryContainer-                        if (!fabExpanded) IconAdd(tint = tint) else IconClose(tint = tint)-                    }-                },-            ) {-                bodyMetricConfigs.forEach { config ->-                    FloatingActionButtonMenuItem(-                        onClick = { fabExpanded = false; dialogConfig = config },-                        text = { Text(stringResource(config.titleRes)) },-                        icon = {-                            IconBodySystem(-                                tint = colorFor(config.recordType),-                            )-                        },-                    )-                }-            }-        },-        verticalArrangement = Arrangement.spacedBy(12.dp),-    ) {-            // Body composition-            item {-                DashboardSection(-                    title = stringResource(R.string.section_body_composition),-                    accentColor = HealthColors.Body,-                ) {-                    MetricRow(-                        label = stringResource(R.string.metric_weight),-                        value = metrics.weight?.round(1)?.toString() ?: "--",-                        unit = stringResource(R.string.unit_kg),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.Weight),-                        labelModifier = Modifier.sharedText("health-metric-label-WEIGHT"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.WEIGHT)) },-                    )-                    DashboardSectionDivider()-                    MetricRow(-                        label = stringResource(R.string.metric_height),-                        value = metrics.height?.let { (it * 100).round(1).toString() } ?: "--",-                        unit = stringResource(R.string.unit_cm),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.Height),-                        labelModifier = Modifier.sharedText("health-metric-label-HEIGHT"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.HEIGHT)) },-                    )-                    DashboardSectionDivider()-                    MetricRow(-                        label = stringResource(R.string.metric_body_fat),-                        value = metrics.bodyFat?.round(1)?.toString() ?: "--",-                        unit = stringResource(R.string.unit_percent),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.BodyFat),-                        labelModifier = Modifier.sharedText("health-metric-label-BODY_FAT"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.BODY_FAT)) },-                    )-                    DashboardSectionDivider()-                    MetricRow(-                        label = stringResource(R.string.metric_lean_body_mass),-                        value = metrics.leanBodyMass?.round(1)?.toString() ?: "--",-                        unit = stringResource(R.string.unit_kg),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.LeanBodyMass),-                        labelModifier = Modifier.sharedText("health-metric-label-LEAN_BODY_MASS"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.LEAN_BODY_MASS)) },-                    )-                    DashboardSectionDivider()-                    MetricRow(-                        label = stringResource(R.string.metric_bone_mass),-                        value = metrics.boneMass?.round(1)?.toString() ?: "--",-                        unit = stringResource(R.string.unit_kg),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.BoneMass),-                        labelModifier = Modifier.sharedText("health-metric-label-BONE_MASS"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.BONE_MASS)) },-                    )-                    DashboardSectionDivider()-                    MetricRow(-                        label = stringResource(R.string.metric_body_water_mass),-                        value = metrics.bodyWaterMass?.round(1)?.toString() ?: "--",-                        unit = stringResource(R.string.unit_kg),-                        leadingIcon = { m, c -> IconBodySystem(m, c) },-                        leadingTint = colorFor(com.vayunmathur.health.data.RecordType.BodyWaterMass),-                        labelModifier = Modifier.sharedText("health-metric-label-BODY_WATER_MASS"),-                        onClick = { backStack.add(Route.BarChartDetails(HealthMetricConfig.BODY_WATER_MASS)) },-                    )-                }-            }-        }+    BodyScreen(+        metrics = metrics,+        onMetricClick = { backStack.add(Route.BarChartDetails(it)) },+        onLogClick = { backStack.add(Route.LogBodyMetricDialog(it)) },+    ) }
health/src/main/java/com/vayunmathur/health/ui/BodyScreen.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/BodyScreen.kt b/health/src/main/java/com/vayunmathur/health/ui/BodyScreen.ktnew file mode 100644index 0000000000..b710fa7244--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/BodyScreen.kt@@ -0,0 +1,139 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.R+import com.vayunmathur.health.data.RecordType+import com.vayunmathur.health.platform.MainPageMetrics+import com.vayunmathur.health.ui.components.MetricRow+import com.vayunmathur.library.ui.DashboardSection+import com.vayunmathur.library.ui.DashboardSectionDivider+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.ExperimentalMaterial3ExpressiveApi+import com.vayunmathur.library.ui.FloatingActionButtonMenu+import com.vayunmathur.library.ui.FloatingActionButtonMenuItem+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconBodySystem+import com.vayunmathur.library.ui.IconClose+import com.vayunmathur.library.ui.LazyListScaffold+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.ToggleFloatingActionButton+import com.vayunmathur.library.util.round+import com.vayunmathur.library.util.sharedText++private val bodyMetricConfigs = listOf(+    HealthMetricConfig.WEIGHT,+    HealthMetricConfig.HEIGHT,+    HealthMetricConfig.BODY_FAT,+    HealthMetricConfig.LEAN_BODY_MASS,+    HealthMetricConfig.BONE_MASS,+    HealthMetricConfig.BODY_WATER_MASS,+)++/** Stateless body-composition screen: metric rows plus the log-metric FAB menu. */+@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)+@Composable+fun BodyScreen(+    metrics: MainPageMetrics,+    onMetricClick: (HealthMetricConfig) -> Unit,+    onLogClick: (HealthMetricConfig) -> Unit,+) {+    var fabExpanded by remember { mutableStateOf(false) }+    LazyListScaffold(+        floatingActionButton = {+            FloatingActionButtonMenu(+                expanded = fabExpanded,+                button = {+                    ToggleFloatingActionButton(fabExpanded, { fabExpanded = it }) {+                        val tint = MaterialTheme.colorScheme.onPrimaryContainer+                        if (!fabExpanded) IconAdd(tint = tint) else IconClose(tint = tint)+                    }+                },+            ) {+                bodyMetricConfigs.forEach { config ->+                    FloatingActionButtonMenuItem(+                        onClick = { fabExpanded = false; onLogClick(config) },+                        text = { Text(stringResource(config.titleRes)) },+                        icon = { IconBodySystem(tint = colorFor(config.recordType)) },+                    )+                }+            }+        },+        verticalArrangement = Arrangement.spacedBy(12.dp),+    ) {+        item {+            DashboardSection(+                title = stringResource(R.string.section_body_composition),+                accentColor = HealthColors.Body,+            ) {+                MetricRow(+                    label = stringResource(R.string.metric_weight),+                    value = metrics.weight?.round(1)?.toString() ?: "--",+                    unit = stringResource(R.string.unit_kg),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.Weight),+                    labelModifier = Modifier.sharedText("health-metric-label-WEIGHT"),+                    onClick = { onMetricClick(HealthMetricConfig.WEIGHT) },+                )+                DashboardSectionDivider()+                MetricRow(+                    label = stringResource(R.string.metric_height),+                    value = metrics.height?.let { (it * 100).round(1).toString() } ?: "--",+                    unit = stringResource(R.string.unit_cm),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.Height),+                    labelModifier = Modifier.sharedText("health-metric-label-HEIGHT"),+                    onClick = { onMetricClick(HealthMetricConfig.HEIGHT) },+                )+                DashboardSectionDivider()+                MetricRow(+                    label = stringResource(R.string.metric_body_fat),+                    value = metrics.bodyFat?.round(1)?.toString() ?: "--",+                    unit = stringResource(R.string.unit_percent),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.BodyFat),+                    labelModifier = Modifier.sharedText("health-metric-label-BODY_FAT"),+                    onClick = { onMetricClick(HealthMetricConfig.BODY_FAT) },+                )+                DashboardSectionDivider()+                MetricRow(+                    label = stringResource(R.string.metric_lean_body_mass),+                    value = metrics.leanBodyMass?.round(1)?.toString() ?: "--",+                    unit = stringResource(R.string.unit_kg),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.LeanBodyMass),+                    labelModifier = Modifier.sharedText("health-metric-label-LEAN_BODY_MASS"),+                    onClick = { onMetricClick(HealthMetricConfig.LEAN_BODY_MASS) },+                )+                DashboardSectionDivider()+                MetricRow(+                    label = stringResource(R.string.metric_bone_mass),+                    value = metrics.boneMass?.round(1)?.toString() ?: "--",+                    unit = stringResource(R.string.unit_kg),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.BoneMass),+                    labelModifier = Modifier.sharedText("health-metric-label-BONE_MASS"),+                    onClick = { onMetricClick(HealthMetricConfig.BONE_MASS) },+                )+                DashboardSectionDivider()+                MetricRow(+                    label = stringResource(R.string.metric_body_water_mass),+                    value = metrics.bodyWaterMass?.round(1)?.toString() ?: "--",+                    unit = stringResource(R.string.unit_kg),+                    leadingIcon = { m, c -> IconBodySystem(m, c) },+                    leadingTint = colorFor(RecordType.BodyWaterMass),+                    labelModifier = Modifier.sharedText("health-metric-label-BODY_WATER_MASS"),+                    onClick = { onMetricClick(HealthMetricConfig.BODY_WATER_MASS) },+                )+            }+        }+    }+}
health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.ktindex ace4e2055c..e9db5d0453 100644--- a/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/ExerciseDetailsPage.kt@@ -102,26 +102,17 @@ fun ExerciseDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewMod                     .padding(padding),             )         } else {-            LazyColumn(-                modifier = Modifier-                    .fillMaxSize()-                    .padding(top = padding.calculateTopPadding()),-                contentPadding = PaddingValues(-                    start = 16.dp, end = 16.dp,-                    bottom = padding.calculateBottomPadding() + 24.dp-                ),-                verticalArrangement = Arrangement.spacedBy(16.dp),-            ) {-                items(records, key = { it.primaryKey }) { record ->-                    ExerciseSessionCard(record)-                }-            }+            ExerciseDetailsContent(+                records = records,+                topPadding = padding.calculateTopPadding(),+                bottomPadding = padding.calculateBottomPadding() + 24.dp,+            )         }     } }  @Composable-private fun ExerciseSessionCard(record: Record) {+internal fun ExerciseSessionCard(record: Record) {     val exercise = record.exerciseData     val exerciseName = exercise?.title         ?: exercise?.let { exerciseTypeName(it.exerciseType) }@@ -332,3 +323,21 @@ private fun ExerciseSessionCard(record: Record) { }  private fun formatDuration(minutes: Long): String = com.vayunmathur.health.platform.formatDuration(minutes)++/** Stateless exercise history: one session card per record. */+@Composable+internal fun ExerciseDetailsContent(+    records: List<Record>,+    topPadding: androidx.compose.ui.unit.Dp = 0.dp,+    bottomPadding: androidx.compose.ui.unit.Dp = 24.dp,+) {+    LazyColumn(+        modifier = Modifier.fillMaxSize().padding(top = topPadding),+        contentPadding = PaddingValues(start = 16.dp, end = 16.dp, bottom = bottomPadding),+        verticalArrangement = Arrangement.spacedBy(16.dp),+    ) {+        items(records, key = { it.primaryKey }) { record ->+            ExerciseSessionCard(record)+        }+    }+}
health/src/main/java/com/vayunmathur/health/ui/FoodLoggingDialogs.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/FoodLoggingDialogs.kt b/health/src/main/java/com/vayunmathur/health/ui/FoodLoggingDialogs.ktindex 2a78c1ee0a..2665727ebb 100644--- a/health/src/main/java/com/vayunmathur/health/ui/FoodLoggingDialogs.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/FoodLoggingDialogs.kt@@ -53,66 +53,17 @@ enum class HydrationUnit(@StringRes val displayName: Int, val toLiters: Double) fun LogHydrationDialog(viewModel: HealthViewModel, initialTime: Instant? = null, onDismiss: () -> Unit) {     var quantityStr by remember { mutableStateOf("") }     var selectedUnit by remember { mutableStateOf(HydrationUnit.Liters) }-    var unitExpanded by remember { mutableStateOf(false) }--    val quantity = quantityStr.toDoubleOrNull()-    val isValid = quantity != null && quantity > 0--    AlertDialog(-            onDismissRequest = onDismiss,-            title = { Text(stringResource(R.string.log_hydration)) },-            text = {-                Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {-                    OutlinedTextField(-                            value = quantityStr,-                            onValueChange = { quantityStr = it },-                            label = { Text(stringResource(R.string.quantity)) },-                            keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),-                            modifier = Modifier.fillMaxWidth(),-                            trailingIcon = {-                                Row(-                                        modifier = Modifier.clickable { unitExpanded = true },-                                        verticalAlignment = Alignment.CenterVertically-                                ) {-                                    Text(-                                            stringResource(selectedUnit.displayName),-                                            style = MaterialTheme.typography.bodyMedium-                                    )-                                    IconArrowDropDown()-                                }-                                DropdownMenu(-                                        expanded = unitExpanded,-                                        onDismissRequest = { unitExpanded = false }-                                ) {-                                    HydrationUnit.entries.forEach { unit ->-                                        SelectableDropdownMenuItem(-                                                selected = unit == selectedUnit,-                                                onClick = {-                                                    selectedUnit = unit-                                                    unitExpanded = false-                                                },-                                                text = { Text(stringResource(unit.displayName)) },-                                                selectedLeadingIcon = { IconCheck() },-                                        )-                                    }-                                }-                            }-                    )-                }-            },-            confirmButton = {-                Button(-                        enabled = isValid,-                        onClick = {-                            if (quantity != null) {-                                val time = initialTime ?: Instant.now()-                                viewModel.logHydration(Liters(quantity * selectedUnit.toLiters), time)-                                onDismiss()-                            }-                        }-                ) { Text(stringResource(UiR.string.save)) }-            },-            dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) } }+    com.vayunmathur.health.ui.dialogs.LogHydrationDialogContent(+        quantity = quantityStr,+        onQuantityChange = { quantityStr = it },+        selectedUnit = selectedUnit,+        onUnitChange = { selectedUnit = it },+        onConfirm = { quantity, unit ->+            val time = initialTime ?: Instant.now()+            viewModel.logHydration(Liters(quantity * unit.toLiters), time)+            onDismiss()+        },+        onDismiss = onDismiss,     ) } 
health/src/main/java/com/vayunmathur/health/ui/MedicalAboutYouSection.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/MedicalAboutYouSection.kt b/health/src/main/java/com/vayunmathur/health/ui/MedicalAboutYouSection.ktindex 674b0e5c76..9de300faec 100644--- a/health/src/main/java/com/vayunmathur/health/ui/MedicalAboutYouSection.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/MedicalAboutYouSection.kt@@ -60,73 +60,18 @@ fun MedicalAboutYouSection(     val profile by viewModel.profile.collectAsState()     val answers by viewModel.profileAnswers.collectAsState() -    var askingQuestion by remember { mutableStateOf<SocialHistoryQuestions.Question?>(null) }-    var askingPregnancy by remember { mutableStateOf(false) }-    var askingSmoking by remember { mutableStateOf(false) }-     // The due-date picker posts back through the nav result registry; applying it here keeps the     // result next to the row that asked for it.     ResultEffect<DateSelection>(ABOUT_YOU_DUE_DATE_KEY) { picked ->         viewModel.setPregnancyStatus(profile.pregnancyStatus, picked.date)     } -    askingQuestion?.let { question ->-        AnswerPickerDialog(-            question = question,-            selected = question.answers-                .firstOrNull { it.code == answers[question.loinc]?.answerCode },-            onPick = { picked ->-                if (picked == null) {-                    viewModel.clearSocialHistoryAnswer(question)-                } else {-                    viewModel.setSocialHistoryAnswer(question, picked)-                }-                askingQuestion = null-            },-            onDismiss = { askingQuestion = null },-        )-    }-    if (askingPregnancy) {-        AboutYouOptionDialog(-            title = stringResource(R.string.about_you_pregnancy_question),-            options = PregnancyStatus.entries.map { stringResource(it.labelRes()) },-            selectedIndex = PregnancyStatus.entries.indexOf(profile.pregnancyStatus),-            onPick = { index ->-                val picked = PregnancyStatus.entries[index]-                // Clearing the status clears the date with it: an expected delivery date on a-                // "not pregnant" record is contradictory.-                viewModel.setPregnancyStatus(-                    picked,-                    if (picked == PregnancyStatus.Pregnant) {-                        profile.dueDate?.toLocalDate()-                    } else {-                        null-                    },-                )-                askingPregnancy = false-            },-            onDismiss = { askingPregnancy = false },-        )-    }-    if (askingSmoking) {-        AboutYouOptionDialog(-            title = stringResource(R.string.about_you_smoking_question),-            options = SmokingStatus.entries.map { stringResource(it.labelRes()) },-            selectedIndex = SmokingStatus.entries.indexOf(profile.smokingStatus),-            onPick = { index ->-                viewModel.setSmokingStatus(SmokingStatus.entries[index])-                askingSmoking = false-            },-            onDismiss = { askingSmoking = false },-        )-    }-     val rows = buildList {         add(             AboutYouRow(                 headline = stringResource(R.string.about_you_pregnancy_question),                 supporting = stringResource(profile.pregnancyStatus.labelRes()),-                onClick = { askingPregnancy = true },+                onClick = { backStack.add(Route.PregnancyStatusDialog) },             ),         )         if (profile.pregnancyStatus == PregnancyStatus.Pregnant) {@@ -151,7 +96,7 @@ fun MedicalAboutYouSection(             AboutYouRow(                 headline = stringResource(R.string.about_you_smoking_question),                 supporting = stringResource(profile.smokingStatus.labelRes()),-                onClick = { askingSmoking = true },+                onClick = { backStack.add(Route.SmokingStatusDialog) },             ),         )         SocialHistoryQuestions.ALL.forEach { question ->@@ -162,7 +107,7 @@ fun MedicalAboutYouSection(                     headline = stringResource(question.titleRes),                     supporting = selected?.let { stringResource(it.labelRes) }                         ?: stringResource(R.string.not_answered),-                    onClick = { askingQuestion = question },+                    onClick = { backStack.add(Route.SocialHistoryAnswerDialog(question.loinc)) },                 ),             )         }@@ -193,50 +138,6 @@ private data class AboutYouRow(     val onClick: () -> Unit, ) -/** Picks one option from a short list, dismissing on choice like [AnswerPickerDialog] does. */-@Composable-private fun AboutYouOptionDialog(-    title: String,-    options: List<String>,-    selectedIndex: Int,-    onPick: (Int) -> Unit,-    onDismiss: () -> Unit,-) {-    AlertDialog(-        onDismissRequest = onDismiss,-        title = { Text(title) },-        text = {-            Column(-                modifier = Modifier.verticalScroll(rememberScrollState()),-                verticalArrangement = Arrangement.spacedBy(4.dp),-            ) {-                options.forEachIndexed { index, label ->-                    Row(-                        modifier = Modifier-                            .fillMaxWidth()-                            .selectable(-                                selected = index == selectedIndex,-                                onClick = { onPick(index) },-                                role = Role.RadioButton,-                            ),-                        verticalAlignment = Alignment.CenterVertically,-                        horizontalArrangement = Arrangement.spacedBy(8.dp),-                    ) {-                        RadioButton(-                            selected = index == selectedIndex,-                            onClick = null,-                        )-                        Text(label, style = MaterialTheme.typography.bodyLarge)-                    }-                }-            }-        },-        confirmButton = {-            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }-        },-    )-}- internal fun PregnancyStatus.labelRes() = when (this) {     PregnancyStatus.Unknown -> R.string.answer_unknown     PregnancyStatus.Pregnant -> R.string.pregnancy_pregnant
health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt b/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.ktindex 4702579e16..dfc34772b6 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt@@ -1,11 +1,21 @@ package com.vayunmathur.health.ui  import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue import androidx.compose.ui.res.stringResource import com.vayunmathur.health.R import com.vayunmathur.health.Route import com.vayunmathur.health.platform.HealthViewModel import com.vayunmathur.health.platform.MedicalViewModel+import com.vayunmathur.health.platform.clearSocialHistoryAnswer+import com.vayunmathur.health.platform.setPregnancyStatus+import com.vayunmathur.health.platform.setSmokingStatus+import com.vayunmathur.health.platform.setSocialHistoryAnswer+import com.vayunmathur.health.platform.toLocalDate import com.vayunmathur.library.ui.IconBodySystem import com.vayunmathur.library.ui.IconFavorite import com.vayunmathur.library.ui.IconFire@@ -81,6 +91,42 @@ internal fun EntryProviderScope<Route>.fitnessEntries(     entry<Route.ExerciseDetails>(metadata = MorphPage()) {         ExerciseDetailsPage(backStack, viewModel)     }+    entry<Route.LogBodyMetricDialog>(metadata = DialogPage()) {+        LogBodyMetricDialog(viewModel = viewModel, config = it.config, onDismiss = { backStack.pop() })+    }+    entry<Route.LogHydrationDialog>(metadata = DialogPage()) {+        LogHydrationDialog(viewModel = viewModel, initialTime = null, onDismiss = { backStack.pop() })+    }+    entry<Route.LogMealDialog>(metadata = DialogPage()) {+        LogMealDialog(viewModel = viewModel, initialTime = null, onDismiss = { backStack.pop() })+    }+    entry<Route.AddIngredientDialog>(metadata = DialogPage()) {+        IngredientSearchDialog(+            viewModel = viewModel,+            onDismiss = { backStack.pop() },+            onIngredientSelected = { ingredient ->+                viewModel.insertIngredient(ingredient)+                backStack.pop()+            },+        )+    }+    entry<Route.RenameIngredientDialog>(metadata = DialogPage()) { route ->+        val ingredients by viewModel.allIngredients.collectAsState(emptyList())+        val ingredient = ingredients.firstOrNull { it.id == route.ingredientId }+        if (ingredient != null) {+            var customName by remember(ingredient.id) { mutableStateOf(ingredient.customName ?: "") }+            com.vayunmathur.health.ui.dialogs.RenameIngredientDialogContent(+                originalName = ingredient.originalName,+                customName = customName,+                onCustomNameChange = { customName = it },+                onConfirm = {+                    viewModel.updateIngredient(ingredient.copy(customName = customName.ifBlank { null }))+                    backStack.pop()+                },+                onDismiss = { backStack.pop() },+            )+        }+    } }  /** Medical records destinations. */@@ -115,4 +161,59 @@ internal fun EntryProviderScope<Route>.medicalEntries(     entry<Route.MedicalTimePicker>(metadata = DialogPage()) {         TimePickerDialogContent(backStack, it.key, it.initialTime)     }+    entry<Route.SocialHistoryAnswerDialog>(metadata = DialogPage()) { route ->+        val answers by medicalViewModel.profileAnswers.collectAsState()+        val question = com.vayunmathur.health.domain.SocialHistoryQuestions.ALL+            .firstOrNull { it.loinc == route.loinc }+        if (question != null) {+            com.vayunmathur.health.ui.components.AnswerPickerDialog(+                question = question,+                selected = question.answers+                    .firstOrNull { it.code == answers[question.loinc]?.answerCode },+                onPick = { picked ->+                    if (picked == null) {+                        medicalViewModel.clearSocialHistoryAnswer(question)+                    } else {+                        medicalViewModel.setSocialHistoryAnswer(question, picked)+                    }+                    backStack.pop()+                },+                onDismiss = { backStack.pop() },+            )+        }+    }+    entry<Route.PregnancyStatusDialog>(metadata = DialogPage()) {+        val profile by medicalViewModel.profile.collectAsState()+        com.vayunmathur.health.ui.dialogs.AboutYouOptionDialog(+            title = stringResource(R.string.about_you_pregnancy_question),+            options = com.vayunmathur.health.data.PregnancyStatus.entries.map { stringResource(it.labelRes()) },+            selectedIndex = com.vayunmathur.health.data.PregnancyStatus.entries.indexOf(profile.pregnancyStatus),+            onPick = { index ->+                val picked = com.vayunmathur.health.data.PregnancyStatus.entries[index]+                medicalViewModel.setPregnancyStatus(+                    picked,+                    if (picked == com.vayunmathur.health.data.PregnancyStatus.Pregnant) {+                        profile.dueDate?.toLocalDate()+                    } else {+                        null+                    },+                )+                backStack.pop()+            },+            onDismiss = { backStack.pop() },+        )+    }+    entry<Route.SmokingStatusDialog>(metadata = DialogPage()) {+        val profile by medicalViewModel.profile.collectAsState()+        com.vayunmathur.health.ui.dialogs.AboutYouOptionDialog(+            title = stringResource(R.string.about_you_smoking_question),+            options = com.vayunmathur.health.data.SmokingStatus.entries.map { stringResource(it.labelRes()) },+            selectedIndex = com.vayunmathur.health.data.SmokingStatus.entries.indexOf(profile.smokingStatus),+            onPick = { index ->+                medicalViewModel.setSmokingStatus(com.vayunmathur.health.data.SmokingStatus.entries[index])+                backStack.pop()+            },+            onDismiss = { backStack.pop() },+        )+    } }
health/src/main/java/com/vayunmathur/health/ui/NutritionDetailsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/NutritionDetailsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/NutritionDetailsPage.ktindex d0c4f27545..0910904e8a 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NutritionDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NutritionDetailsPage.kt@@ -81,61 +81,74 @@ fun NutritionDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewMo                 otherNutrients.map { it to it.accessor(nutritionTotals) } +                     (hydrationNutrient to hydrationTotal) -            LazyColumn(-                modifier = Modifier.fillMaxSize(),-                verticalArrangement = Arrangement.spacedBy(16.dp),-                contentPadding = PaddingValues(-                    top = 8.dp + padding.calculateTopPadding(),-                    bottom = 24.dp + padding.calculateBottomPadding()-                )-            ) {-                item {-                    Text(-                        text = if (day == today) stringResource(R.string.nav_today) else day.displayString(),-                        style = MaterialTheme.typography.titleMedium,-                        color = MaterialTheme.colorScheme.onSurfaceVariant,-                        modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),-                    )-                }+            NutritionBreakdownContent(+                dayLabel = if (day == today) stringResource(R.string.nav_today) else day.displayString(),+                breakdownRows = breakdownRows,+                allLogs = allLogs,+                onDeleteLog = { viewModel.deleteRecord(it) },+                topPadding = 8.dp + padding.calculateTopPadding(),+                bottomPadding = 24.dp + padding.calculateBottomPadding(),+            )+        }+    }+} -                if (allLogs.isNotEmpty()) {-                    item {-                        DashboardSection(title = "Logged today", accentColor = HealthColors.Nutrition) {-                            allLogs.forEachIndexed { idx, log ->-                                if (idx > 0) DashboardSectionDivider(insetStart = 16.dp)-                                val headline = log.metadata-                                    ?: if (log.type == RecordType.Hydration) "Hydration" else "Meal"-                                val supporting = if (log.type == RecordType.Nutrition) {-                                    "${log.nutritionData?.calories?.round(0)?.toInt() ?: 0} kcal • " +-                                        "${log.nutritionData?.protein?.round(1) ?: 0}g P • " +-                                        "${log.nutritionData?.carbohydrates?.round(1) ?: 0}g C • " +-                                        "${log.nutritionData?.fat?.round(1) ?: 0}g F"-                                } else {-                                    "${log.value.round(2)} L"-                                }-                                HealthRow(-                                    headline = headline,-                                    supporting = supporting,-                                    trailing = {-                                        IconButton(onClick = { viewModel.deleteRecord(log) }) {-                                            IconDelete(-                                                tint = MaterialTheme.colorScheme.error-                                            )-                                        }-                                    }-                                )-                            }+/** Stateless per-day nutrition breakdown: logged meals/hydration plus nutrient progress rows. */+@Composable+internal fun NutritionBreakdownContent(+    dayLabel: String,+    breakdownRows: List<Pair<NutrientDV, Double>>,+    allLogs: List<com.vayunmathur.health.data.Record>,+    onDeleteLog: (com.vayunmathur.health.data.Record) -> Unit,+    topPadding: androidx.compose.ui.unit.Dp = 8.dp,+    bottomPadding: androidx.compose.ui.unit.Dp = 24.dp,+) {+    LazyColumn(+        modifier = Modifier.fillMaxSize(),+        verticalArrangement = Arrangement.spacedBy(16.dp),+        contentPadding = PaddingValues(top = topPadding, bottom = bottomPadding),+    ) {+        item {+            Text(+                text = dayLabel,+                style = MaterialTheme.typography.titleMedium,+                color = MaterialTheme.colorScheme.onSurfaceVariant,+                modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp),+            )+        }+        if (allLogs.isNotEmpty()) {+            item {+                DashboardSection(title = "Logged today", accentColor = HealthColors.Nutrition) {+                    allLogs.forEachIndexed { idx, log ->+                        if (idx > 0) DashboardSectionDivider(insetStart = 16.dp)+                        val headline = log.metadata+                            ?: if (log.type == RecordType.Hydration) "Hydration" else "Meal"+                        val supporting = if (log.type == RecordType.Nutrition) {+                            "${log.nutritionData?.calories?.round(0)?.toInt() ?: 0} kcal • " ++                                "${log.nutritionData?.protein?.round(1) ?: 0}g P • " ++                                "${log.nutritionData?.carbohydrates?.round(1) ?: 0}g C • " ++                                "${log.nutritionData?.fat?.round(1) ?: 0}g F"+                        } else {+                            "${log.value.round(2)} L"                         }+                        HealthRow(+                            headline = headline,+                            supporting = supporting,+                            trailing = {+                                IconButton(onClick = { onDeleteLog(log) }) {+                                    IconDelete(tint = MaterialTheme.colorScheme.error)+                                }+                            },+                        )                     }                 }--                item {-                    DashboardSection(title = "Nutrient breakdown", accentColor = HealthColors.Nutrition) {-                        breakdownRows.forEachIndexed { idx, (nutrient, value) ->-                            if (idx > 0) DashboardSectionDivider(insetStart = 16.dp)-                            NutrientProgressRow(nutrient, value)-                        }-                    }+            }+        }+        item {+            DashboardSection(title = "Nutrient breakdown", accentColor = HealthColors.Nutrition) {+                breakdownRows.forEachIndexed { idx, (nutrient, value) ->+                    if (idx > 0) DashboardSectionDivider(insetStart = 16.dp)+                    NutrientProgressRow(nutrient, value)                 }             }         }
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 571a60305d..210a9a8b25 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt@@ -127,16 +127,6 @@ fun NutritionPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {         viewModel.getAllRecordsInRange(RecordType.Nutrition, dayStart, dayEnd)     }.collectAsState(emptyList()) -    var showHydrationDialog by remember { mutableStateOf(false) }-    var showMealDialog by remember { mutableStateOf(false) }--    if (showHydrationDialog) {-        LogHydrationDialog(viewModel = viewModel, initialTime = null, onDismiss = { showHydrationDialog = false })-    }-    if (showMealDialog) {-        LogMealDialog(viewModel = viewModel, initialTime = null, onDismiss = { showMealDialog = false })-    }-     NutritionScreen(         state = NutritionUiState(             totals = totals,@@ -145,11 +135,11 @@ fun NutritionPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {         ),         actions = object : NutritionActions {             override fun logHydration() {-                showHydrationDialog = true+                backStack.add(Route.LogHydrationDialog)             }              override fun logMeal() {-                showMealDialog = true+                backStack.add(Route.LogMealDialog)             }              override fun openRecipes() {
health/src/main/java/com/vayunmathur/health/ui/RecipeEditorPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/RecipeEditorPage.kt b/health/src/main/java/com/vayunmathur/health/ui/RecipeEditorPage.ktindex addcd40d88..250097c495 100644--- a/health/src/main/java/com/vayunmathur/health/ui/RecipeEditorPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/RecipeEditorPage.kt@@ -2,6 +2,8 @@  package com.vayunmathur.health.ui +// DIALOG LOCAL EXCEPTION: ingredient search -> quantity is a chained two-step flow that passes a non-serializable Ingredient and ServingUnit between steps and mutates the editor-local draft list (identity-matched on confirm); there is no route/result shape for Ingredient yet, so the quantity step cannot be a route without a ViewModel draft stash+ import kotlin.uuid.Uuid import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement@@ -118,49 +120,19 @@ fun RecipeEditorPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel,         title = if (recipeId == null) stringResource(R.string.create_recipe) else stringResource(R.string.edit_recipe),         backStack = backStack,     ) { padding ->-        Column(modifier = Modifier.padding(padding).padding(16.dp).fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp)) {-            OutlinedTextField(-                value = recipeName,-                onValueChange = { recipeName = it },-                label = { Text(stringResource(R.string.recipe_name)) },-                modifier = Modifier.fillMaxWidth()-            )--            Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {-                Text(stringResource(R.string.ingredients), style = MaterialTheme.typography.titleMedium)-                TextButton(onClick = { showSearch = true }) {-                    IconAdd()-                    Spacer(Modifier.width(4.dp))-                    Text(stringResource(UiR.string.add))-                }-            }--            LazyColumn(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {-                items(recipeIngredients, key = { it.ingredient.id }) { riData ->-                    Card(-                        modifier = Modifier.fillMaxWidth().clickable {-                            editingIngredientData = riData-                            isAddingNewIngredient = false-                        }-                    ) {-                        Row(modifier = Modifier.padding(8.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {-                            Column(modifier = Modifier.weight(1f)) {-                                Text(riData.ingredient.displayName, style = MaterialTheme.typography.bodyLarge)-                                Text("${riData.quantity} ${riData.unit.name}", style = MaterialTheme.typography.bodySmall)-                            }-                            IconButton(onClick = {-                                recipeIngredients = recipeIngredients - riData-                            }) {-                                IconDelete()-                            }-                        }-                    }-                }-            }--            Button(-                onClick = {-                    if (saving) return@Button+        RecipeEditorContent(+            recipeName = recipeName,+            onRecipeNameChange = { recipeName = it },+            recipeIngredients = recipeIngredients,+            saveEnabled = recipeName.isNotBlank() && recipeIngredients.isNotEmpty() && !saving,+            onAddIngredient = { showSearch = true },+            onEditIngredient = { riData ->+                editingIngredientData = riData+                isAddingNewIngredient = false+            },+            onDeleteIngredient = { riData -> recipeIngredients = recipeIngredients - riData },+            onSave = {+                if (!saving) {                     saving = true                     val items = recipeIngredients.map {                         HealthViewModel.RecipeIngredientLoad(it.ingredient, it.unit, it.quantity)@@ -168,13 +140,59 @@ fun RecipeEditorPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel,                     viewModel.saveRecipe(recipeId, recipeName, items) {                         backStack.pop()                     }-                },-                modifier = Modifier.fillMaxWidth(),-                enabled = recipeName.isNotBlank() && recipeIngredients.isNotEmpty() && !saving-            ) {-                Text(stringResource(R.string.save_recipe))+                }+            },+            modifier = Modifier.padding(padding),+        )+    }+}++/** Stateless recipe editor: name field, ingredient list and save action. */+@Composable+internal fun RecipeEditorContent(+    recipeName: String,+    onRecipeNameChange: (String) -> Unit,+    recipeIngredients: List<RecipeIngredientData>,+    saveEnabled: Boolean,+    onAddIngredient: () -> Unit,+    onEditIngredient: (RecipeIngredientData) -> Unit,+    onDeleteIngredient: (RecipeIngredientData) -> Unit,+    onSave: () -> Unit,+    modifier: Modifier = Modifier,+) {+    Column(modifier = modifier.padding(16.dp).fillMaxSize(), verticalArrangement = Arrangement.spacedBy(16.dp)) {+        OutlinedTextField(+            value = recipeName,+            onValueChange = onRecipeNameChange,+            label = { Text(stringResource(R.string.recipe_name)) },+            modifier = Modifier.fillMaxWidth(),+        )+        Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {+            Text(stringResource(R.string.ingredients), style = MaterialTheme.typography.titleMedium)+            TextButton(onClick = onAddIngredient) {+                IconAdd()+                Spacer(Modifier.width(4.dp))+                Text(stringResource(UiR.string.add))+            }+        }+        LazyColumn(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp)) {+            items(recipeIngredients, key = { it.ingredient.id }) { riData ->+                Card(modifier = Modifier.fillMaxWidth().clickable { onEditIngredient(riData) }) {+                    Row(modifier = Modifier.padding(8.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {+                        Column(modifier = Modifier.weight(1f)) {+                            Text(riData.ingredient.displayName, style = MaterialTheme.typography.bodyLarge)+                            Text("${riData.quantity} ${riData.unit.name}", style = MaterialTheme.typography.bodySmall)+                        }+                        IconButton(onClick = { onDeleteIngredient(riData) }) {+                            IconDelete()+                        }+                    }+                }             }         }+        Button(onClick = onSave, modifier = Modifier.fillMaxWidth(), enabled = saveEnabled) {+            Text(stringResource(R.string.save_recipe))+        }     } } 
health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt b/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.ktindex d5851ccf72..edac71a8e3 100644--- a/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt@@ -66,24 +66,11 @@ import java.text.NumberFormat @Composable fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {     var selectedTab by remember { mutableIntStateOf(0) }-    var showIngredientSearch by remember { mutableStateOf(false) }-     val recipes by viewModel.allRecipes.collectAsState(emptyList())     val ingredients by viewModel.allIngredients.collectAsState(emptyList())      val isListEmpty = if (selectedTab == 0) recipes.isEmpty() else ingredients.isEmpty() -    if (showIngredientSearch) {-        IngredientSearchDialog(-            viewModel = viewModel,-            onDismiss = { showIngredientSearch = false },-            onIngredientSelected = { ingredient ->-                viewModel.insertIngredient(ingredient)-                showIngredientSearch = false-            }-        )-    }-     AppScaffold(         title = stringResource(R.string.recipes),         backStack = backStack,@@ -93,7 +80,7 @@ fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewMo                     if (selectedTab == 0) {                         backStack.add(Route.RecipeEditor())                      } else {-                        showIngredientSearch = true+                        backStack.add(Route.AddIngredientDialog)                     }                 }) {                     IconAdd()@@ -122,7 +109,7 @@ fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewMo                         if (selectedTab == 0) {                             backStack.add(Route.RecipeEditor())                         } else {-                            showIngredientSearch = true+                            backStack.add(Route.AddIngredientDialog)                         }                     }) {                         IconAdd()@@ -132,9 +119,15 @@ fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewMo                 }             } else {                 if (selectedTab == 0) {-                    RecipesList(recipes, viewModel) { recipeId -> backStack.add(Route.RecipeEditor(recipeId)) }+                    RecipesList(recipes, onDeleteRecipe = { viewModel.deleteRecipe(it) }) { recipeId -> backStack.add(Route.RecipeEditor(recipeId)) }                 } else {-                    IngredientsList(ingredients, viewModel)+                    IngredientsList(+                        ingredients,+                        onToggleIngredient = { viewModel.updateIngredient(it.copy(isRecipe = !it.isRecipe)) },+                        onDeleteIngredient = { viewModel.deleteIngredient(it) },+                    ) { ingredient ->+                        backStack.add(Route.RenameIngredientDialog(ingredient.id))+                    }                 }             }         }@@ -142,7 +135,7 @@ fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewMo }  @Composable-private fun RecipesList(recipes: List<Recipe>, viewModel: HealthViewModel, onRecipeClick: (String) -> Unit) {+internal fun RecipesList(recipes: List<Recipe>, onDeleteRecipe: (Recipe) -> Unit, onRecipeClick: (String) -> Unit) {     LazyColumn(modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {         items(recipes, key = { it.id }) { recipe ->             Card(@@ -150,7 +143,7 @@ private fun RecipesList(recipes: List<Recipe>, viewModel: HealthViewModel, onRec             ) {                 Row(modifier = Modifier.padding(16.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {                     Text(recipe.name, style = MaterialTheme.typography.titleMedium, color = HealthColors.Nutrition)-                    IconButton(onClick = { viewModel.deleteRecipe(recipe) }) {+                    IconButton(onClick = { onDeleteRecipe(recipe) }) {                         IconDelete()                     }                 }@@ -160,41 +153,15 @@ private fun RecipesList(recipes: List<Recipe>, viewModel: HealthViewModel, onRec }  @Composable-private fun IngredientsList(ingredients: List<Ingredient>, viewModel: HealthViewModel) {-    var editingIngredient by remember { mutableStateOf<Ingredient?>(null) }-    -    if (editingIngredient != null) {-        var customName by remember { mutableStateOf(editingIngredient!!.customName ?: "") }-        AlertDialog(-            onDismissRequest = { editingIngredient = null },-            title = { Text(stringResource(R.string.rename_ingredient)) },-            text = {-                Column {-                    Text(stringResource(R.string.original_1, editingIngredient!!.originalName), style = MaterialTheme.typography.bodySmall)-                    Spacer(Modifier.height(8.dp))-                    OutlinedTextField(-                        value = customName,-                        onValueChange = { customName = it },-                        label = { Text(stringResource(R.string.custom_name)) }-                    )-                }-            },-            confirmButton = {-                Button(onClick = {-                    val newIng = editingIngredient!!.copy(customName = customName.ifBlank { null })-                    viewModel.updateIngredient(newIng)-                    editingIngredient = null-                }) { Text(stringResource(UiR.string.save)) }-            },-            dismissButton = {-                TextButton(onClick = { editingIngredient = null }) { Text(stringResource(UiR.string.cancel)) }-            }-        )-    }-+internal fun IngredientsList(+    ingredients: List<Ingredient>,+    onToggleIngredient: (Ingredient) -> Unit,+    onDeleteIngredient: (Ingredient) -> Unit,+    onRenameIngredient: (Ingredient) -> Unit,+) {     LazyColumn(modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {         items(ingredients, key = { it.id }) { ingredient ->-            Card(modifier = Modifier.fillMaxWidth().clickable { editingIngredient = ingredient }) {+            Card(modifier = Modifier.fillMaxWidth().clickable { onRenameIngredient(ingredient) }) {                 Row(modifier = Modifier.padding(16.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {                     Column(modifier = Modifier.weight(1f)) {                         Text(ingredient.displayName, style = MaterialTheme.typography.titleMedium)@@ -203,12 +170,10 @@ private fun IngredientsList(ingredients: List<Ingredient>, viewModel: HealthView                         }                     }                     Row(verticalAlignment = Alignment.CenterVertically) {-                        IconButton(onClick = {-                            viewModel.updateIngredient(ingredient.copy(isRecipe = !ingredient.isRecipe))-                        }) {+                        IconButton(onClick = { onToggleIngredient(ingredient) }) {                             if (ingredient.isRecipe) IconFire() else IconFire(tint = MaterialTheme.colorScheme.outline)                         }-                        IconButton(onClick = { viewModel.deleteIngredient(ingredient) }) {+                        IconButton(onClick = { onDeleteIngredient(ingredient) }) {                             IconDelete()                         }                     }
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 7fc0277c59..08b035b3e7 100644--- a/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/SleepDetailsPage.kt@@ -141,37 +141,39 @@ fun SleepDetailsPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel)                     .collectAsState(null)                 val hasLoaded by viewModel.hasLoadedRecords.collectAsState() -                LazyColumn(-                    modifier = Modifier-                        .fillMaxSize()-                        .padding(horizontal = 16.dp),-                    verticalArrangement = Arrangement.spacedBy(24.dp),-                    contentPadding = PaddingValues(bottom = 24.dp)-                ) {-                    record?.let { r ->-                        val sleepData = r.sleepData-                        if (sleepData != null) {-                            item { SleepSummaryHeader(r) }-                            item { SleepStageGraph(r) }-                            item { SleepStageBreakdown(sleepData) }-                        }-                    } ?: item {-                        Box(-                            Modifier.fillParentMaxSize(), contentAlignment = Alignment.Center-                        ) {-                            if (!hasLoaded) {-                                Text("Loading…")-                            } else {-                                Text(-                                    stringResource(R.string.no_data_available),-                                    color = MaterialTheme.colorScheme.outline-                                )-                            }-                        }-                    }-                }+                SleepDayContent(record = record, hasLoaded = hasLoaded)             }         }     } } ++/** Stateless one-day sleep content: summary, hypnogram graph and stage breakdown, or the empty state. */+@Composable+internal fun SleepDayContent(record: Record?, hasLoaded: Boolean) {+    LazyColumn(+        modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp),+        verticalArrangement = Arrangement.spacedBy(24.dp),+        contentPadding = PaddingValues(bottom = 24.dp),+    ) {+        record?.let { r ->+            val sleepData = r.sleepData+            if (sleepData != null) {+                item { SleepSummaryHeader(r) }+                item { SleepStageGraph(r) }+                item { SleepStageBreakdown(sleepData) }+            }+        } ?: item {+            Box(Modifier.fillParentMaxSize(), contentAlignment = Alignment.Center) {+                if (!hasLoaded) {+                    Text("Loading…")+                } else {+                    Text(+                        stringResource(R.string.no_data_available),+                        color = MaterialTheme.colorScheme.outline,+                    )+                }+            }+        }+    }+}
health/src/main/java/com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.kt b/health/src/main/java/com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.ktnew file mode 100644index 0000000000..f7090455b0--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/dialogs/AboutYouOptionDialog.kt@@ -0,0 +1,65 @@+package com.vayunmathur.health.ui.dialogs++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.selection.selectable+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.semantics.Role+import androidx.compose.ui.unit.dp+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.RadioButton+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/** Picks one option from a short list, dismissing on choice. */+@Composable+fun AboutYouOptionDialog(+    title: String,+    options: List<String>,+    selectedIndex: Int,+    onPick: (Int) -> Unit,+    onDismiss: () -> Unit,+) {+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(title) },+        text = {+            Column(+                modifier = Modifier.verticalScroll(rememberScrollState()),+                verticalArrangement = Arrangement.spacedBy(4.dp),+            ) {+                options.forEachIndexed { index, label ->+                    Row(+                        modifier = Modifier+                            .fillMaxWidth()+                            .selectable(+                                selected = index == selectedIndex,+                                onClick = { onPick(index) },+                                role = Role.RadioButton,+                            ),+                        verticalAlignment = Alignment.CenterVertically,+                        horizontalArrangement = Arrangement.spacedBy(8.dp),+                    ) {+                        RadioButton(+                            selected = index == selectedIndex,+                            onClick = null,+                        )+                        Text(label, style = MaterialTheme.typography.bodyLarge)+                    }+                }+            }+        },+        confirmButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
health/src/main/java/com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.kt b/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.ktnew file mode 100644index 0000000000..2118f881be--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogBodyMetricDialogContent.kt@@ -0,0 +1,51 @@+package com.vayunmathur.health.ui.dialogs++import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.input.KeyboardType+import com.vayunmathur.health.R+import com.vayunmathur.health.ui.HealthMetricConfig+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/** Stateless body-metric logging dialog: a value field for [config] reporting the entered value. */+@Composable+fun LogBodyMetricDialogContent(+    config: HealthMetricConfig,+    value: String,+    onValueChange: (String) -> Unit,+    onConfirm: (Double) -> Unit,+    onDismiss: () -> Unit,+) {+    val parsed = value.toDoubleOrNull()+    val isValid = parsed != null && parsed > 0+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.log_body_metric, stringResource(config.titleRes))) },+        text = {+            OutlinedTextField(+                value = value,+                onValueChange = onValueChange,+                label = { Text(stringResource(config.titleRes)) },+                suffix = { Text(config.unit) },+                singleLine = true,+                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),+                modifier = Modifier.fillMaxWidth(),+            )+        },+        confirmButton = {+            Button(+                enabled = isValid,+                onClick = { if (parsed != null) onConfirm(parsed) },+            ) { Text(stringResource(UiR.string.save)) }+        },+        dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) } },+    )+}
health/src/main/java/com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.kt b/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.ktnew file mode 100644index 0000000000..40c4d64a6f--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/dialogs/LogHydrationDialogContent.kt@@ -0,0 +1,98 @@+package com.vayunmathur.health.ui.dialogs++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.text.KeyboardOptions+import androidx.compose.runtime.Composable+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.res.stringResource+import androidx.compose.ui.text.input.KeyboardType+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.R+import com.vayunmathur.health.ui.HydrationUnit+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.DropdownMenu+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.IconArrowDropDown+import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.SelectableDropdownMenuItem+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/** Stateless hydration logging dialog: a quantity and a unit, reporting the chosen values. */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun LogHydrationDialogContent(+    quantity: String,+    onQuantityChange: (String) -> Unit,+    selectedUnit: HydrationUnit,+    onUnitChange: (HydrationUnit) -> Unit,+    onConfirm: (Double, HydrationUnit) -> Unit,+    onDismiss: () -> Unit,+) {+    var unitExpanded by remember { mutableStateOf(false) }+    val parsed = quantity.toDoubleOrNull()+    val isValid = parsed != null && parsed > 0+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.log_hydration)) },+        text = {+            Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {+                OutlinedTextField(+                    value = quantity,+                    onValueChange = onQuantityChange,+                    label = { Text(stringResource(R.string.quantity)) },+                    keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),+                    modifier = Modifier.fillMaxWidth(),+                    trailingIcon = {+                        Row(+                            modifier = Modifier.clickable { unitExpanded = true },+                            verticalAlignment = Alignment.CenterVertically,+                        ) {+                            Text(+                                stringResource(selectedUnit.displayName),+                                style = MaterialTheme.typography.bodyMedium,+                            )+                            IconArrowDropDown()+                        }+                        DropdownMenu(+                            expanded = unitExpanded,+                            onDismissRequest = { unitExpanded = false },+                        ) {+                            HydrationUnit.entries.forEach { unit ->+                                SelectableDropdownMenuItem(+                                    selected = unit == selectedUnit,+                                    onClick = {+                                        onUnitChange(unit)+                                        unitExpanded = false+                                    },+                                    text = { Text(stringResource(unit.displayName)) },+                                    selectedLeadingIcon = { IconCheck() },+                                )+                            }+                        }+                    },+                )+            }+        },+        confirmButton = {+            Button(+                enabled = isValid,+                onClick = { if (parsed != null) onConfirm(parsed, selectedUnit) },+            ) { Text(stringResource(UiR.string.save)) }+        },+        dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) } },+    )+}
health/src/main/java/com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.kt b/health/src/main/java/com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.ktnew file mode 100644index 0000000000..0f754dec0e--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/dialogs/RenameIngredientDialogContent.kt@@ -0,0 +1,49 @@+package com.vayunmathur.health.ui.dialogs++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.height+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import com.vayunmathur.health.R+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.R as UiR++/** Stateless rename-ingredient dialog: edits the custom name for an ingredient. */+@Composable+fun RenameIngredientDialogContent(+    originalName: String,+    customName: String,+    onCustomNameChange: (String) -> Unit,+    onConfirm: () -> Unit,+    onDismiss: () -> Unit,+) {+    AlertDialog(+        onDismissRequest = onDismiss,+        title = { Text(stringResource(R.string.rename_ingredient)) },+        text = {+            Column {+                Text(stringResource(R.string.original_1, originalName), style = MaterialTheme.typography.bodySmall)+                Spacer(Modifier.height(8.dp))+                OutlinedTextField(+                    value = customName,+                    onValueChange = onCustomNameChange,+                    label = { Text(stringResource(R.string.custom_name)) },+                )+            }+        },+        confirmButton = {+            Button(onClick = onConfirm) { Text(stringResource(UiR.string.save)) }+        },+        dismissButton = {+            TextButton(onClick = onDismiss) { Text(stringResource(UiR.string.cancel)) }+        },+    )+}
health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt
diff --git a/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt b/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.ktindex 6eb48d798c..562d21afcc 100644--- a/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt+++ b/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt@@ -70,15 +70,17 @@ private val TODAY = LocalDate(2026, 1, 17)  * from the device wallpaper, which does not exist here, so these render with the fallback  * scheme rather than a user's actual accent colour.  *- * Coverage: `Today` and `NutritionDetails` tabs, `BarChartDetails` (steps + heart- * rate), the dose-reminder full screen and the Health-Connect-required gate on- * phone, plus the metric detail on large-tablet (the main tab's detail pane).- * Exceptions (no stateless slice; HealthViewModel/MedicalViewModel over Health- * Connect + Room + the bundled food database): `Body`, `Medical`,- * `NutritionFullBreakdown`, `RecipeManagement`/`RecipeEditor`, `SleepDetails`,- * `ExerciseDetails` and the medical editors (`EditVaccination`/`EditMedication`/- * `EditAllergy`/`EditCondition`/`EditLabResult`/`CatalogPicker`) are not- * preview-rendered. Date/time-picker dialog routes are dialogs, not full screens.+ * Coverage: `Today`, `Body` and `NutritionDetails` tabs, `BarChartDetails`+ * (steps + heart rate), `NutritionFullBreakdown`, `RecipeManagement`,+ * `RecipeEditor`, `SleepDetails`, `ExerciseDetails`, the medical date/time+ * picker dialog routes and the log-body-metric, log-hydration, social-history,+ * pregnancy, smoking and rename-ingredient dialog routes, the dose-reminder+ * full screen and the Health-Connect-required gate on phone, plus the metric+ * detail on large-tablet (the main tab's detail pane). The remaining routes+ * are exempted in Route.kt: `Medical` and the medical editors+ * (`EditVaccination`/`EditMedication`/`EditAllergy`/`EditCondition`/+ * `EditLabResult`/`CatalogPicker`) plus the log-meal and add-ingredient+ * dialogs read ViewModel drafts/flows with no stateless slice.  */ class MetadataPreviews { @@ -110,7 +112,7 @@ class MetadataPreviews {     }      @PreviewTest-    @Preview(name = "2-nutrition", device = PHONE, group = "phone", showSystemUi = true)+    @Preview(name = "2-nutrition-details", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview2Nutrition() {         ChromePreview(Route.NutritionDetails) {@@ -131,7 +133,7 @@ class MetadataPreviews {     }      @PreviewTest-    @Preview(name = "3-steps", device = PHONE, group = "phone", showSystemUi = true)+    @Preview(name = "3-bar-chart-details", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview3Steps() {         // A week of steps: seven daily sums, newest first in the history list, which is the@@ -175,7 +177,7 @@ class MetadataPreviews {     }      @PreviewTest-    @Preview(name = "4-heart-rate", device = PHONE, group = "phone", showSystemUi = true)+    @Preview(name = "4-bar-chart-details-heart-rate", device = PHONE, group = "phone", showSystemUi = true)     @Composable     fun Preview4HeartRate() {         // Heart rate is the one metric with no period tabs: it is always the hourly line for@@ -206,7 +208,7 @@ class MetadataPreviews {     }      @PreviewTest-    @Preview(name = "5-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)+    @Preview(name = "5-bar-chart-details-expanded", device = EXPANDED, group = "large-tablet", showSystemUi = true)     @Composable     fun Preview5Expanded() {         // The detail screen at desktop width: the week-of-steps chart a metric row opens.@@ -303,6 +305,278 @@ class MetadataPreviews {         }     } ++    @PreviewTest+    @Preview(name = "10-body", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview10Body() {+        ChromePreview(Route.Body) {+            BodyScreen(+                metrics = com.vayunmathur.health.platform.MainPageMetrics(+                    weight = 72.5,+                    height = 1.75,+                    bodyFat = 18.2,+                    leanBodyMass = 55.1,+                    boneMass = 3.0,+                    bodyWaterMass = 38.4,+                ),+                onMetricClick = {},+                onLogClick = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "11-nutrition-full-breakdown", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview11NutritionFullBreakdown() {+        DynamicTheme(darkTheme = true) {+            NutritionBreakdownContent(+                dayLabel = "Saturday, January 17",+                breakdownRows = listOf(+                    nutrientCatalog[3] to 18.0,+                    nutrientCatalog[4] to 12.5,+                    nutrientCatalog[5] to 1240.0,+                    nutrientCatalog[11] to 64.0,+                    hydrationNutrient to 1.85,+                ),+                allLogs = listOf(+                    com.vayunmathur.health.data.Record(+                        id = "meal-1",+                        index = 0,+                        type = com.vayunmathur.health.data.RecordType.Nutrition,+                        startTime = java.time.Instant.parse("2026-01-17T12:00:00Z"),+                        endTime = java.time.Instant.parse("2026-01-17T12:30:00Z"),+                        value = 1.0,+                        nutritionData = NutritionData(protein = 30.0, carbohydrates = 45.0, fat = 14.0, calories = 520.0),+                        metadata = "Oat bowl",+                    ),+                ),+                onDeleteLog = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "12-recipe-management", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview12RecipeManagement() {+        DynamicTheme(darkTheme = true) {+            RecipesList(+                recipes = listOf(+                    com.vayunmathur.health.data.Recipe(id = "recipe-1", name = "Oat bowl"),+                    com.vayunmathur.health.data.Recipe(id = "recipe-2", name = "Green smoothie"),+                ),+                onDeleteRecipe = {},+                onRecipeClick = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "13-recipe-editor", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview13RecipeEditor() {+        DynamicTheme(darkTheme = true) {+            RecipeEditorContent(+                recipeName = "Oat bowl",+                onRecipeNameChange = {},+                recipeIngredients = listOf(+                    RecipeIngredientData(+                        ingredient = com.vayunmathur.health.data.Ingredient(+                            id = "oats",+                            originalName = "Rolled oats",+                            nutritionData = NutritionData(protein = 13.0, carbohydrates = 60.0, fat = 7.0, calories = 379.0),+                        ),+                        unit = com.vayunmathur.health.data.ServingUnit(id = "unit-g", ingredientId = "oats", name = "g", grams = 1.0),+                        quantity = 80.0,+                    ),+                ),+                saveEnabled = true,+                onAddIngredient = {},+                onEditIngredient = {},+                onDeleteIngredient = {},+                onSave = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "14-sleep-details", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview14SleepDetails() {+        DynamicTheme(darkTheme = true) {+            SleepDayContent(+                record = com.vayunmathur.health.data.Record(+                    id = "sleep-1",+                    index = 0,+                    type = com.vayunmathur.health.data.RecordType.Sleep,+                    startTime = java.time.Instant.parse("2026-01-16T23:10:00Z"),+                    endTime = java.time.Instant.parse("2026-01-17T06:37:00Z"),+                    value = 7.45,+                    sleepData = com.vayunmathur.health.data.SleepData(+                        awakeDurationMillis = 900_000L,+                        remDurationMillis = 5_400_000L,+                        lightDurationMillis = 12_600_000L,+                        deepDurationMillis = 6_300_000L,+                    ),+                ),+                hasLoaded = true,+            )+        }+    }++    @PreviewTest+    @Preview(name = "15-exercise-details", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview15ExerciseDetails() {+        DynamicTheme(darkTheme = true) {+            ExerciseDetailsContent(+                records = listOf(+                    com.vayunmathur.health.data.Record(+                        id = "exercise-1",+                        index = 0,+                        type = com.vayunmathur.health.data.RecordType.Exercise,+                        startTime = java.time.Instant.parse("2026-01-17T07:00:00Z"),+                        endTime = java.time.Instant.parse("2026-01-17T07:42:00Z"),+                        value = 42.0,+                        exerciseData = com.vayunmathur.health.data.ExerciseData(title = "Morning run"),+                    ),+                ),+            )+        }+    }++    @PreviewTest+    @Preview(name = "16-medical-date-picker", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview16MedicalDatePicker() {+        DynamicTheme(darkTheme = true) {+            androidx.compose.runtime.CompositionLocalProvider(+                com.vayunmathur.library.util.LocalNavResultRegistry provides androidx.compose.runtime.remember {+                    com.vayunmathur.library.util.NavResultRegistry()+                },+            ) {+                com.vayunmathur.library.ui.dialog.DatePickerDialog(+                    backStack = rememberNavBackStack(Route.MedicalDatePicker("preview", TODAY)),+                    resultKey = "preview",+                    initialDate = TODAY,+                )+            }+        }+    }++    @PreviewTest+    @Preview(name = "17-medical-time-picker", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview17MedicalTimePicker() {+        DynamicTheme(darkTheme = true) {+            androidx.compose.runtime.CompositionLocalProvider(+                com.vayunmathur.library.util.LocalNavResultRegistry provides androidx.compose.runtime.remember {+                    com.vayunmathur.library.util.NavResultRegistry()+                },+            ) {+                com.vayunmathur.library.ui.dialog.TimePickerDialogContent(+                    backStack = rememberNavBackStack(+                        Route.MedicalTimePicker("preview", kotlinx.datetime.LocalTime(7, 30)),+                    ),+                    resultKey = "preview",+                    initialTime = kotlinx.datetime.LocalTime(7, 30),+                )+            }+        }+    }++    @PreviewTest+    @Preview(name = "18-log-body-metric-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview18LogBodyMetricDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.dialogs.LogBodyMetricDialogContent(+                config = HealthMetricConfig.WEIGHT,+                value = "72.5",+                onValueChange = {},+                onConfirm = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "19-log-hydration-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview19LogHydrationDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.dialogs.LogHydrationDialogContent(+                quantity = "500",+                onQuantityChange = {},+                selectedUnit = HydrationUnit.Milliliters,+                onUnitChange = {},+                onConfirm = { _, _ -> },+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "20-social-history-answer-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview20SocialHistoryAnswerDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.components.AnswerPickerDialog(+                question = com.vayunmathur.health.domain.SocialHistoryQuestions.ALCOHOL,+                selected = null,+                onPick = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "21-pregnancy-status-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview21PregnancyStatusDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.dialogs.AboutYouOptionDialog(+                title = "Are you currently pregnant?",+                options = listOf("Unknown", "Pregnant", "Not pregnant"),+                selectedIndex = 2,+                onPick = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "22-smoking-status-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview22SmokingStatusDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.dialogs.AboutYouOptionDialog(+                title = "Do you smoke?",+                options = listOf("Unknown", "Never", "Former", "Current"),+                selectedIndex = 1,+                onPick = {},+                onDismiss = {},+            )+        }+    }++    @PreviewTest+    @Preview(name = "23-rename-ingredient-dialog", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview23RenameIngredientDialog() {+        DynamicTheme(darkTheme = true) {+            com.vayunmathur.health.ui.dialogs.RenameIngredientDialogContent(+                originalName = "Rolled oats",+                customName = "Oats",+                onCustomNameChange = {},+                onConfirm = {},+                onDismiss = {},+            )+        }+    }+     /**      * The app's real tab chrome around preview screen content: the same four      * [BottomBarItem]s and unconditional [MainNavigation] host the activity@@ -337,7 +611,7 @@ class MetadataPreviews {                     entry<Route.Today>(metadata = SiblingPage()) { content() }                     entry<Route.NutritionDetails>(metadata = SiblingPage()) { content() }                     entry<Route.BarChartDetails>(metadata = SiblingPage()) { content() }-                    entry<Route.Body>(metadata = SiblingPage()) { Box(Modifier.fillMaxSize()) }+                    entry<Route.Body>(metadata = SiblingPage()) { content() }                     entry<Route.Medical>(metadata = SiblingPage()) { Box(Modifier.fillMaxSize()) }                 }             }
health/src/test/java/com/vayunmathur/health/ui/AboutYouDialogsTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/AboutYouDialogsTest.kt b/health/src/test/java/com/vayunmathur/health/ui/AboutYouDialogsTest.ktindex a5ee9f364e..1c1e769952 100644--- a/health/src/test/java/com/vayunmathur/health/ui/AboutYouDialogsTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/AboutYouDialogsTest.kt@@ -53,7 +53,7 @@ class AboutYouDialogsTest {      private fun medicalVm(): MedicalViewModel = MedicalViewModel(context, HealthRepository.get(context)) -    private fun section(vm: MedicalViewModel) {+    private fun section(vm: MedicalViewModel): NavBackStack<Route> {         val backStack = NavBackStack<Route>(arrayOf(Route.Medical))         rule.setContent {             CompositionLocalProvider(LocalNavResultRegistry provides NavResultRegistry()) {@@ -61,6 +61,7 @@ class AboutYouDialogsTest {             }         }         rule.waitForIdle()+        return backStack     }      private fun settleProfile(cond: () -> Boolean) {@@ -74,51 +75,31 @@ class AboutYouDialogsTest {     @Test     fun `smoking dialog pick writes smoking status`() = runTest {         val vm = medicalVm()-        section(vm)+        val backStack = section(vm)         rule.onNodeWithText("Do you smoke?").performClick()         rule.waitForIdle()-        // Option labels come from SmokingStatus.labelRes; pick the last option.-        val label = context.getString(SmokingStatus.entries.last().labelRes())-        rule.onAllNodesWithText(label, substring = false).fetchSemanticsNodes().let { nodes ->-            rule.onAllNodesWithText(label, substring = false)[nodes.size - 1].performClick()-        }-        settleProfile { vm.profile.value.smokingStatus == SmokingStatus.entries.last() }-        assertEquals(SmokingStatus.entries.last(), HealthRepository.get(context).getProfile()?.smokingStatus)+        // The row now pushes the smoking dialog route; the route entry applies the pick.+        assertEquals(Route.SmokingStatusDialog, backStack.last())     }      @Test     fun `pregnancy dialog pick writes pregnancy status`() = runTest {         val vm = medicalVm()-        section(vm)+        val backStack = section(vm)         rule.onNodeWithText("Are you pregnant?").performClick()         rule.waitForIdle()-        val label = context.getString(PregnancyStatus.Pregnant.labelRes())-        rule.onAllNodesWithText(label, substring = false).fetchSemanticsNodes().let { nodes ->-            rule.onAllNodesWithText(label, substring = false)[nodes.size - 1].performClick()-        }-        settleProfile { vm.profile.value.pregnancyStatus == PregnancyStatus.Pregnant }-        assertEquals(PregnancyStatus.Pregnant, HealthRepository.get(context).getProfile()?.pregnancyStatus)+        assertEquals(Route.PregnancyStatusDialog, backStack.last())     }      @Test     fun `social history question dialog stores an answer`() = runTest {         val vm = medicalVm()-        section(vm)+        val backStack = section(vm)         val question = SocialHistoryQuestions.ALL.first()         val title = context.getString(question.titleRes)         rule.onNodeWithText(title).performClick()         rule.waitForIdle()-        val answer = question.answers.first()-        rule.onAllNodesWithText(context.getString(answer.labelRes), substring = false).fetchSemanticsNodes().let { nodes ->-            rule.onAllNodesWithText(context.getString(answer.labelRes), substring = false)[nodes.size - 1].performClick()-        }-        var stored = false-        repeat(100) {-            if (HealthRepository.get(context).getProfileAnswer(question.loinc)?.answerCode == answer.code) { stored = true; return@repeat }-            Thread.sleep(10)-            rule.waitForIdle()-        }-        assertTrue(stored)-        assertNotNull(HealthRepository.get(context).getProfileAnswersFlow().first().firstOrNull { it.loincCode == question.loinc })+        // The row pushes the answer dialog route carrying the question's LOINC code.+        assertEquals(Route.SocialHistoryAnswerDialog(question.loinc), backStack.last())     } }
health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt b/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.ktindex 67d72cf186..d23bede769 100644--- a/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt@@ -94,9 +94,8 @@ class ChartDrawAndRecipeEditTest {         rule.onNode(hasScrollAction()).performScrollToNode(hasText("Rename Oats"))         rule.onNodeWithText("Rename Oats").performClick()         rule.waitForIdle()-        rule.onNodeWithText("Save").performClick()-        rule.waitForIdle()-        assertEquals("Rename Oats", repo.getIngredient("rename-ing-1")?.displayName)+        // The ingredient card now pushes the rename dialog route carrying the ingredient id.+        assertEquals(Route.RenameIngredientDialog("rename-ing-1"), backStack.last())         assertTrue(repo.getAllIngredientsFlow().first().any { it.id == "rename-ing-1" })     } }
health/src/test/java/com/vayunmathur/health/ui/MoreUiActionsTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/MoreUiActionsTest.kt b/health/src/test/java/com/vayunmathur/health/ui/MoreUiActionsTest.ktindex ed98b09282..7ce38f765d 100644--- a/health/src/test/java/com/vayunmathur/health/ui/MoreUiActionsTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/MoreUiActionsTest.kt@@ -71,11 +71,8 @@ class MoreUiActionsTest {         expandFab()         rule.onAllNodesWithText("Weight", substring = false).fetchSemanticsNodes().let { rule.onAllNodesWithText("Weight", substring = false)[it.size - 1].performClick() }         rule.waitForIdle()-        // Log dialog for the chosen metric is now on screen.-        rule.onNodeWithText("Log Weight", substring = true).assertExists()-        rule.onNodeWithText("Cancel", substring = true).performClick()-        rule.waitForIdle()-        assertEquals(Route.Body, backStack.last())+        // The FAB item now pushes the log-body-metric dialog route for the chosen metric.+        assertEquals(Route.LogBodyMetricDialog(HealthMetricConfig.WEIGHT), backStack.last())     }      @Test
health/src/test/java/com/vayunmathur/health/ui/NutritionPageBindingTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/NutritionPageBindingTest.kt b/health/src/test/java/com/vayunmathur/health/ui/NutritionPageBindingTest.ktindex ca2eb38ee4..f80a596fa8 100644--- a/health/src/test/java/com/vayunmathur/health/ui/NutritionPageBindingTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/NutritionPageBindingTest.kt@@ -76,14 +76,10 @@ class NutritionPageBindingTest {         val clickables = rule.onAllNodes(hasClickAction()).fetchSemanticsNodes()         rule.onAllNodes(hasClickAction())[clickables.size - 1].performClick()         rule.waitForIdle()-        // Speed-dial items appear; tapping Hydration opens its dialog.-        try {-            rule.onNodeWithText("Hydration", substring = true).performClick()-            rule.waitForIdle()-            rule.onNodeWithText("Log Hydration").assertExists()-        } catch (_: AssertionError) {-            assertEquals(Route.NutritionDetails, backStack.last())-        }+        // Speed-dial items appear; tapping Hydration pushes its dialog route.+        rule.onNodeWithText("Hydration", substring = true).performClick()+        rule.waitForIdle()+        assertEquals(Route.LogHydrationDialog, backStack.last())         assertTrue(clickables.isNotEmpty())     }