Skip to content

Commit

Permalink
fix: color didn't refresh immediately when users change it
Browse files Browse the repository at this point in the history
Co-authored-by: nopdan <xci@live.com>
  • Loading branch information
WhiredPlanck and nopdan committed Feb 2, 2024
1 parent 7f63473 commit ff944c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/com/osfans/trime/data/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Theme(private var isDarkMode: Boolean) {
liquidKeyboard = fullThemeConfigMap!!["liquid_keyboard"] as Map<String, Any?>?
}.also { Timber.d("Setting up all theme config map takes $it ms") }
measureTimeMillis {
refreshColorCaches(isDarkMode)
systemChangeColor(isDarkMode)
}.also { Timber.d("Initializing cache takes $it ms") }
Timber.i("The theme is initialized")
}.getOrElse {
Expand Down Expand Up @@ -330,15 +330,21 @@ class Theme(private var isDarkMode: Boolean) {
}

// 当切换暗黑模式时,刷新键盘配色方案
fun refreshColorCaches(isDarkMode: Boolean) {
fun systemChangeColor(isDarkMode: Boolean) {
this.isDarkMode = isDarkMode
currentColorSchemeId = getColorSchemeName()
Timber.d(
"Caching color values (currentColorSchemeId=$currentColorSchemeId, isDarkMode=$isDarkMode) ...",
"System changing color, current ColorScheme: $currentColorSchemeId, isDarkMode=$isDarkMode",
)
refreshColorValues()
}

fun fireChangeColor() {
currentColorSchemeId = getColorSchemeName()
Timber.d("Fire changing color, current color scheme: $currentColorSchemeId")
refreshColorValues()
}

private fun refreshColorValues() {
currentColors.clear()
val colorMap = presetColorSchemes!![currentColorSchemeId]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object ThemeManager {
fun onSystemNightModeChange(isNight: Boolean) {
isNightMode = isNight
if (::_activeTheme.isInitialized) {
activeTheme.refreshColorCaches(isNightMode)
activeTheme.systemChangeColor(isNightMode)
} else {
activeTheme = evalActiveTheme()
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ open class Trime : LifecycleInputMethodService() {
inputView!!.switchUiByState(KeyboardWindow.State.Main)
loadConfig()
val theme = ThemeManager.activeTheme
theme.fireChangeColor()
SoundThemeManager.switchSound(theme.colors.getString("sound"))
resetCandidate()
KeyboardSwitcher.newOrReset()
Expand Down

0 comments on commit ff944c3

Please sign in to comment.