Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code of theme/flavors, theme_none() uses blue colors #891

Merged
merged 8 commits into from
Sep 29, 2023
Prev Previous commit
Minor cleanup code.
  • Loading branch information
OLarionova-HORIS committed Sep 29, 2023
commit 88a30d0239fecaea226db096dab9b9d03e89701b
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,16 @@ object ThemeUtil {

// open for ThemeOptionTest
internal fun getThemeValues(themeName: String, userOptions: Map<String, Any> = emptyMap()): Map<String, Any> {
val baselineValues = ThemeValues.forName(themeName).values
val baselineValues = ThemeValues.forName(themeName)

val flavorName = if (themeName != ThemeOption.Name.LP_NONE) {
// use flavor to not 'none' theme only
userOptions[ThemeOption.FLAVOR] as? String
?: baselineValues[ThemeOption.FLAVOR] as? String
?: error("Flavor name should be specified")
} else {
null
}
val effectiveOptions = baselineValues + userOptions

return (flavorName?.let { applyFlavor(baselineValues, flavorName) } ?: baselineValues)
.mergeWith(userOptions)
}
if (themeName == ThemeOption.Name.LP_NONE) {
// Not apply flavor to 'none' theme
return effectiveOptions
}

private fun applyFlavor(themeSettings: Map<String, Any>, flavorName: String): Map<String, Any> {
val flavorName = effectiveOptions[ThemeOption.FLAVOR] as? String ?: error("Flavor name should be specified")
val flavor = ThemeFlavor.forName(flavorName)

val geomThemeOptions = mapOf(
Expand All @@ -52,20 +46,16 @@ object ThemeUtil {
)

// resolve symbolic colors
val withResolvedColors = themeSettings.mapValues { (parameter, options) ->
if (options !is Map<*, *>) {
return@mapValues options
}
options.mapValues { (key, value) ->
when (value) {
!is SymbolicColor -> value
else -> flavor.symbolicColors[value]
?: error("Undefined color in flavor scheme = '$flavorName': '$parameter': '${key}' = '${value.name}'")
}
val withResolvedColors = effectiveOptions.mapValues { (parameter, options) ->
val subOptions = options as? Map<*, *> ?: return@mapValues options
subOptions.mapValues subOptionsScope@{ (key, value) ->
val color = value as? SymbolicColor ?: return@subOptionsScope value
flavor.symbolicColors[color]
?: error("Undefined color in flavor scheme = '$flavorName': '$parameter': '${key}' = '${color.name}'")
}
}
.mergeWith(flavor.specialColors)

return geomThemeOptions + withResolvedColors
return geomThemeOptions.mergeWith(withResolvedColors)
}
}