Show confirmation dialog before deleting a shortcut
This commit is contained in:
parent
d175edca76
commit
59c250f505
@ -149,6 +149,8 @@
|
|||||||
<string name="alert_delete_directory">The directory %1$s and all its content will be deleted permanently. Proceed\?</string>
|
<string name="alert_delete_directory">The directory %1$s and all its content will be deleted permanently. Proceed\?</string>
|
||||||
<!-- Warning message that is shown when a user attempts to delete a file -->
|
<!-- Warning message that is shown when a user attempts to delete a file -->
|
||||||
<string name="alert_delete_file">The file %1$s will be deleted permanently. Proceed\?</string>
|
<string name="alert_delete_file">The file %1$s will be deleted permanently. Proceed\?</string>
|
||||||
|
<!-- Warning message that is shown when a user attempts to delete a pinned shortcut -->
|
||||||
|
<string name="alert_delete_shortcut">The shortcut %1$s will be removed permanently. Proceed\?</string>
|
||||||
<!-- A somewhat generic error message that is shown when something (a file of a specific file, an app, …)
|
<!-- A somewhat generic error message that is shown when something (a file of a specific file, an app, …)
|
||||||
could not be opened because there was no app installed that could handle the request -->
|
could not be opened because there was no app installed that could handle the request -->
|
||||||
<string name="error_activity_not_found">Couldn\'t open %1$s</string>
|
<string name="error_activity_not_found">Couldn\'t open %1$s</string>
|
||||||
|
|||||||
@ -7,9 +7,7 @@ import androidx.compose.foundation.layout.*
|
|||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.*
|
import androidx.compose.material.icons.rounded.*
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.material3.SnackbarResult
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.geometry.Rect
|
import androidx.compose.ui.geometry.Rect
|
||||||
@ -51,6 +49,7 @@ fun AppShortcutItem(
|
|||||||
val lifecycleOwner = LocalLifecycleOwner.current
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
val snackbarHostState = LocalSnackbarHostState.current
|
val snackbarHostState = LocalSnackbarHostState.current
|
||||||
|
|
||||||
|
var requestDelete by remember { mutableStateOf(false) }
|
||||||
var edit by remember { mutableStateOf(false) }
|
var edit by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val transition = updateTransition(showDetails, label = "AppShortcutItem")
|
val transition = updateTransition(showDetails, label = "AppShortcutItem")
|
||||||
@ -145,7 +144,7 @@ fun AppShortcutItem(
|
|||||||
toolbarActions.add(DefaultToolbarAction(
|
toolbarActions.add(DefaultToolbarAction(
|
||||||
label = stringResource(R.string.menu_delete),
|
label = stringResource(R.string.menu_delete),
|
||||||
icon = Icons.Rounded.Delete,
|
icon = Icons.Rounded.Delete,
|
||||||
action = { viewModel.deleteShortcut() }
|
action = { requestDelete = true }
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +194,28 @@ fun AppShortcutItem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requestDelete) {
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { requestDelete = false },
|
||||||
|
text = { Text(stringResource(R.string.alert_delete_shortcut, shortcut.label)) },
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
viewModel.deleteShortcut()
|
||||||
|
requestDelete = false
|
||||||
|
}) {
|
||||||
|
Text(stringResource(android.R.string.ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = {
|
||||||
|
requestDelete = false
|
||||||
|
}) {
|
||||||
|
Text(stringResource(android.R.string.cancel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (edit) {
|
if (edit) {
|
||||||
CustomizeSearchableSheet(
|
CustomizeSearchableSheet(
|
||||||
searchable = shortcut,
|
searchable = shortcut,
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class ShortcutItemVM(private val shortcut: AppShortcut) : SearchableItemVM(short
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteShortcut() {
|
fun deleteShortcut() {
|
||||||
|
if (!canDelete) return
|
||||||
shortcutRepository.removePinnedShortcut(shortcut)
|
shortcutRepository.removePinnedShortcut(shortcut)
|
||||||
favoritesRepository.unpinItem(shortcut)
|
favoritesRepository.unpinItem(shortcut)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user