Add color scheme duplicate and delete actions
This commit is contained in:
parent
9c70a495f8
commit
d8e108cb70
@ -11,16 +11,20 @@ import androidx.compose.foundation.layout.padding
|
|||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.material.icons.Icons
|
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.Edit
|
||||||
import androidx.compose.material.icons.rounded.MoreVert
|
import androidx.compose.material.icons.rounded.MoreVert
|
||||||
import androidx.compose.material.icons.rounded.RadioButtonChecked
|
import androidx.compose.material.icons.rounded.RadioButtonChecked
|
||||||
import androidx.compose.material.icons.rounded.RadioButtonUnchecked
|
import androidx.compose.material.icons.rounded.RadioButtonUnchecked
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@ -51,6 +55,8 @@ fun ThemesSettingsScreen() {
|
|||||||
val selectedTheme by viewModel.selectedTheme.collectAsStateWithLifecycle(null)
|
val selectedTheme by viewModel.selectedTheme.collectAsStateWithLifecycle(null)
|
||||||
val themes by viewModel.themes.collectAsStateWithLifecycle(emptyList())
|
val themes by viewModel.themes.collectAsStateWithLifecycle(emptyList())
|
||||||
|
|
||||||
|
var deleteTheme by remember { mutableStateOf<Theme?>(null) }
|
||||||
|
|
||||||
PreferenceScreen(title = stringResource(R.string.preference_screen_colors)) {
|
PreferenceScreen(title = stringResource(R.string.preference_screen_colors)) {
|
||||||
item {
|
item {
|
||||||
PreferenceCategory {
|
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
|
@Composable
|
||||||
|
|||||||
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -824,4 +824,5 @@
|
|||||||
<string name="note_widget_file_read_error_description">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.</string>
|
<string name="note_widget_file_read_error_description">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.</string>
|
||||||
<string name="note_widget_file_write_error">Error saving note</string>
|
<string name="note_widget_file_write_error">Error saving note</string>
|
||||||
<string name="note_widget_file_write_error_description">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.</string>
|
<string name="note_widget_file_write_error_description">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.</string>
|
||||||
|
<string name="confirmation_delete_color_scheme">Do you really want to delete the color scheme %1$s?</string>
|
||||||
</resources>
|
</resources>
|
||||||
@ -79,4 +79,10 @@ class ThemeRepository(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteTheme(theme: Theme) {
|
||||||
|
scope.launch {
|
||||||
|
database.themeDao().delete(theme.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user