From d8e108cb70ab21830944955827eca86eed72aa14 Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Fri, 25 Aug 2023 18:40:14 +0200 Subject: [PATCH] Add color scheme duplicate and delete actions --- .../colorscheme/ThemesSettingsScreen.kt | 51 +++++++++++++++++++ .../colorscheme/ThemesSettingsScreenVM.kt | 8 +++ core/i18n/src/main/res/values/strings.xml | 1 + .../mm20/launcher2/themes/ThemeRepository.kt | 6 +++ 4 files changed, 66 insertions(+) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt index 48f3f396..2a48a88b 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreen.kt @@ -11,16 +11,20 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ContentCopy +import androidx.compose.material.icons.rounded.Delete import androidx.compose.material.icons.rounded.Edit import androidx.compose.material.icons.rounded.MoreVert import androidx.compose.material.icons.rounded.RadioButtonChecked import androidx.compose.material.icons.rounded.RadioButtonUnchecked +import androidx.compose.material3.AlertDialog import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -51,6 +55,8 @@ fun ThemesSettingsScreen() { val selectedTheme by viewModel.selectedTheme.collectAsStateWithLifecycle(null) val themes by viewModel.themes.collectAsStateWithLifecycle(emptyList()) + var deleteTheme by remember { mutableStateOf(null) } + PreferenceScreen(title = stringResource(R.string.preference_screen_colors)) { item { PreferenceCategory { @@ -85,6 +91,28 @@ fun ThemesSettingsScreen() { } ) } + DropdownMenuItem( + leadingIcon = { + Icon(Icons.Rounded.ContentCopy, null) + }, + text = { Text(stringResource(R.string.duplicate)) }, + onClick = { + viewModel.duplicate(theme) + showMenu = false + } + ) + if (!theme.builtIn) { + DropdownMenuItem( + leadingIcon = { + Icon(Icons.Rounded.Delete, null) + }, + text = { Text(stringResource(R.string.menu_delete)) }, + onClick = { + deleteTheme = theme + showMenu = false + } + ) + } } } }, @@ -96,6 +124,29 @@ fun ThemesSettingsScreen() { } } } + if (deleteTheme != null) { + AlertDialog( + onDismissRequest = { deleteTheme = null }, + text = { Text(stringResource(R.string.confirmation_delete_color_scheme, deleteTheme!!.name)) }, + confirmButton = { + TextButton( + onClick = { + viewModel.delete(deleteTheme!!) + deleteTheme = null + } + ) { + Text(stringResource(android.R.string.ok)) + } + }, + dismissButton = { + TextButton( + onClick = { deleteTheme = null } + ) { + Text(stringResource(android.R.string.cancel)) + } + } + ) + } } @Composable diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt index b8447da5..3ed6dafe 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/colorscheme/ThemesSettingsScreenVM.kt @@ -49,4 +49,12 @@ class ThemesSettingsScreenVM : ViewModel(), KoinComponent { } } } + + fun duplicate(theme: Theme) { + themeRepository.createTheme(theme.copy(id = UUID.randomUUID())) + } + + fun delete(theme: Theme) { + themeRepository.deleteTheme(theme) + } } \ No newline at end of file diff --git a/core/i18n/src/main/res/values/strings.xml b/core/i18n/src/main/res/values/strings.xml index e6eae94e..39487279 100644 --- a/core/i18n/src/main/res/values/strings.xml +++ b/core/i18n/src/main/res/values/strings.xml @@ -824,4 +824,5 @@ The linked file could not be read. Possibly, it has been moved or deleted. A copy has been restored from the launcher\'s internal storage. If you edit the note, the linked file will possibly be overwritten. Error saving note The note could not be written to the linked file. Possibly, it has been moved or deleted. A copy has been saved to the launcher\'s internal storage. + Do you really want to delete the color scheme %1$s? \ No newline at end of file diff --git a/data/themes/src/main/java/de/mm20/launcher2/themes/ThemeRepository.kt b/data/themes/src/main/java/de/mm20/launcher2/themes/ThemeRepository.kt index bfdba738..f20e53ae 100644 --- a/data/themes/src/main/java/de/mm20/launcher2/themes/ThemeRepository.kt +++ b/data/themes/src/main/java/de/mm20/launcher2/themes/ThemeRepository.kt @@ -79,4 +79,10 @@ class ThemeRepository( ) } + fun deleteTheme(theme: Theme) { + scope.launch { + database.themeDao().delete(theme.id) + } + } + } \ No newline at end of file