Skip to content

Commit

Permalink
feat: add GeneralStyle to Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
goofyz committed Apr 17, 2024
1 parent dcc213d commit ae982ab
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/com/osfans/trime/data/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package com.osfans.trime.data.theme

import com.osfans.trime.core.Rime
import com.osfans.trime.data.AppPrefs
import com.osfans.trime.data.theme.mapper.GeneralStyleMapper
import com.osfans.trime.data.theme.model.GeneralStyle
import com.osfans.trime.util.config.Config
import com.osfans.trime.util.config.ConfigItem
import com.osfans.trime.util.config.ConfigList
Expand All @@ -29,6 +31,7 @@ import kotlin.system.measureTimeMillis
/** 主题和样式配置 */
class Theme(name: String) {
val style: Style
val generalStyle: GeneralStyle
val liquid: Liquid
val keyboards: Keyboards

Expand Down Expand Up @@ -74,6 +77,7 @@ class Theme(name: String) {
style = Style(config)
liquid = Liquid(config)
keyboards = Keyboards(config)
generalStyle = mapToGeneralStyle(config)
fallbackColors = config.getMap("fallback_colors")
presetKeys = config.getMap("preset_keys")
presetColorSchemes = config.getMap("preset_color_schemes")
Expand All @@ -82,6 +86,19 @@ class Theme(name: String) {
prefs.selectedTheme = name
}

private fun mapToGeneralStyle(config: Config): GeneralStyle {
val generalStyleMap = config.getMap("style")
val mapper = GeneralStyleMapper(generalStyleMap)
val generalStyle = mapper.map()

Timber.w(
"GeneralStyleMapper (%d) Warnings: %s",
mapper.errors.size,
mapper.errors.joinToString(","),
)
return generalStyle
}

class Style(private val config: Config) {
fun getString(key: String): String = config.getString("style/$key")

Expand Down

0 comments on commit ae982ab

Please sign in to comment.