From f0ac2de8e49543452fdacb9113af747ecff40b50 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sun, 11 Feb 2024 17:56:45 +0100 Subject: [PATCH] Improve dialog for folder and feed deletion in FeedTab --- .../com/readrops/app/compose/feeds/FeedTab.kt | 14 +++--- .../compose/feeds/dialogs/DeleteFeedDialog.kt | 45 ------------------- .../util/components/TwoChoicesDialog.kt | 42 +++++++++++++++++ 3 files changed, 51 insertions(+), 50 deletions(-) delete mode 100644 appcompose/src/main/java/com/readrops/app/compose/feeds/dialogs/DeleteFeedDialog.kt create mode 100644 appcompose/src/main/java/com/readrops/app/compose/util/components/TwoChoicesDialog.kt diff --git a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedTab.kt b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedTab.kt index ea9c78a5..2b32b767 100644 --- a/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedTab.kt +++ b/appcompose/src/main/java/com/readrops/app/compose/feeds/FeedTab.kt @@ -34,10 +34,10 @@ import cafe.adriel.voyager.navigator.tab.TabOptions import com.readrops.app.compose.R import com.readrops.app.compose.feeds.dialogs.AddFeedDialog import com.readrops.app.compose.feeds.dialogs.AddUpdateFolderDialog -import com.readrops.app.compose.feeds.dialogs.DeleteFeedDialog import com.readrops.app.compose.feeds.dialogs.FeedModalBottomSheet import com.readrops.app.compose.feeds.dialogs.UpdateFeedDialog import com.readrops.app.compose.util.components.Placeholder +import com.readrops.app.compose.util.components.TwoChoicesDialog import com.readrops.app.compose.util.theme.spacing import com.readrops.db.entities.Feed import org.koin.androidx.compose.getViewModel @@ -72,10 +72,14 @@ object FeedTab : Tab { } is DialogState.DeleteFeed -> { - DeleteFeedDialog( - feed = dialog.feed, + TwoChoicesDialog( + title = "Delete feed", + text = "Do you want to delete feed ${dialog.feed.name}?", + icon = rememberVectorPainter(image = Icons.Default.Delete), + confirmText = "Delete", + dismissText = "Cancel", onDismiss = { viewModel.closeDialog() }, - onDelete = { + onConfirm = { viewModel.deleteFeed(dialog.feed) viewModel.closeDialog() } @@ -139,7 +143,7 @@ object FeedTab : Tab { ) } - is DialogState.DeleteFolder -> {} + is DialogState.UpdateFolder -> { AddUpdateFolderDialog( updateFolder = true, viewModel = viewModel, diff --git a/appcompose/src/main/java/com/readrops/app/compose/feeds/dialogs/DeleteFeedDialog.kt b/appcompose/src/main/java/com/readrops/app/compose/feeds/dialogs/DeleteFeedDialog.kt deleted file mode 100644 index 1b708b70..00000000 --- a/appcompose/src/main/java/com/readrops/app/compose/feeds/dialogs/DeleteFeedDialog.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.readrops.app.compose.feeds.dialogs - -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Delete -import androidx.compose.material3.AlertDialog -import androidx.compose.material3.Icon -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.runtime.Composable -import com.readrops.db.entities.Feed - -@Composable -fun DeleteFeedDialog( - feed: Feed, - onDismiss: () -> Unit, - onDelete: () -> Unit, -) { - AlertDialog( - onDismissRequest = onDismiss, - icon = { - Icon( - imageVector = Icons.Default.Delete, - contentDescription = null, - ) - }, - title = { - Text(text = "Delete feed") - }, - text = { - Text(text = "Do you want to delete feed ${feed.name}?") - }, - confirmButton = { - TextButton(onClick = onDelete) { - Text(text = "Delete") - } - }, - dismissButton = { - TextButton( - onClick = onDismiss - ) { - Text(text = "Cancel") - } - }, - ) -} \ No newline at end of file diff --git a/appcompose/src/main/java/com/readrops/app/compose/util/components/TwoChoicesDialog.kt b/appcompose/src/main/java/com/readrops/app/compose/util/components/TwoChoicesDialog.kt new file mode 100644 index 00000000..85b848b1 --- /dev/null +++ b/appcompose/src/main/java/com/readrops/app/compose/util/components/TwoChoicesDialog.kt @@ -0,0 +1,42 @@ +package com.readrops.app.compose.util.components + +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Icon +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.painter.Painter + +@Composable +fun TwoChoicesDialog( + title: String, + text: String, + icon: Painter, + confirmText: String, + dismissText: String, + onDismiss: () -> Unit, + onConfirm: () -> Unit, +) { + AlertDialog( + onDismissRequest = onDismiss, + icon = { + Icon( + painter = icon, + contentDescription = null, + ) + }, + title = { Text(text = title) }, + text = { Text(text = text) }, + confirmButton = { + TextButton(onClick = onConfirm) { + Text(text = confirmText) + } + }, + dismissButton = { + TextButton(onClick = onDismiss + ) { + Text(text = dismissText) + } + }, + ) +} \ No newline at end of file