From 519bbd4a89ff764a516722c3591a25e3fdd7e6c0 Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 21 Dec 2025 01:38:09 +0200 Subject: [PATCH] Moved the deletion popup and fixed the icon / selection list not reverting --- .../ui/components/DeleteRecipeDialog.kt | 2 +- .../recipe/ui/components/MainScreen.kt | 31 +++++++++++++------ .../recipe/ui/components/RecipeInfo.kt | 16 ---------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/DeleteRecipeDialog.kt b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/DeleteRecipeDialog.kt index f518cad..27f118f 100644 --- a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/DeleteRecipeDialog.kt +++ b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/DeleteRecipeDialog.kt @@ -33,7 +33,7 @@ fun DeleteRecipeDialog(onAccept: ( ) -> Unit, onDismiss: () -> Unit) { modifier = Modifier.height(100.dp).wrapContentSize(Alignment.Center) ) { Text( - text = "Do you really wish to permanently delete this recipe ?", + text = "Do you really wish to permanently delete these recipes ?", textAlign = TextAlign.Center, ) } diff --git a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/MainScreen.kt b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/MainScreen.kt index 0b12538..1757267 100644 --- a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/MainScreen.kt +++ b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/MainScreen.kt @@ -43,6 +43,7 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) { val navController = rememberNavController() + val openDeletionDialog = remember { mutableStateOf(false) } val openTagFilterDialog = remember { mutableStateOf(false) } val selectedEntries = remember { mutableStateOf(listOf()) } @@ -90,8 +91,8 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) { Column(modifier = Modifier.padding(padding)) { Row( modifier = Modifier - .fillMaxWidth() - .padding(8.dp), + .fillMaxWidth() + .padding(8.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp) ) { @@ -115,12 +116,7 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) { IconButton( modifier = Modifier.weight(0.15f), onClick = { - // TODO I feel like this could be done in batch or something...but I truly don't care atm - for (entry in selectedEntries.value) { - view.removeRecipe(entry) - ctx.db.recipeDao().delete(entry.recipe) - ctx.db.recipeWithTagsDao().delete(entry.recipe.title) - } + openDeletionDialog.value = true }, ) { Icon( @@ -129,8 +125,7 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) { contentDescription = "Load recipes from filesystem" ) } - } - else { + } else { IconButton( modifier = Modifier.weight(0.15f), onClick = { ctx.sourceChooser.launch(Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)) }, @@ -166,6 +161,22 @@ fun MainScreen(ctx: MainActivity, padding: PaddingValues, view: RecipesView) { } when { + openDeletionDialog.value -> { + DeleteRecipeDialog( + onAccept = { + // TODO I feel like this could be done in batch or something...but I truly don't care atm + for (entry in selectedEntries.value) { + view.removeRecipe(entry) + ctx.db.recipeDao().delete(entry.recipe) + ctx.db.recipeWithTagsDao().delete(entry.recipe.title) + } + selectedEntries.value = listOf() + openDeletionDialog.value = false + }, + onDismiss = { openDeletionDialog.value = false } + ) + } + openTagFilterDialog.value -> { TagFilterDialog( onAccept = { diff --git a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/RecipeInfo.kt b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/RecipeInfo.kt index e2de34c..be178df 100644 --- a/app/src/main/java/xyz/pixelatedw/recipe/ui/components/RecipeInfo.kt +++ b/app/src/main/java/xyz/pixelatedw/recipe/ui/components/RecipeInfo.kt @@ -49,7 +49,6 @@ fun RecipeInfo( active: RecipeWithTags ) { val keepScreen = view.keepScreenOn.collectAsState() - val openDeletionDialog = remember { mutableStateOf(false) } val picsCounts = remember { active.recipe.pics.size }; val timestamp = view.activeRecipe.collectAsState().value?.recipe?.lastModified ?: 0 @@ -149,19 +148,4 @@ fun RecipeInfo( ) } } - - when { - openDeletionDialog.value -> { - DeleteRecipeDialog( - onAccept = { - view.removeRecipe(active) - ctx.db.recipeDao().delete(active.recipe) - ctx.db.recipeWithTagsDao().delete(active.recipe.title) - openDeletionDialog.value = false - nav.popBackStack() - }, - onDismiss = { openDeletionDialog.value = false } - ) - } - } }