From 5ddfd633925c05da78cea66e91008c0f2bc63aa5 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Wed, 29 Jan 2025 23:18:06 +0100 Subject: [PATCH] add advanced pref screen (not fully functional) --- .../helium314/keyboard/settings/AllPrefs.kt | 9 +- .../helium314/keyboard/settings/Preference.kt | 60 +++- .../keyboard/settings/SettingsActivity.kt | 11 +- .../keyboard/settings/SettingsNavHost.kt | 22 +- .../screens/AdvancedSettingsScreen.kt | 263 ++++++++++++++++++ .../settings/screens/GestureTypingScreen.kt | 2 +- .../settings/screens/MainSettingsScreen.kt | 16 +- .../settings/screens/TextCorrectionScreen.kt | 23 +- 8 files changed, 372 insertions(+), 34 deletions(-) create mode 100644 app/src/main/java/helium314/keyboard/settings/screens/AdvancedSettingsScreen.kt diff --git a/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt b/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt index a4cdb526d..ba00bd050 100644 --- a/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt +++ b/app/src/main/java/helium314/keyboard/settings/AllPrefs.kt @@ -9,6 +9,7 @@ import androidx.annotation.StringRes import androidx.compose.runtime.Composable import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.settings.screens.createAboutPrefs +import helium314.keyboard.settings.screens.createAdvancedPrefs import helium314.keyboard.settings.screens.createCorrectionPrefs import helium314.keyboard.settings.screens.createGestureTypingPrefs import helium314.keyboard.settings.screens.createPreferencesPrefs @@ -56,7 +57,7 @@ class PrefDef( private fun createPrefDefs(context: Context) = createAboutPrefs(context) + createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context) + - createGestureTypingPrefs(context) + createGestureTypingPrefs(context) + createAdvancedPrefs(context) // todo: move somewhere else fun Context.getActivity(): ComponentActivity? { @@ -79,7 +80,13 @@ object NonSettingsPrefs { const val GITHUB = "github" const val SAVE_LOG = "save_log" const val CUSTOM_KEY_CODES = "customize_key_codes" + const val CUSTOM_SYMBOLS_NUMBER_LAYOUTS = "custom_symbols_number_layouts" + const val CUSTOM_FUNCTIONAL_LAYOUTS = "custom_functional_key_layouts" + const val BACKUP_RESTORE = "backup_restore" + const val DEBUG_SETTINGS = "screen_debug" + const val LOAD_GESTURE_LIB = "load_gesture_library" } @JvmField +// todo: maybe better name it "reloadKeyboard"? var themeChanged = false diff --git a/app/src/main/java/helium314/keyboard/settings/Preference.kt b/app/src/main/java/helium314/keyboard/settings/Preference.kt index 77427bac5..ffdacf138 100644 --- a/app/src/main/java/helium314/keyboard/settings/Preference.kt +++ b/app/src/main/java/helium314/keyboard/settings/Preference.kt @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only package helium314.keyboard.settings +import android.content.SharedPreferences import androidx.annotation.DrawableRes import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -30,12 +31,15 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.Hyphens import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.core.content.edit import helium314.keyboard.latin.R import helium314.keyboard.latin.utils.Log +import helium314.keyboard.settings.dialogs.ListPickerDialog import helium314.keyboard.settings.dialogs.SliderDialog // taken from StreetComplete (and a bit SCEE) @@ -201,8 +205,8 @@ fun SliderPreference( 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 initialValue = if (default is Int) prefs.getInt(pref, default) - else if (default is Float) prefs.getFloat(pref, default) + val initialValue = if (default is Int || default is Float) + getPrefOfType(prefs, pref, default) else throw IllegalArgumentException("only float and int are supported") var showDialog by remember { mutableStateOf(false) } @@ -230,6 +234,58 @@ fun SliderPreference( ) } +@Composable +fun ListPreference( + def: PrefDef, + items: List>, + default: T, +) { + var showDialog by remember { mutableStateOf(false) } + // todo: get rid of the arrays from old settings + val prefs = LocalContext.current.prefs() + val selected = items.firstOrNull { it.second == getPrefOfType(prefs, def.key, default) } + Preference( + name = def.title, + description = selected?.first, + onClick = { showDialog = true } + ) + if (showDialog) { + ListPickerDialog( + onDismissRequest = { showDialog = false }, + items = items, + onItemSelected = { + if (it != selected) + putPrefOfType(prefs, def.key, it.second) + }, + selectedItem = selected, + title = { Text(def.title) }, + getItemName = { it.first } + ) + } +} + +private fun getPrefOfType(prefs: SharedPreferences, key: String, default: T): T = + when (default) { + is String -> prefs.getString(key, default) + is Int -> prefs.getInt(key, default) + is Long -> prefs.getLong(key, default) + is Float -> prefs.getFloat(key, default) + is Boolean -> prefs.getBoolean(key, default) + else -> throw IllegalArgumentException("unknown type ${default.javaClass}") + } as T + +private fun putPrefOfType(prefs: SharedPreferences, key: String, value: T) = + prefs.edit { + when (value) { + is String -> putString(key, value) + is Int -> putInt(key, value) + is Long -> putLong(key, value) + is Float -> putFloat(key, value) + is Boolean -> putBoolean(key, value) + else -> throw IllegalArgumentException("unknown type ${value.javaClass}") + } + } + @Preview @Composable private fun PreferencePreview() { diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index 62e7c93b5..a4cb14ebf 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -14,9 +14,11 @@ import kotlinx.coroutines.flow.MutableStateFlow // todo // more pref screens -// other super-custom things -// toolbar key customizer (missing from toolbar screen) -// icon selector +// debug +// appearance +// colors +// personal dictionary +// languages (maybe separately) // consider IME insets when searching // improve performance when loading screens with many settings (lazyColumn?) // screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding @@ -53,6 +55,7 @@ import kotlinx.coroutines.flow.MutableStateFlow // -> users confused, but probably better than the 2 above // adjust layout a little, there is too much empty space and titles are too large (dialogs!) // check dialogs have the same colors +// list preference -> we can make auto_correct_threshold a float directly // maybe later // weird problem with app sometimes closing on back, but that's related to "old" settings (don't care if all are removed) @@ -64,6 +67,8 @@ import kotlinx.coroutines.flow.MutableStateFlow // adjust the debug settings thing, so that users can always find them in search but nowhere else? unless debug mode // search only in current pref screen, except when in main? // try getting rid of appcompat stuff (activity, dialogs, ...) +// re-organize screens, no need to keep exactly the same arrangement +// use simple list picker // preliminary results: // looks ok (ugly M3 switches) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt b/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt index 327da3511..584929494 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt @@ -11,6 +11,7 @@ import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import helium314.keyboard.settings.screens.AboutScreen +import helium314.keyboard.settings.screens.AdvancedSettingsScreen import helium314.keyboard.settings.screens.GestureTypingScreen import helium314.keyboard.settings.screens.MainSettingsScreen import helium314.keyboard.settings.screens.PreferencesScreen @@ -52,6 +53,7 @@ fun SettingsNavHost( onClickPreferences = { navController.navigate(SettingsDestination.Preferences) }, onClickToolbar = { navController.navigate(SettingsDestination.Toolbar) }, onClickGestureTyping = { navController.navigate(SettingsDestination.GestureTyping) }, + onClickAdvanced = { navController.navigate(SettingsDestination.Advanced) }, onClickBack = ::goBack, ) } @@ -61,25 +63,35 @@ fun SettingsNavHost( ) } composable(SettingsDestination.TextCorrection) { - TextCorrectionScreen ( + TextCorrectionScreen( onClickBack = ::goBack ) } composable(SettingsDestination.Preferences) { - PreferencesScreen ( + PreferencesScreen( onClickBack = ::goBack ) } composable(SettingsDestination.Toolbar) { - ToolbarScreen ( + ToolbarScreen( onClickBack = ::goBack ) } composable(SettingsDestination.GestureTyping) { - GestureTypingScreen ( + GestureTypingScreen( onClickBack = ::goBack ) } + composable(SettingsDestination.Advanced) { + AdvancedSettingsScreen( + onClickBack = ::goBack + ) + } + composable(SettingsDestination.Debug) { +// DebugSettingsScreen( +// onClickBack = ::goBack +// ) + } } } @@ -90,6 +102,8 @@ object SettingsDestination { const val Preferences = "preferences" const val Toolbar = "toolbar" const val GestureTyping = "gesture_typing" + const val Advanced = "advanced" + const val Debug = "debug" val navTarget = MutableStateFlow(Settings) private val navScope = CoroutineScope(Dispatchers.Default) diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedSettingsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedSettingsScreen.kt new file mode 100644 index 000000000..fab0921c0 --- /dev/null +++ b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedSettingsScreen.kt @@ -0,0 +1,263 @@ +package helium314.keyboard.settings.screens + +import android.content.Context +import android.os.Build +import androidx.compose.material3.Surface +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import helium314.keyboard.latin.BuildConfig +import helium314.keyboard.latin.R +import helium314.keyboard.latin.SystemBroadcastReceiver +import helium314.keyboard.latin.settings.DebugSettings +import helium314.keyboard.latin.settings.Settings +import helium314.keyboard.settings.AllPrefs +import helium314.keyboard.settings.ListPreference +import helium314.keyboard.settings.NonSettingsPrefs +import helium314.keyboard.settings.PrefDef +import helium314.keyboard.settings.Preference +import helium314.keyboard.settings.PreferenceCategory +import helium314.keyboard.settings.SearchPrefScreen +import helium314.keyboard.settings.SettingsActivity2 +import helium314.keyboard.settings.SettingsDestination +import helium314.keyboard.settings.SliderPreference +import helium314.keyboard.settings.SwitchPreference +import helium314.keyboard.settings.Theme +import helium314.keyboard.settings.prefs +import helium314.keyboard.settings.themeChanged + +@Composable +fun AdvancedSettingsScreen( + onClickBack: () -> Unit, +) { + val prefs = LocalContext.current.prefs() + SearchPrefScreen( + onClickBack = onClickBack, + title = stringResource(R.string.settings_screen_advanced), + ) { + SettingsActivity2.allPrefs.map[Settings.PREF_ALWAYS_INCOGNITO_MODE]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_KEY_LONGPRESS_TIMEOUT]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_SPACE_HORIZONTAL_SWIPE]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_SPACE_VERTICAL_SWIPE]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_DELETE_SWIPE]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_SPACE_TO_CHANGE_LANG]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY]!!.Preference() + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) + SettingsActivity2.allPrefs.map[Settings.PREF_SHOW_SETUP_WIZARD_ICON]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_SYMBOL_SPACE]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_CLIP]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_CUSTOM_CURRENCY_KEY]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_MORE_POPUP_KEYS]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_ABC_AFTER_EMOJI]!!.Preference() + SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_SYMBOLS_NUMBER_LAYOUTS]!!.Preference() + SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS]!!.Preference() + SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKUP_RESTORE]!!.Preference() + if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, false)) + SettingsActivity2.allPrefs.map[NonSettingsPrefs.DEBUG_SETTINGS]!!.Preference() + PreferenceCategory( + stringResource(R.string.settings_category_experimental) + ) { + SettingsActivity2.allPrefs.map[Settings.PREF_EMOJI_MAX_SDK]!!.Preference() + SettingsActivity2.allPrefs.map[Settings.PREF_URL_DETECTION]!!.Preference() + if (BuildConfig.BUILD_TYPE != "nouserlib") + SettingsActivity2.allPrefs.map[NonSettingsPrefs.LOAD_GESTURE_LIB]!!.Preference() + } + } +} + +fun createAdvancedPrefs(context: Context) = listOf( + PrefDef(context, Settings.PREF_ALWAYS_INCOGNITO_MODE, R.string.incognito, R.string.prefs_force_incognito_mode_summary) { + SwitchPreference( + def = it, + default = false + ) + }, + PrefDef(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { + SliderPreference( + name = it.title, + pref = it.key, + default = 300, + range = 100f..700f, + description = { stringResource(R.string.abbreviation_unit_milliseconds, it.toString()) } + ) + }, + PrefDef(context, Settings.PREF_SPACE_HORIZONTAL_SWIPE, R.string.show_horizontal_space_swipe) { def -> + // todo: get rid of the arrays from old settings + val items = listOf( + stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor", + stringResource(R.string.switch_language) to "switch_language", + stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad", + stringResource(R.string.action_none) to "none", + ) + ListPreference(def, items, "move_cursor") + }, + PrefDef(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) { def -> + // todo: get rid of the arrays from old settings + val items = listOf( + stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor", + stringResource(R.string.switch_language) to "switch_language", + stringResource(R.string.space_swipe_toggle_numpad_entry) to "toggle_numpad", + stringResource(R.string.action_none) to "none", + ) + ListPreference(def, items, "none") + }, + PrefDef(context, Settings.PREF_DELETE_SWIPE, R.string.delete_swipe, R.string.delete_swipe_summary) { + SwitchPreference( + def = it, + default = true + ) + }, + PrefDef(context, Settings.PREF_SPACE_TO_CHANGE_LANG, R.string.prefs_long_press_keyboard_to_change_lang, R.string.prefs_long_press_keyboard_to_change_lang_summary) { + SwitchPreference( + def = it, + default = true + ) + }, + PrefDef(context, Settings.PREFS_LONG_PRESS_SYMBOLS_FOR_NUMPAD, R.string.prefs_long_press_symbol_for_numpad) { + SwitchPreference( + def = it, + default = false + ) + }, + PrefDef(context, Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY, R.string.prefs_enable_emoji_alt_physical_key, R.string.prefs_enable_emoji_alt_physical_key_summary) { + SwitchPreference( + def = it, + default = true + ) + }, + PrefDef(context, Settings.PREF_SHOW_SETUP_WIZARD_ICON, R.string.prefs_enable_emoji_alt_physical_key_summary) { + val ctx = LocalContext.current + SwitchPreference( + def = it, + default = true + ) { SystemBroadcastReceiver.toggleAppIcon(ctx) } + }, + PrefDef(context, Settings.PREF_ABC_AFTER_SYMBOL_SPACE, R.string.switch_keyboard_after, R.string.after_symbol_and_space) { + SwitchPreference( + def = it, + default = true + ) + }, + PrefDef(context, Settings.PREF_ABC_AFTER_EMOJI, R.string.switch_keyboard_after, R.string.after_emoji) { + SwitchPreference( + def = it, + default = false + ) + }, + PrefDef(context, Settings.PREF_ABC_AFTER_CLIP, R.string.switch_keyboard_after, R.string.after_clip) { + SwitchPreference( + def = it, + default = false + ) + }, + PrefDef(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { + var showDialog by remember { mutableStateOf(false) } + Preference( + name = it.title, + onClick = { showDialog = true } + ) +// if (showDialog) todo: show the currency customizer + }, + PrefDef(context, Settings.PREF_MORE_POPUP_KEYS, R.string.show_popup_keys_title) { def -> + // todo: get rid of the arrays from old settings + val items = listOf( + stringResource(R.string.show_popup_keys_normal) to "normal", + stringResource(R.string.show_popup_keys_main) to "main", + stringResource(R.string.show_popup_keys_more) to "more", + stringResource(R.string.show_popup_keys_all) to "all", + ) + ListPreference(def, items, "main") + // todo: on value changed -> KeyboardLayoutSet.onSystemLocaleChanged() + }, + PrefDef(context, NonSettingsPrefs.CUSTOM_SYMBOLS_NUMBER_LAYOUTS, R.string.customize_symbols_number_layouts) { + var showDialog by remember { mutableStateOf(false) } + Preference( + name = it.title, + onClick = { showDialog = true } + ) +// if (showDialog) todo: show the currency customizer + }, + PrefDef(context, NonSettingsPrefs.CUSTOM_FUNCTIONAL_LAYOUTS, R.string.customize_functional_key_layouts) { + var showDialog by remember { mutableStateOf(false) } + Preference( + name = it.title, + onClick = { showDialog = true } + ) +// if (showDialog) todo: show the currency customizer + }, + PrefDef(context, NonSettingsPrefs.BACKUP_RESTORE, R.string.backup_restore_title) { + var showDialog by remember { mutableStateOf(false) } + Preference( + name = it.title, + onClick = { showDialog = true } + ) +// if (showDialog) todo: show the currency customizer + }, + PrefDef(context, NonSettingsPrefs.DEBUG_SETTINGS, R.string.debug_settings_title) { + Preference( + name = it.title, + onClick = { SettingsDestination.navigateTo(SettingsDestination.Debug) } + ) + }, + PrefDef(context, Settings.PREF_EMOJI_MAX_SDK, R.string.prefs_key_emoji_max_sdk) { + SliderPreference( + name = it.title, + pref = it.key, + default = Build.VERSION.SDK_INT, + range = 21f..35f, + description = { + "Android " + when(it) { + 21 -> "5.0" + 22 -> "5.1" + 23 -> "6" + 24 -> "7.0" + 25 -> "7.1" + 26 -> "8.0" + 27 -> "8.1" + 28 -> "9" + 29 -> "10" + 30 -> "11" + 31 -> "12" + 32 -> "12L" + 33 -> "13" + 34 -> "14" + 35 -> "15" + else -> "version unknown" + } + }, + onValueChanged = { themeChanged = true } + ) + }, + PrefDef(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) { + SwitchPreference( + def = it, + default = false + ) + }, + PrefDef(context, NonSettingsPrefs.LOAD_GESTURE_LIB, R.string.load_gesture_library, R.string.load_gesture_library_summary) { + var showDialog by remember { mutableStateOf(false) } + Preference( + name = it.title, + onClick = { showDialog = true } + ) +// if (showDialog) todo: show the dialog, or launch that thing + }, +) + +@Preview +@Composable +private fun Preview() { + SettingsActivity2.allPrefs = AllPrefs(LocalContext.current) + Theme(true) { + Surface { + AdvancedSettingsScreen { } + } + } +} 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 f51fe6e38..49365377c 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/GestureTypingScreen.kt @@ -116,7 +116,7 @@ private fun Preview() { SettingsActivity2.allPrefs = AllPrefs(LocalContext.current) Theme(true) { Surface { - GestureTypingScreen { } + GestureTypingScreen { } } } } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt index cca8d53c6..1dbf477db 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt @@ -38,6 +38,7 @@ fun MainSettingsScreen( onClickPreferences: () -> Unit, onClickToolbar: () -> Unit, onClickGestureTyping: () -> Unit, + onClickAdvanced: () -> Unit, onClickBack: () -> Unit, ) { val ctx = LocalContext.current @@ -80,7 +81,18 @@ fun MainSettingsScreen( ) { Icon( painter = painterResource(R.drawable.ic_arrow_left), - modifier = Modifier.scale(-1f, 1f), // no rotate drawable allowed in compose + modifier = Modifier.scale(-1f, 1f), + contentDescription = null + ) + } + Preference( + name = stringResource(R.string.settings_screen_advanced), + onClick = onClickAdvanced, + icon = R.drawable.ic_settings_advanced_foreground + ) { + Icon( + painter = painterResource(R.drawable.ic_arrow_left), + modifier = Modifier.scale(-1f, 1f), contentDescription = null ) } @@ -148,7 +160,7 @@ fun Activity.switchTo(fragment: androidx.fragment.app.Fragment) { private fun PreviewScreen() { Theme(true) { Surface { - MainSettingsScreen({}, {}, {}, {}, {}, {}) + MainSettingsScreen({}, {}, {}, {}, {}, {}, {}) } } } 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 c63da1415..c16ccfe32 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt @@ -25,6 +25,7 @@ import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.UserDictionaryListFragment import helium314.keyboard.latin.utils.Log import helium314.keyboard.settings.AllPrefs +import helium314.keyboard.settings.ListPreference import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.Preference @@ -130,33 +131,13 @@ fun createCorrectionPrefs(context: Context) = listOf( Settings.PREF_AUTO_CORRECTION_CONFIDENCE, R.string.auto_correction_confidence, ) { def -> - var showDialog by remember { mutableStateOf(false) } // todo: arrays are arranged in a rather absurd way... this should be improved val items = listOf( stringResource(R.string.auto_correction_threshold_mode_modest) to "0", stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1", stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2", ) - val prefs = LocalContext.current.prefs() - val selected = items.firstOrNull { it.second == prefs.getString(def.key, "0") } - Preference( - name = def.title, - description = selected?.first, - onClick = { showDialog = true } - ) - if (showDialog) { - ListPickerDialog( - onDismissRequest = {showDialog = false }, - items = items, - onItemSelected = { - if (it != selected) - prefs.edit().putString(def.key, it.second).apply() - }, - selectedItem = selected, - title = { Text(def.title) }, - getItemName = { it.first } - ) - } + ListPreference(def, items, "0") }, PrefDef(context, Settings.PREF_AUTO_CAP,