health: recipes and ingredients as sibling routes with swipe
- Commit
0d36a7a4519cb8c23b676ccf057a0ccea9528709- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-06 04:24 UTC (10 hours ago)
- Parents
b27eed2
Route.RecipeManagement (one destination hosting a pager) is replaced by Route.Recipes and Route.Ingredients, real sibling destinations under Nutrition, each with its own entry (SiblingPage) and list page (RecipesPage/IngredientsPage). Navigation.kt hosts the single MainNavigation inside SwipeRouteHost: the top bar, tab row, create FAB (new recipe on Recipes, add-ingredient on Ingredients, hidden on empty lists) and the HealthBottomBar bottom bar all live outside the NavDisplay, so swiping or tapping between the siblings crossfades only the list and the bars stay still. Sibling switches replace the top entry, so Back from either sibling returns to Nutrition. RecipeEditor and the AddIngredient/RenameIngredient dialog routes push exactly as before. Screenshot previews split into 12-recipes and 24-ingredients; metadata regenerated (the committed set was stale, so the regen also renumbers unrelated health shots). Tests that drove the pager screen now drive a RecipeSiblingHost test host; HealthPagesW6 asserts the new route on the stack. Verified: :health:lint, :health:lintVitalRelease pass; :health:testDevUnitTest passes (RecipeEditorFlowTest, the documented full-suite-only flake from the pager change, passed this run and in isolation); :health:metadata regenerated.
Diff
health/AGENTS.md
diff --git a/health/AGENTS.md b/health/AGENTS.mdindex 033ce6e0d2..176e17a77e 100644--- a/health/AGENTS.md+++ b/health/AGENTS.md@@ -97,7 +97,8 @@ _Install: ./install health (dev by default)._ - com/vayunmathur/health/ui/IngredientSearchDialog.kt - com/vayunmathur/health/ui/IngredientQuantityDialog.kt - com/vayunmathur/health/ui/RecipeEditorPage.kt-- com/vayunmathur/health/ui/RecipeManagementPage.kt+- com/vayunmathur/health/ui/RecipesPage.kt — Recipes sibling route of recipe management (`SwipeRouteHost` in `Navigation.kt` owns its tab row/FAB; swipe switches routes)+- com/vayunmathur/health/ui/IngredientsPage.kt — Ingredients sibling route of recipe management - com/vayunmathur/health/ui/MedicationPage.kt - com/vayunmathur/health/ui/DoseReminderScreen.kt - com/vayunmathur/health/ui/VaccinationsPage.kt
health/src/main/java/com/vayunmathur/health/Navigation.kt
diff --git a/health/src/main/java/com/vayunmathur/health/Navigation.kt b/health/src/main/java/com/vayunmathur/health/Navigation.ktindex 3b6640ec8b..55b5e4cbcb 100644--- a/health/src/main/java/com/vayunmathur/health/Navigation.kt+++ b/health/src/main/java/com/vayunmathur/health/Navigation.kt@@ -1,26 +1,70 @@ package com.vayunmathur.health import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.res.stringResource import com.vayunmathur.health.platform.HealthViewModel import com.vayunmathur.health.platform.MedicalViewModel import com.vayunmathur.health.ui.HealthBottomBar import com.vayunmathur.health.ui.fitnessEntries import com.vayunmathur.health.ui.medicalEntries+import com.vayunmathur.library.ui.FloatingActionButton+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconNavigation+import com.vayunmathur.library.ui.RouteTab+import com.vayunmathur.library.ui.SwipeRouteHost+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TopAppBar import com.vayunmathur.library.util.MainNavigation import com.vayunmathur.library.util.rememberNavBackStack +/**+ * Health's nav host. The recipe-management sibling group (Recipes /+ * Ingredients routes) gets its chrome from [SwipeRouteHost], which wraps+ * the single [MainNavigation]: the host's top bar, tab row, FAB and the+ * [HealthBottomBar] bottom bar are all rendered outside the `NavDisplay`,+ * so a swipe/tab switch between the sibling routes crossfades only the+ * list content while the bars stay still (only the tab indicator and+ * the FAB's target follow the current sibling). On every other route+ * the chrome hides and the same [MainNavigation] renders as before.+ */ @Composable fun Navigation(viewModel: HealthViewModel, medicalViewModel: MedicalViewModel) { val backStack = rememberNavBackStack<Route>(Route.Today)- MainNavigation(+ val recipes by viewModel.allRecipes.collectAsState(emptyList())+ val ingredients by viewModel.allIngredients.collectAsState(emptyList())+ SwipeRouteHost( backStack = backStack,- bottomBar = { HealthBottomBar(backStack) },+ tabs = listOf(+ RouteTab(Route.Recipes, stringResource(R.string.recipes)),+ RouteTab(Route.Ingredients, stringResource(R.string.ingredients)),+ ),+ showChrome = { it == Route.Recipes || it == Route.Ingredients },+ topBar = {+ TopAppBar(+ title = { Text(stringResource(R.string.recipes)) },+ navigationIcon = { IconNavigation(backStack) },+ )+ }, // HealthBottomBar (BottomNavBar) claims IME/navigation insets itself; // hosted screens must not pad for them a second time.- bottomBarOwnsInsets = true,+ bottomBar = { HealthBottomBar(backStack) },+ floatingActionButton = { current ->+ when (current) {+ Route.Recipes -> if (recipes.isNotEmpty()) {+ FloatingActionButton(onClick = { backStack.add(Route.RecipeEditor()) }) { IconAdd() }+ }+ Route.Ingredients -> if (ingredients.isNotEmpty()) {+ FloatingActionButton(onClick = { backStack.add(Route.AddIngredientDialog) }) { IconAdd() }+ }+ else -> Unit+ }+ }, ) {- fitnessEntries(backStack, viewModel)- medicalEntries(backStack, medicalViewModel)+ MainNavigation(backStack = backStack, bottomBarOwnsInsets = true) {+ fitnessEntries(backStack, viewModel)+ medicalEntries(backStack, medicalViewModel)+ } } }-
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 f662c02fcb..d4a17fe5ab 100644--- a/health/src/main/java/com/vayunmathur/health/Route.kt+++ b/health/src/main/java/com/vayunmathur/health/Route.kt@@ -35,9 +35,13 @@ sealed interface Route: NavKey { @Serializable data object NutritionFullBreakdown: Route - /** Singleton holding recipe management state and operations. */+ /** The Recipes sibling of recipe management; swipe/tab switches to [Ingredients]. */ @Serializable- data object RecipeManagement: Route+ data object Recipes: Route++ /** The Ingredients sibling of recipe management; swipe/tab switches to [Recipes]. */+ @Serializable+ data object Ingredients: Route /** Immutable value describing recipe editor; carries recipeId. */ @Serializable
health/src/main/java/com/vayunmathur/health/ui/IngredientsPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/IngredientsPage.kt b/health/src/main/java/com/vayunmathur/health/ui/IngredientsPage.ktnew file mode 100644index 0000000000..c4cc3c2e11--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/IngredientsPage.kt@@ -0,0 +1,89 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+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.Ingredient+import com.vayunmathur.health.platform.HealthViewModel+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconFire+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.NavBackStack++/**+ * The Ingredients sibling route of recipe management (Recipes is the+ * other sibling; see [RecipesPage]). The food-database card lives here+ * because ingredient search depends on the bundled database. Rename and+ * add still push as dialog routes over this destination.+ */+@Composable+fun IngredientsPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {+ val ingredients by viewModel.allIngredients.collectAsState(emptyList())+ Column(Modifier.fillMaxSize()) {+ FoodDatabaseCard(viewModel, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))+ if (ingredients.isEmpty()) {+ RecipeEmptyState(+ label = stringResource(R.string.add_your_first_ingredient),+ onCreate = { backStack.add(Route.AddIngredientDialog) },+ )+ } else {+ IngredientsList(+ ingredients,+ onToggleIngredient = { viewModel.updateIngredient(it.copy(isRecipe = !it.isRecipe)) },+ onDeleteIngredient = { viewModel.deleteIngredient(it) },+ ) { ingredient ->+ backStack.add(Route.RenameIngredientDialog(ingredient.id))+ }+ }+ }+}++@Composable+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 { 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)+ if (ingredient.customName != null) {+ Text(stringResource(R.string.original_1, ingredient.originalName), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.outline)+ }+ }+ Row(verticalAlignment = Alignment.CenterVertically) {+ IconButton(onClick = { onToggleIngredient(ingredient) }) {+ if (ingredient.isRecipe) IconFire() else IconFire(tint = MaterialTheme.colorScheme.outline)+ }+ IconButton(onClick = { onDeleteIngredient(ingredient) }) {+ IconDelete()+ }+ }+ }+ }+ }+ }+}
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 299d19e229..4270d3eb26 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NavigationEntries.kt@@ -76,8 +76,11 @@ internal fun EntryProviderScope<Route>.fitnessEntries( entry<Route.NutritionFullBreakdown> { NutritionDetailsPage(backStack, viewModel) }- entry<Route.RecipeManagement> {- RecipeManagementPage(backStack, viewModel)+ entry<Route.Recipes>(metadata = SiblingPage()) {+ RecipesPage(backStack, viewModel)+ }+ entry<Route.Ingredients>(metadata = SiblingPage()) {+ IngredientsPage(backStack, viewModel) } entry<Route.RecipeEditor> { RecipeEditorPage(backStack, viewModel, it.recipeId)
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 210a9a8b25..a9c59655fa 100644--- a/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt+++ b/health/src/main/java/com/vayunmathur/health/ui/NutritionPage.kt@@ -143,7 +143,7 @@ fun NutritionPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) { } override fun openRecipes() {- backStack.add(Route.RecipeManagement)+ backStack.add(Route.Recipes) } override fun openFullBreakdown() {
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.ktdeleted file mode 100644index 4ae78298a0..0000000000--- a/health/src/main/java/com/vayunmathur/health/ui/RecipeManagementPage.kt+++ /dev/null@@ -1,198 +0,0 @@-@file:OptIn(kotlin.uuid.ExperimentalUuidApi::class)--package com.vayunmathur.health.ui--import kotlin.uuid.Uuid-import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Arrangement-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width-import androidx.compose.runtime.Composable-import androidx.compose.runtime.collectAsState-import androidx.compose.runtime.getValue-import androidx.compose.foundation.pager.rememberPagerState-import com.vayunmathur.health.data.Ingredient-import com.vayunmathur.health.data.Recipe-import com.vayunmathur.library.ui.AlertDialog-import com.vayunmathur.library.ui.Button-import com.vayunmathur.library.ui.Card-import com.vayunmathur.library.ui.ExperimentalMaterial3Api-import com.vayunmathur.library.ui.FloatingActionButton-import com.vayunmathur.library.ui.IconAdd-import com.vayunmathur.library.ui.IconButton-import com.vayunmathur.library.ui.IconDelete-import com.vayunmathur.library.ui.IconFire-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 androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.foundation.text.KeyboardOptions-import com.vayunmathur.library.ui.R as UiR-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.graphics.Color-import androidx.compose.ui.res.painterResource-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.Route-import com.vayunmathur.library.ui.IconNavigation-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle-import com.vayunmathur.library.ui.TabbedPagerScaffold-import com.vayunmathur.library.ui.TopAppBar-import com.vayunmathur.library.ui.EmptyState-import com.vayunmathur.health.data.FoodDatabase-import com.vayunmathur.health.data.FoodSearchAPI-import com.vayunmathur.health.platform.HealthViewModel-import com.vayunmathur.library.util.NavBackStack-import kotlinx.coroutines.launch-import java.text.NumberFormat--/**- * Recipes and ingredients as two swipeable peer pages of this one- * destination: neither tab is a route, so the pager (tap or swipe) owns the- * selection, the lists come from the ViewModel, and the create action follows- * the settled page. Editor and dialog destinations still push as routes.- */-@OptIn(ExperimentalMaterial3Api::class)-@Composable-fun RecipeManagementPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {- val recipes by viewModel.allRecipes.collectAsState(emptyList())- val ingredients by viewModel.allIngredients.collectAsState(emptyList())- val pagerState = rememberPagerState(pageCount = { 2 })- val currentPage = pagerState.currentPage- val recipesEmpty = recipes.isEmpty()- val ingredientsEmpty = ingredients.isEmpty()- val isListEmpty = if (currentPage == 0) recipesEmpty else ingredientsEmpty-- TabbedPagerScaffold(- pagerState = pagerState,- tabStyle = TabStyle.PrimaryTabRow,- topBar = {- TopAppBar(- title = { Text(stringResource(R.string.recipes)) },- navigationIcon = { IconNavigation(backStack) },- )- },- floatingActionButton = {- if (!isListEmpty) {- FloatingActionButton(onClick = {- if (currentPage == 0) {- backStack.add(Route.RecipeEditor())- } else {- backStack.add(Route.AddIngredientDialog)- }- }) {- IconAdd()- }- }- },- tabs = listOf(- PagerTab(stringResource(R.string.recipes)) {- if (recipesEmpty) {- RecipeEmptyState(- label = stringResource(R.string.create_your_first_recipe),- onCreate = { backStack.add(Route.RecipeEditor()) },- )- } else {- RecipesList(recipes, onDeleteRecipe = { viewModel.deleteRecipe(it) }) { recipeId ->- backStack.add(Route.RecipeEditor(recipeId))- }- }- },- PagerTab(stringResource(R.string.ingredients)) {- Column(Modifier.fillMaxSize()) {- // Ingredient search depends on the bundled food database, so its- // first-run state belongs on the Ingredients page.- FoodDatabaseCard(viewModel, modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp))- if (ingredientsEmpty) {- RecipeEmptyState(- label = stringResource(R.string.add_your_first_ingredient),- onCreate = { backStack.add(Route.AddIngredientDialog) },- )- } else {- IngredientsList(- ingredients,- onToggleIngredient = { viewModel.updateIngredient(it.copy(isRecipe = !it.isRecipe)) },- onDeleteIngredient = { viewModel.deleteIngredient(it) },- ) { ingredient ->- backStack.add(Route.RenameIngredientDialog(ingredient.id))- }- }- }- },- ),- )-}--@Composable-private fun RecipeEmptyState(label: String, onCreate: () -> Unit) {- Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {- Button(onClick = onCreate) {- IconAdd()- Spacer(Modifier.width(8.dp))- Text(label)- }- }-}--@Composable-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(- modifier = Modifier.fillMaxWidth().clickable { onRecipeClick(recipe.id) }- ) {- 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 = { onDeleteRecipe(recipe) }) {- IconDelete()- }- }- }- }- }-}--@Composable-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 { 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)- if (ingredient.customName != null) {- Text(stringResource(R.string.original_1, ingredient.originalName), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.outline)- }- }- Row(verticalAlignment = Alignment.CenterVertically) {- IconButton(onClick = { onToggleIngredient(ingredient) }) {- if (ingredient.isRecipe) IconFire() else IconFire(tint = MaterialTheme.colorScheme.outline)- }- IconButton(onClick = { onDeleteIngredient(ingredient) }) {- IconDelete()- }- }- }- }- }- }-}
health/src/main/java/com/vayunmathur/health/ui/RecipesPage.kt
diff --git a/health/src/main/java/com/vayunmathur/health/ui/RecipesPage.kt b/health/src/main/java/com/vayunmathur/health/ui/RecipesPage.ktnew file mode 100644index 0000000000..8dd3221dd1--- /dev/null+++ b/health/src/main/java/com/vayunmathur/health/ui/RecipesPage.kt@@ -0,0 +1,83 @@+package com.vayunmathur.health.ui++import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+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.Recipe+import com.vayunmathur.health.platform.HealthViewModel+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.util.NavBackStack++/**+ * The Recipes sibling route of recipe management. Ingredients is the+ * other sibling; the shared `SwipeRouteHost` in `Navigation.kt` owns the+ * tab row, top bar and create FAB, and a swipe here switches routes+ * (replacing this entry, never pushing) rather than flipping a pager.+ * The recipe editor still pushes as its own route.+ */+@Composable+fun RecipesPage(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {+ val recipes by viewModel.allRecipes.collectAsState(emptyList())+ if (recipes.isEmpty()) {+ RecipeEmptyState(+ label = stringResource(R.string.create_your_first_recipe),+ onCreate = { backStack.add(Route.RecipeEditor()) },+ )+ } else {+ RecipesList(recipes, onDeleteRecipe = { viewModel.deleteRecipe(it) }) { recipeId ->+ backStack.add(Route.RecipeEditor(recipeId))+ }+ }+}++@Composable+internal fun RecipeEmptyState(label: String, onCreate: () -> Unit) {+ Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {+ Button(onClick = onCreate) {+ IconAdd()+ Spacer(Modifier.width(8.dp))+ Text(label)+ }+ }+}++@Composable+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(+ modifier = Modifier.fillMaxWidth().clickable { onRecipeClick(recipe.id) }+ ) {+ Row(modifier = Modifier.padding(16.dp).fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) {+ Text(recipe.name, style = com.vayunmathur.library.ui.MaterialTheme.typography.titleMedium, color = HealthColors.Nutrition)+ IconButton(onClick = { onDeleteRecipe(recipe) }) {+ IconDelete()+ }+ }+ }+ }+ }+}
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 562d21afcc..fb4241ee52 100644--- a/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt+++ b/health/src/screenshotTest/kotlin/com/vayunmathur/health/ui/MetadataPreviews.kt@@ -71,7 +71,7 @@ private val TODAY = LocalDate(2026, 1, 17) * scheme rather than a user's actual accent colour. * * Coverage: `Today`, `Body` and `NutritionDetails` tabs, `BarChartDetails`- * (steps + heart rate), `NutritionFullBreakdown`, `RecipeManagement`,+ * (steps + heart rate), `NutritionFullBreakdown`, `Recipes`/`Ingredients`, * `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@@ -358,9 +358,9 @@ class MetadataPreviews { } @PreviewTest- @Preview(name = "12-recipe-management", device = PHONE, group = "phone", showSystemUi = true)+ @Preview(name = "12-recipes", device = PHONE, group = "phone", showSystemUi = true) @Composable- fun Preview12RecipeManagement() {+ fun Preview12Recipes() { DynamicTheme(darkTheme = true) { RecipesList( recipes = listOf(@@ -373,6 +373,26 @@ class MetadataPreviews { } } + @PreviewTest+ @Preview(name = "24-ingredients", device = PHONE, group = "phone", showSystemUi = true)+ @Composable+ fun Preview24Ingredients() {+ DynamicTheme(darkTheme = true) {+ IngredientsList(+ ingredients = listOf(+ com.vayunmathur.health.data.Ingredient(+ id = "oats",+ originalName = "Rolled oats",+ nutritionData = NutritionData(protein = 13.0, carbohydrates = 60.0, fat = 7.0, calories = 379.0),+ ),+ ),+ onToggleIngredient = {},+ onDeleteIngredient = {},+ onRenameIngredient = {},+ )+ }+ }+ @PreviewTest @Preview(name = "13-recipe-editor", device = PHONE, group = "phone", showSystemUi = true) @Composable
health/src/test/java/com/vayunmathur/health/platform/ActivityAndStoreTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/platform/ActivityAndStoreTest.kt b/health/src/test/java/com/vayunmathur/health/platform/ActivityAndStoreTest.ktindex 19d6b1c498..6364ece667 100644--- a/health/src/test/java/com/vayunmathur/health/platform/ActivityAndStoreTest.kt+++ b/health/src/test/java/com/vayunmathur/health/platform/ActivityAndStoreTest.kt@@ -103,7 +103,7 @@ class ActivityAndStoreTest { assertEquals("{\"type\":\"com.vayunmathur.health.Route.Today\"}", json.encodeToString(Route.serializer(), Route.Today)) val routes: List<Route> = listOf( Route.Today, Route.Body, Route.NutritionDetails, Route.NutritionFullBreakdown,- Route.RecipeManagement, Route.RecipeEditor("r1"), Route.RecipeEditor(),+ Route.Recipes, Route.RecipeEditor("r1"), Route.RecipeEditor(), Route.BarChartDetails(HealthMetricConfig.WEIGHT), Route.SleepDetails, Route.ExerciseDetails, Route.Medical, Route.EditVaccination("v1"), Route.EditMedication(), Route.EditAllergy("a1"), Route.EditCondition(), Route.EditLabResult("l1"),
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 045fc0839f..42ea3c1e89 100644--- a/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/ChartDrawAndRecipeEditTest.kt@@ -87,8 +87,8 @@ class ChartDrawAndRecipeEditTest { fun `ingredient rename dialog saves custom name`() = runBlocking<Unit> { val repo = HealthRepository.get(context) repo.insertIngredient(Ingredient(id = "rename-ing-1", originalName = "Rename Oats", nutritionData = NutritionData(calories = 90.0)))- val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.RecipeManagement))- rule.setContent { RecipeManagementPage(backStack, vm()) }+ val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.Recipes))+ rule.setContent { RecipeSiblingHost(backStack, vm()) } rule.waitForIdle() rule.onNodeWithText("Ingredients").performClick() rule.waitForIdle()
health/src/test/java/com/vayunmathur/health/ui/HealthPagesW6Test.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/HealthPagesW6Test.kt b/health/src/test/java/com/vayunmathur/health/ui/HealthPagesW6Test.ktindex 4190e91cae..fcaec8760e 100644--- a/health/src/test/java/com/vayunmathur/health/ui/HealthPagesW6Test.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/HealthPagesW6Test.kt@@ -81,7 +81,7 @@ class HealthPagesW6Test { fun recipeManagement_tabsSeededAndIngredientTab() { seed() val s = stack()- rule.setContent { RecipeManagementPage(s, health()) }+ rule.setContent { RecipeSiblingHost(s, health()) } rule.waitForIdle() // Ingredients tab shows the seeded ingredient (scroll it into view). rule.onAllNodesWithText("Ingredients", substring = true)[0].performClick()@@ -93,7 +93,8 @@ class HealthPagesW6Test { kotlinx.coroutines.runBlocking { assertTrue(repository().getAllRecipesFlow().first().any { it.name == "W6 Stew" }) }- assertTrue(s.backStack.last() is Route.Today)+ // Sibling switch replaces/adds one route over the parent: Back returns to Today.+ assertTrue(s.backStack.last() == Route.Ingredients) } @Test
health/src/test/java/com/vayunmathur/health/ui/InteractionsTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/InteractionsTest.kt b/health/src/test/java/com/vayunmathur/health/ui/InteractionsTest.ktindex 5aff9e8a11..aa6654719e 100644--- a/health/src/test/java/com/vayunmathur/health/ui/InteractionsTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/InteractionsTest.kt@@ -133,8 +133,8 @@ class InteractionsTest { fun `recipe management recipe click navigates to editor`() = runBlocking { HealthRepository.get(context).insertRecipe(Recipe(id = "interact-recipe-1", name = "Interact Soup")) HealthRepository.get(context).insertIngredient(Ingredient(id = "interact-ing-1", originalName = "Interact Carrot", nutritionData = NutritionData(calories = 40.0)))- val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.RecipeManagement))- rule.setContent { RecipeManagementPage(backStack, vm()) }+ val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.Recipes))+ rule.setContent { RecipeSiblingHost(backStack, vm()) } rule.waitForIdle() rule.onNodeWithText("Interact Soup").assertIsDisplayed() rule.onNodeWithText("Interact Soup").performClick()
health/src/test/java/com/vayunmathur/health/ui/RecipeSiblingHost.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/RecipeSiblingHost.kt b/health/src/test/java/com/vayunmathur/health/ui/RecipeSiblingHost.ktnew file mode 100644index 0000000000..eca310008a--- /dev/null+++ b/health/src/test/java/com/vayunmathur/health/ui/RecipeSiblingHost.kt@@ -0,0 +1,24 @@+package com.vayunmathur.health.ui++import androidx.compose.runtime.Composable+import com.vayunmathur.health.Route+import com.vayunmathur.health.platform.HealthViewModel+import com.vayunmathur.library.ui.RouteTab+import com.vayunmathur.library.ui.SwipeRouteHost+import com.vayunmathur.library.util.NavBackStack++/** Test host for the recipe sibling routes, mirroring `Navigation.kt`'s chrome. */+@Composable+fun RecipeSiblingHost(backStack: NavBackStack<Route>, viewModel: HealthViewModel) {+ SwipeRouteHost(+ showChrome = { true },+ backStack = backStack,+ tabs = listOf(+ RouteTab(Route.Recipes, "Recipes"),+ RouteTab(Route.Ingredients, "Ingredients"),+ ),+ ) { route ->+ if (route == Route.Ingredients) IngredientsPage(backStack, viewModel)+ else RecipesPage(backStack, viewModel)+ }+}
health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt b/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.ktindex e7b9dc47cc..169decfd71 100644--- a/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/ThresholdBatchTest.kt@@ -160,8 +160,8 @@ class ThresholdBatchTest { fun `ingredients list toggle marks ingredient as recipe`() = runBlocking<Unit> { val repo = repo() repo.insertIngredient(Ingredient(id = "toggle-ing-1", originalName = "Toggle Beans", nutritionData = NutritionData(calories = 90.0)))- val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.RecipeManagement))- rule.setContent { RecipeManagementPage(backStack, vm()) }+ val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.Recipes))+ rule.setContent { RecipeSiblingHost(backStack, vm()) } rule.waitForIdle() rule.onNodeWithText("Ingredients").performClick() // Ingredients arrive via a Room flow resumed on the paused main
health/src/test/java/com/vayunmathur/health/ui/UncoveredScreensTest.kt
diff --git a/health/src/test/java/com/vayunmathur/health/ui/UncoveredScreensTest.kt b/health/src/test/java/com/vayunmathur/health/ui/UncoveredScreensTest.ktindex 2c193471f4..8e391dae80 100644--- a/health/src/test/java/com/vayunmathur/health/ui/UncoveredScreensTest.kt+++ b/health/src/test/java/com/vayunmathur/health/ui/UncoveredScreensTest.kt@@ -141,8 +141,8 @@ class UncoveredScreensTest { fun `recipe management shows seeded recipes and ingredients tabs`() = runBlocking<Unit> { repo().insertRecipe(Recipe(id = "rcp-screen-1", name = "Screen Salad")) repo().insertIngredient(Ingredient(id = "ing-screen-1", originalName = "Screen Tomato", nutritionData = nutrition()))- val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.RecipeManagement))- rule.setContent { RecipeManagementPage(backStack, vm()) }+ val backStack = NavBackStack<Route>(arrayOf(Route.Today, Route.Recipes))+ rule.setContent { RecipeSiblingHost(backStack, vm()) } rule.waitForIdle() // Both pager pages (and the pager itself) are scrollable and the // shared suite database can leave this row far down the lazy list,
metadata_data/photos/health/phone/1.png
diff --git a/metadata_data/photos/health/phone/1.png b/metadata_data/photos/health/phone/1.pngindex 64d81e4cbc..8080218c3f 100644Binary files a/metadata_data/photos/health/phone/1.png and b/metadata_data/photos/health/phone/1.png differ
metadata_data/photos/health/phone/10.png
diff --git a/metadata_data/photos/health/phone/10.png b/metadata_data/photos/health/phone/10.pngnew file mode 100644index 0000000000..ecc7a156f8Binary files /dev/null and b/metadata_data/photos/health/phone/10.png differ
metadata_data/photos/health/phone/11.png
diff --git a/metadata_data/photos/health/phone/11.png b/metadata_data/photos/health/phone/11.pngnew file mode 100644index 0000000000..64d81e4cbcBinary files /dev/null and b/metadata_data/photos/health/phone/11.png differ
metadata_data/photos/health/phone/12.png
diff --git a/metadata_data/photos/health/phone/12.png b/metadata_data/photos/health/phone/12.pngnew file mode 100644index 0000000000..575ad3eb35Binary files /dev/null and b/metadata_data/photos/health/phone/12.png differ
metadata_data/photos/health/phone/13.png
diff --git a/metadata_data/photos/health/phone/13.png b/metadata_data/photos/health/phone/13.pngnew file mode 100644index 0000000000..09b5e42605Binary files /dev/null and b/metadata_data/photos/health/phone/13.png differ
metadata_data/photos/health/phone/14.png
diff --git a/metadata_data/photos/health/phone/14.png b/metadata_data/photos/health/phone/14.pngnew file mode 100644index 0000000000..254cacad2aBinary files /dev/null and b/metadata_data/photos/health/phone/14.png differ
metadata_data/photos/health/phone/15.png
diff --git a/metadata_data/photos/health/phone/15.png b/metadata_data/photos/health/phone/15.pngnew file mode 100644index 0000000000..b6807128f6Binary files /dev/null and b/metadata_data/photos/health/phone/15.png differ
metadata_data/photos/health/phone/16.png
diff --git a/metadata_data/photos/health/phone/16.png b/metadata_data/photos/health/phone/16.pngnew file mode 100644index 0000000000..6da0537cd7Binary files /dev/null and b/metadata_data/photos/health/phone/16.png differ
metadata_data/photos/health/phone/17.png
diff --git a/metadata_data/photos/health/phone/17.png b/metadata_data/photos/health/phone/17.pngnew file mode 100644index 0000000000..4a3e802af8Binary files /dev/null and b/metadata_data/photos/health/phone/17.png differ
metadata_data/photos/health/phone/18.png
diff --git a/metadata_data/photos/health/phone/18.png b/metadata_data/photos/health/phone/18.pngnew file mode 100644index 0000000000..8d66c01f8eBinary files /dev/null and b/metadata_data/photos/health/phone/18.png differ
metadata_data/photos/health/phone/19.png
diff --git a/metadata_data/photos/health/phone/19.png b/metadata_data/photos/health/phone/19.pngnew file mode 100644index 0000000000..c2fd3e307aBinary files /dev/null and b/metadata_data/photos/health/phone/19.png differ
metadata_data/photos/health/phone/2.png
diff --git a/metadata_data/photos/health/phone/2.png b/metadata_data/photos/health/phone/2.pngindex 4a3e802af8..3ac232a011 100644Binary files a/metadata_data/photos/health/phone/2.png and b/metadata_data/photos/health/phone/2.png differ
metadata_data/photos/health/phone/20.png
diff --git a/metadata_data/photos/health/phone/20.png b/metadata_data/photos/health/phone/20.pngnew file mode 100644index 0000000000..b13938bb67Binary files /dev/null and b/metadata_data/photos/health/phone/20.png differ
metadata_data/photos/health/phone/21.png
diff --git a/metadata_data/photos/health/phone/21.png b/metadata_data/photos/health/phone/21.pngnew file mode 100644index 0000000000..31de462760Binary files /dev/null and b/metadata_data/photos/health/phone/21.png differ
metadata_data/photos/health/phone/3.png
diff --git a/metadata_data/photos/health/phone/3.png b/metadata_data/photos/health/phone/3.pngindex 8d66c01f8e..668e9b679a 100644Binary files a/metadata_data/photos/health/phone/3.png and b/metadata_data/photos/health/phone/3.png differ
metadata_data/photos/health/phone/4.png
diff --git a/metadata_data/photos/health/phone/4.png b/metadata_data/photos/health/phone/4.pngindex c2fd3e307a..370aa6e369 100644Binary files a/metadata_data/photos/health/phone/4.png and b/metadata_data/photos/health/phone/4.png differ
metadata_data/photos/health/phone/5.png
diff --git a/metadata_data/photos/health/phone/5.png b/metadata_data/photos/health/phone/5.pngindex b13938bb67..6bdc812808 100644Binary files a/metadata_data/photos/health/phone/5.png and b/metadata_data/photos/health/phone/5.png differ
metadata_data/photos/health/phone/6.png
diff --git a/metadata_data/photos/health/phone/6.png b/metadata_data/photos/health/phone/6.pngindex 31de462760..9a8ea2c4d0 100644Binary files a/metadata_data/photos/health/phone/6.png and b/metadata_data/photos/health/phone/6.png differ
metadata_data/photos/health/phone/7.png
diff --git a/metadata_data/photos/health/phone/7.png b/metadata_data/photos/health/phone/7.pngnew file mode 100644index 0000000000..af069ce076Binary files /dev/null and b/metadata_data/photos/health/phone/7.png differ
metadata_data/photos/health/phone/8.png
diff --git a/metadata_data/photos/health/phone/8.png b/metadata_data/photos/health/phone/8.pngnew file mode 100644index 0000000000..1bdf88e196Binary files /dev/null and b/metadata_data/photos/health/phone/8.png differ
metadata_data/photos/health/phone/9.png
diff --git a/metadata_data/photos/health/phone/9.png b/metadata_data/photos/health/phone/9.pngnew file mode 100644index 0000000000..19ae12deb5Binary files /dev/null and b/metadata_data/photos/health/phone/9.png differ