Moved the deletion popup and fixed the icon / selection list not reverting

master
Wynd 2025-12-21 01:38:09 +02:00
parent a7d961393f
commit 519bbd4a89
3 changed files with 22 additions and 27 deletions

View File

@ -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,
)
}

View File

@ -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<RecipeWithTags>()) }
@ -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 = {

View File

@ -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 }
)
}
}
}