Skip to content

Commit ff944c3

Browse files
WhiredPlancknopdan
andcommitted
fix: color didn't refresh immediately when users change it
Co-authored-by: nopdan <[email protected]>
1 parent 7f63473 commit ff944c3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

app/src/main/java/com/osfans/trime/data/theme/Theme.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Theme(private var isDarkMode: Boolean) {
102102
liquidKeyboard = fullThemeConfigMap!!["liquid_keyboard"] as Map<String, Any?>?
103103
}.also { Timber.d("Setting up all theme config map takes $it ms") }
104104
measureTimeMillis {
105-
refreshColorCaches(isDarkMode)
105+
systemChangeColor(isDarkMode)
106106
}.also { Timber.d("Initializing cache takes $it ms") }
107107
Timber.i("The theme is initialized")
108108
}.getOrElse {
@@ -330,15 +330,21 @@ class Theme(private var isDarkMode: Boolean) {
330330
}
331331

332332
// 当切换暗黑模式时,刷新键盘配色方案
333-
fun refreshColorCaches(isDarkMode: Boolean) {
333+
fun systemChangeColor(isDarkMode: Boolean) {
334334
this.isDarkMode = isDarkMode
335335
currentColorSchemeId = getColorSchemeName()
336336
Timber.d(
337-
"Caching color values (currentColorSchemeId=$currentColorSchemeId, isDarkMode=$isDarkMode) ...",
337+
"System changing color, current ColorScheme: $currentColorSchemeId, isDarkMode=$isDarkMode",
338338
)
339339
refreshColorValues()
340340
}
341341

342+
fun fireChangeColor() {
343+
currentColorSchemeId = getColorSchemeName()
344+
Timber.d("Fire changing color, current color scheme: $currentColorSchemeId")
345+
refreshColorValues()
346+
}
347+
342348
private fun refreshColorValues() {
343349
currentColors.clear()
344350
val colorMap = presetColorSchemes!![currentColorSchemeId]

app/src/main/java/com/osfans/trime/data/theme/ThemeManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object ThemeManager {
8989
fun onSystemNightModeChange(isNight: Boolean) {
9090
isNightMode = isNight
9191
if (::_activeTheme.isInitialized) {
92-
activeTheme.refreshColorCaches(isNightMode)
92+
activeTheme.systemChangeColor(isNightMode)
9393
} else {
9494
activeTheme = evalActiveTheme()
9595
}

app/src/main/java/com/osfans/trime/ime/core/Trime.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ open class Trime : LifecycleInputMethodService() {
372372
inputView!!.switchUiByState(KeyboardWindow.State.Main)
373373
loadConfig()
374374
val theme = ThemeManager.activeTheme
375+
theme.fireChangeColor()
375376
SoundThemeManager.switchSound(theme.colors.getString("sound"))
376377
resetCandidate()
377378
KeyboardSwitcher.newOrReset()

0 commit comments

Comments
 (0)