android: more checks for colors in customized theme (#2343)

* android: more checks for colors in customized theme

* code style

* refactor

---------

Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
Stanislav Dmitrenko
2023-04-28 11:09:42 +03:00
committed by GitHub
parent c254b33753
commit 607f77d432
2 changed files with 15 additions and 10 deletions

View File

@@ -21,21 +21,26 @@ enum class DefaultTheme {
SYSTEM, LIGHT, DARK, SIMPLEX;
// Call it only with base theme, not SYSTEM
fun hasChangedAnyColor(colors: Colors): Boolean {
fun hasChangedAnyColor(colors: Colors, appColors: AppColors): Boolean {
val palette = when (this) {
SYSTEM -> return false
LIGHT -> LightColorPalette
DARK -> DarkColorPalette
SIMPLEX -> SimplexColorPalette
}
return with(palette) {
colors.primary != primary ||
colors.primaryVariant != primaryVariant ||
colors.secondary != secondary ||
colors.secondaryVariant != secondaryVariant ||
colors.background != background ||
colors.surface != surface
val appPalette = when (this) {
SYSTEM -> return false
LIGHT -> LightColorPaletteApp
DARK -> DarkColorPaletteApp
SIMPLEX -> SimplexColorPaletteApp
}
return colors.primary != palette.primary ||
colors.primaryVariant != palette.primaryVariant ||
colors.secondary != palette.secondary ||
colors.secondaryVariant != palette.secondaryVariant ||
colors.background != palette.background ||
colors.surface != palette.surface ||
appColors != appPalette
}
}

View File

@@ -229,14 +229,14 @@ fun CustomizeThemeView(editColor: (ThemeColor, Color) -> Unit) {
}
}
val isInDarkTheme = isInDarkTheme()
if (currentTheme.base.hasChangedAnyColor(currentTheme.colors)) {
if (currentTheme.base.hasChangedAnyColor(currentTheme.colors, currentTheme.appColors)) {
SectionItemView({ ThemeManager.resetAllThemeColors(darkForSystemTheme = isInDarkTheme) }) {
Text(generalGetString(R.string.reset_color), color = colors.primary)
}
}
SectionSpacer()
SectionView {
if (currentTheme.base.hasChangedAnyColor(currentTheme.colors)) {
if (currentTheme.base.hasChangedAnyColor(currentTheme.colors, currentTheme.appColors)) {
val context = LocalContext.current
val theme = remember { mutableStateOf(null as String?) }
val exportThemeLauncher = rememberSaveThemeLauncher(context, theme)