From 360c2f4ada005c7ed58d97484fbb2754e6777e7b Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Tue, 7 May 2024 12:17:44 -0500 Subject: [PATCH] Fix wrong update check for theme --- .../org/futo/inputmethod/latin/LatinIME.kt | 3 --- .../latin/uix/BasicThemeProvider.kt | 22 +++++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index b4feefc43..13b16f64f 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -53,9 +53,6 @@ import org.futo.inputmethod.latin.uix.DynamicThemeProvider import org.futo.inputmethod.latin.uix.DynamicThemeProviderOwner import org.futo.inputmethod.latin.uix.EmojiTracker.unuseEmoji import org.futo.inputmethod.latin.uix.EmojiTracker.useEmoji -import org.futo.inputmethod.latin.uix.HiddenKeysSetting -import org.futo.inputmethod.latin.uix.KeyBordersSetting -import org.futo.inputmethod.latin.uix.KeyHintsSetting import org.futo.inputmethod.latin.uix.KeyboardBottomOffsetSetting import org.futo.inputmethod.latin.uix.SUGGESTION_BLACKLIST import org.futo.inputmethod.latin.uix.THEME_KEY diff --git a/java/src/org/futo/inputmethod/latin/uix/BasicThemeProvider.kt b/java/src/org/futo/inputmethod/latin/uix/BasicThemeProvider.kt index 680e3f378..acdf44c61 100644 --- a/java/src/org/futo/inputmethod/latin/uix/BasicThemeProvider.kt +++ b/java/src/org/futo/inputmethod/latin/uix/BasicThemeProvider.kt @@ -56,6 +56,10 @@ fun adjustColorBrightnessForContrast(bgColor: Int, fgColor: Int, desiredContrast return ColorUtils.HSLToColor(bgHSL) } +fun Preferences.get(key: SettingsKey): T { + return this[key.key] ?: key.default +} + class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorScheme? = null) : DynamicThemeProvider { override val primaryKeyboardColor: Int @@ -133,16 +137,11 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch val keyboardHeight: Float - fun hasUpdated(newPreferences: Preferences): Boolean { - return when { - newPreferences[HiddenKeysSetting.key] != expertMode -> true - newPreferences[KeyBordersSetting.key] != keyBorders -> true - newPreferences[KeyHintsSetting.key] != showKeyHints -> true - - newPreferences[KeyboardHeightMultiplierSetting.key] != keyboardHeight -> true - - else -> false - } + fun hasUpdated(np: Preferences): Boolean { + return np.get(HiddenKeysSetting) != expertMode + || np.get(KeyBordersSetting) != keyBorders + || np.get(KeyHintsSetting) != showKeyHints + || np.get(KeyboardHeightMultiplierSetting) != keyboardHeight } init { @@ -159,8 +158,7 @@ class BasicThemeProvider(val context: Context, val overrideColorScheme: ColorSch expertMode = context.getSettingBlocking(HiddenKeysSetting) keyBorders = context.getSettingBlocking(KeyBordersSetting) showKeyHints = context.getSettingBlocking(KeyHintsSetting) - - keyboardHeight = context.getSettingBlocking(KeyboardHeightMultiplierSetting.key, KeyboardHeightMultiplierSetting.default) + keyboardHeight = context.getSettingBlocking(KeyboardHeightMultiplierSetting) val primary = colorScheme.primary.toArgb() val secondary = colorScheme.secondary.toArgb()