From 2d38cf0805a517878f33aa6d1a42c35401400b6a Mon Sep 17 00:00:00 2001 From: Helium314 Date: Wed, 5 Feb 2025 05:42:10 +0100 Subject: [PATCH] make sure holo white is not selectable without holo style --- .../helium314/keyboard/settings/Preference.kt | 4 ++-- .../keyboard/settings/SettingsActivity.kt | 4 +--- .../settings/screens/AppearanceScreen.kt | 21 ++++++++++++++++--- .../settings/screens/GestureTypingScreen.kt | 2 +- .../settings/screens/TextCorrectionScreen.kt | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/Preference.kt b/app/src/main/java/helium314/keyboard/settings/Preference.kt index 131035c05..7d4b692cd 100644 --- a/app/src/main/java/helium314/keyboard/settings/Preference.kt +++ b/app/src/main/java/helium314/keyboard/settings/Preference.kt @@ -136,7 +136,7 @@ fun SwitchPreference( val ctx = LocalContext.current val prefs = ctx.prefs() val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() - if (b?.value ?: 0 < 0) + if ((b?.value ?: 0) < 0) Log.v("irrelevant", "stupid way to trigger recomposition on preference change") var value = prefs.getBoolean(pref, default) fun switched(newValue: Boolean) { @@ -194,7 +194,7 @@ fun SliderPreference( val ctx = LocalContext.current val prefs = ctx.prefs() val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() - if (b?.value ?: 0 < 0) + if ((b?.value ?: 0) < 0) Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val initialValue = if (default is Int || default is Float) getPrefOfType(prefs, pref, default) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index 3e5373470..fb991e9c1 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -16,9 +16,6 @@ import kotlinx.coroutines.flow.MutableStateFlow // todo (roughly in order) // make all prefs actually work // appearance -// holo white selectable for non-holo style if we had selected holo theme before -// the list just stays the old one after changing the setting -// also, even if selected it should not be used... // click on bg image does nothing when already set (but works after reload) // split spacer scale setting does not reload? // narrow key gaps setting is not changing properly? @@ -29,6 +26,7 @@ import kotlinx.coroutines.flow.MutableStateFlow // try moving the recomposition of pref change somewhere else, so it's not duplicated everywhere // make the pref lists more compact (compare with old settings) // try making text size similar to old state (also in dialogs) +// more similar dialog style args (for all dialogs, or for none) // check whether dialogs have the same colors, i think currently it's a bit inconsistent // see all the properties for each alertDialog -> any way to set it in a single place? // title too huge for bg image and text on spacebar dialogs, also maybe somewhere else -> where to set in one place? diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt index 6e7676671..b450bcd08 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt @@ -60,7 +60,7 @@ fun AppearanceScreen( val ctx = LocalContext.current val prefs = ctx.prefs() val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() - if (b?.value ?: 0 < 0) + if ((b?.value ?: 0) < 0) Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val dayNightMode = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && Settings.readDayNightPref(prefs, ctx.resources) val lightTheme = prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT) @@ -102,6 +102,7 @@ fun AppearanceScreen( fun createAppearancePrefs(context: Context) = listOf( PrefDef(context, Settings.PREF_THEME_STYLE, R.string.theme_style) { def -> val ctx = LocalContext.current + val prefs = ctx.prefs() val items = KeyboardTheme.STYLES.map { it.getStringResourceOrName("style_name_", ctx) to it } @@ -109,7 +110,15 @@ fun createAppearancePrefs(context: Context) = listOf( def, items, KeyboardTheme.STYLE_MATERIAL - ) + ) { + if (it != KeyboardTheme.STYLE_HOLO) { + // todo: use defaults once they exist + if (prefs.getString(Settings.PREF_THEME_COLORS, "") == KeyboardTheme.THEME_HOLO_WHITE) + prefs.edit().putString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT).apply() + if (prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, "") == KeyboardTheme.THEME_HOLO_WHITE) + prefs.edit().putString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK).apply() + } + } }, PrefDef(context, Settings.PREF_ICON_STYLE, R.string.icon_style) { def -> val ctx = LocalContext.current @@ -138,6 +147,9 @@ fun createAppearancePrefs(context: Context) = listOf( }, PrefDef(context, Settings.PREF_THEME_COLORS, R.string.theme_colors) { def -> val ctx = LocalContext.current + val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() + if ((b?.value ?: 0) < 0) + Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL) val items = KeyboardTheme.COLORS.mapNotNull { if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle != KeyboardTheme.STYLE_HOLO) @@ -152,8 +164,11 @@ fun createAppearancePrefs(context: Context) = listOf( }, PrefDef(context, Settings.PREF_THEME_COLORS_NIGHT, R.string.theme_colors_night) { def -> val ctx = LocalContext.current + val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() + if ((b?.value ?: 0) < 0) + Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val currentStyle = ctx.prefs().getString(Settings.PREF_THEME_STYLE, KeyboardTheme.STYLE_MATERIAL) - val items = KeyboardTheme.COLORS.mapNotNull { + val items = KeyboardTheme.COLORS_DARK.mapNotNull { if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO) return@mapNotNull null it.getStringResourceOrName("theme_name_", ctx) to it diff --git a/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt index b02a6fe16..188eea347 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt @@ -28,7 +28,7 @@ fun GestureTypingScreen( ) { val prefs = LocalContext.current.prefs() val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() - if (b?.value ?: 0 < 0) + if ((b?.value ?: 0) < 0) Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val gestureEnabled = prefs.getBoolean(Settings.PREF_GESTURE_INPUT, true) val gestureTrailEnabled = prefs.getBoolean(Settings.PREF_GESTURE_PREVIEW_TRAIL, true) diff --git a/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt index c49d78807..2fb9e91d7 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt @@ -49,7 +49,7 @@ fun TextCorrectionScreen( ) { val prefs = LocalContext.current.prefs() val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() - if (b?.value ?: 0 < 0) + if ((b?.value ?: 0) < 0) Log.v("irrelevant", "stupid way to trigger recomposition on preference change") val autocorrectEnabled = prefs.getBoolean(Settings.PREF_AUTO_CORRECTION, true) val personalizedSuggestionsEnabled = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true)