Move scheme creation button

This commit is contained in:
MM20
2026-02-01 16:38:25 +01:00
parent bd77ea8338
commit b4697a6fb2
9 changed files with 111 additions and 42 deletions

View File

@@ -11,9 +11,11 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuGroup
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.DropdownMenuPopup
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -64,11 +66,6 @@ fun ColorSchemesSettingsScreen() {
PreferenceScreen(
title = stringResource(R.string.preference_screen_colors),
topBarActions = {
IconButton(onClick = { viewModel.createNew(context) }) {
Icon(painterResource(R.drawable.add_24px), null)
}
},
) {
item {
PreferenceCategory {
@@ -199,6 +196,25 @@ fun ColorSchemesSettingsScreen() {
}
}
}
item {
FilledTonalButton(
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
onClick = {
val uuid = viewModel.createNew(context)
backStack.add(ColorSchemeSettingsRoute(uuid))
}) {
Icon(
painterResource(R.drawable.add_20px),
null,
modifier = Modifier
.padding(end = ButtonDefaults.IconSpacing)
.size(ButtonDefaults.IconSize)
)
Text(stringResource(R.string.preference_create_colors))
}
}
}
if (deleteColors != null) {
AlertDialog(

View File

@@ -7,16 +7,12 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import de.mm20.launcher2.ktx.tryStartActivity
import de.mm20.launcher2.preferences.ui.UiSettings
import de.mm20.launcher2.themes.BlackAndWhiteThemeId
import de.mm20.launcher2.themes.DefaultThemeId
import de.mm20.launcher2.themes.colors.Colors
import de.mm20.launcher2.themes.HighContrastThemeId
import de.mm20.launcher2.themes.ThemeRepository
import de.mm20.launcher2.themes.colors.Colors
import de.mm20.launcher2.themes.toLegacyJson
import de.mm20.launcher2.ui.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.core.component.KoinComponent
@@ -62,21 +58,25 @@ class ColorSchemesSettingsScreenVM : ViewModel(), KoinComponent {
context.tryStartActivity(Intent().apply {
action = Intent.ACTION_SEND
type = "application/json"
putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".fileprovider",
file
))
putExtra(
Intent.EXTRA_STREAM, FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".fileprovider",
file
)
)
}.let { Intent.createChooser(it, null) })
}
}
fun createNew(context: Context) {
fun createNew(context: Context): UUID {
val uuid = UUID.randomUUID()
themeRepository.colors.create(
Colors(
id = UUID.randomUUID(),
id = uuid,
name = context.getString(R.string.new_theme_name)
)
)
return uuid
}
}

View File

@@ -8,10 +8,11 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CutCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuGroup
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.DropdownMenuPopup
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -42,7 +43,7 @@ import de.mm20.launcher2.ui.locals.LocalBackStack
import kotlinx.serialization.Serializable
@Serializable
data object ShapeSchemesSettingsRoute: NavKey
data object ShapeSchemesSettingsRoute : NavKey
@Composable
fun ShapeSchemesSettingsScreen() {
@@ -59,11 +60,6 @@ fun ShapeSchemesSettingsScreen() {
PreferenceScreen(
title = stringResource(R.string.preference_screen_shapes),
topBarActions = {
IconButton(onClick = { viewModel.createNew(context) }) {
Icon(painterResource(R.drawable.add_24px), null)
}
},
) {
item {
PreferenceCategory {
@@ -99,6 +95,7 @@ fun ShapeSchemesSettingsScreen() {
},
text = { Text(stringResource(R.string.duplicate)) },
onClick = {
viewModel.duplicate(theme)
showMenu = false
}
@@ -193,6 +190,24 @@ fun ShapeSchemesSettingsScreen() {
}
}
}
item {
FilledTonalButton(
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
onClick = {
val uuid = viewModel.createNew(context)
backStack.add(ShapeSchemeSettingsRoute(uuid))
}) {
Icon(
painterResource(R.drawable.add_20px),
null,
modifier = Modifier
.padding(end = ButtonDefaults.IconSpacing)
.size(ButtonDefaults.IconSize)
)
Text(stringResource(R.string.preference_create_shapes))
}
}
}
if (deleteShapes != null) {
AlertDialog(

View File

@@ -3,14 +3,13 @@ package de.mm20.launcher2.ui.settings.shapes
import android.content.Context
import androidx.lifecycle.ViewModel
import de.mm20.launcher2.preferences.ui.UiSettings
import de.mm20.launcher2.themes.shapes.Shapes
import de.mm20.launcher2.themes.ThemeRepository
import de.mm20.launcher2.themes.shapes.Shapes
import de.mm20.launcher2.ui.R
import kotlinx.coroutines.flow.Flow
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
import java.util.UUID
import kotlin.getValue
class ShapeSchemesSettingsScreenVM : ViewModel(), KoinComponent {
@@ -40,12 +39,14 @@ class ShapeSchemesSettingsScreenVM : ViewModel(), KoinComponent {
themeRepository.shapes.delete(shapes)
}
fun createNew(context: Context) {
fun createNew(context: Context): UUID {
val uuid = UUID.randomUUID()
themeRepository.shapes.create(
Shapes(
id = UUID.randomUUID(),
id = uuid,
name = context.getString(R.string.new_theme_name)
)
)
return uuid
}
}

View File

@@ -5,11 +5,14 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenuGroup
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.DropdownMenuPopup
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -39,6 +42,7 @@ import de.mm20.launcher2.ui.component.preferences.Preference
import de.mm20.launcher2.ui.component.preferences.PreferenceCategory
import de.mm20.launcher2.ui.component.preferences.PreferenceScreen
import de.mm20.launcher2.ui.locals.LocalBackStack
import de.mm20.launcher2.ui.settings.typography.TypographySettingsRoute
import de.mm20.launcher2.ui.theme.WallpaperColors
import de.mm20.launcher2.ui.theme.transparency.transparencySchemeOf
import de.mm20.launcher2.ui.theme.wallpaperColorsAsState
@@ -64,11 +68,6 @@ fun TransparencySchemesSettingsScreen() {
PreferenceScreen(
title = stringResource(R.string.preference_screen_transparencies),
topBarActions = {
IconButton(onClick = { viewModel.createNew(context) }) {
Icon(painterResource(R.drawable.add_24px), null)
}
},
) {
item {
PreferenceCategory {
@@ -202,6 +201,22 @@ fun TransparencySchemesSettingsScreen() {
}
}
}
item {
FilledTonalButton(
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
onClick = {
val uuid = viewModel.createNew(context)
backStack.add(TransparencySchemeSettingsRoute(uuid))
}) {
Icon(
painterResource(R.drawable.add_20px),
null,
modifier = Modifier.padding(end = ButtonDefaults.IconSpacing).size(ButtonDefaults.IconSize)
)
Text(stringResource(R.string.preference_create_transparency))
}
}
}
if (deleteTransparencies != null) {
AlertDialog(

View File

@@ -39,12 +39,14 @@ class TransparencySchemesSettingsScreenVM : ViewModel(), KoinComponent {
themeRepository.transparencies.delete(transparencies)
}
fun createNew(context: Context) {
fun createNew(context: Context): UUID {
val uuid = UUID.randomUUID()
themeRepository.transparencies.create(
Transparencies(
id = UUID.randomUUID(),
id = uuid,
name = context.getString(R.string.new_theme_name)
)
)
return uuid
}
}

View File

@@ -4,11 +4,14 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuGroup
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.DropdownMenuPopup
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
@@ -29,6 +32,7 @@ import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation3.runtime.NavKey
import de.mm20.launcher2.themes.typography.FontFamily
import de.mm20.launcher2.themes.typography.Typography
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.preferences.Preference
@@ -57,11 +61,6 @@ fun TypographiesSettingsScreen() {
PreferenceScreen(
title = stringResource(R.string.preference_screen_typography),
topBarActions = {
IconButton(onClick = { viewModel.createNew(context) }) {
Icon(painterResource(R.drawable.add_24px), null)
}
},
) {
item {
PreferenceCategory {
@@ -220,6 +219,21 @@ fun TypographiesSettingsScreen() {
}
}
}
item {
FilledTonalButton(
contentPadding = ButtonDefaults.ButtonWithIconContentPadding,
onClick = {
val uuid = viewModel.createNew(context)
backStack.add(TypographySettingsRoute(uuid))
}) {
Icon(
painterResource(R.drawable.add_20px),
null,
modifier = Modifier.padding(end = ButtonDefaults.IconSpacing).size(ButtonDefaults.IconSize)
)
Text(stringResource(R.string.preference_create_typography))
}
}
}
}
if (deleteTypography != null) {

View File

@@ -39,12 +39,14 @@ class TypographySettingsScreenVM : ViewModel(), KoinComponent {
themeRepository.typographies.delete(typography)
}
fun createNew(context: Context) {
fun createNew(context: Context): UUID {
val uuid = UUID.randomUUID()
themeRepository.typographies.create(
Typography(
id = UUID.randomUUID(),
id = uuid,
name = context.getString(R.string.new_theme_name)
)
)
return uuid
}
}