add advanced pref screen (not fully functional)

This commit is contained in:
Helium314 2025-01-29 23:18:06 +01:00
parent f825f6a422
commit 5ddfd63392
8 changed files with 372 additions and 34 deletions

View file

@ -9,6 +9,7 @@ import androidx.annotation.StringRes
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.settings.screens.createAboutPrefs import helium314.keyboard.settings.screens.createAboutPrefs
import helium314.keyboard.settings.screens.createAdvancedPrefs
import helium314.keyboard.settings.screens.createCorrectionPrefs import helium314.keyboard.settings.screens.createCorrectionPrefs
import helium314.keyboard.settings.screens.createGestureTypingPrefs import helium314.keyboard.settings.screens.createGestureTypingPrefs
import helium314.keyboard.settings.screens.createPreferencesPrefs import helium314.keyboard.settings.screens.createPreferencesPrefs
@ -56,7 +57,7 @@ class PrefDef(
private fun createPrefDefs(context: Context) = createAboutPrefs(context) + private fun createPrefDefs(context: Context) = createAboutPrefs(context) +
createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context) + createCorrectionPrefs(context) + createPreferencesPrefs(context) + createToolbarPrefs(context) +
createGestureTypingPrefs(context) createGestureTypingPrefs(context) + createAdvancedPrefs(context)
// todo: move somewhere else // todo: move somewhere else
fun Context.getActivity(): ComponentActivity? { fun Context.getActivity(): ComponentActivity? {
@ -79,7 +80,13 @@ object NonSettingsPrefs {
const val GITHUB = "github" const val GITHUB = "github"
const val SAVE_LOG = "save_log" const val SAVE_LOG = "save_log"
const val CUSTOM_KEY_CODES = "customize_key_codes" 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 @JvmField
// todo: maybe better name it "reloadKeyboard"?
var themeChanged = false var themeChanged = false

View file

@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.settings package helium314.keyboard.settings
import android.content.SharedPreferences
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
@ -30,12 +31,15 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource 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.Hyphens
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.edit
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.settings.dialogs.ListPickerDialog
import helium314.keyboard.settings.dialogs.SliderDialog import helium314.keyboard.settings.dialogs.SliderDialog
// taken from StreetComplete (and a bit SCEE) // taken from StreetComplete (and a bit SCEE)
@ -201,8 +205,8 @@ fun <T: Number> SliderPreference(
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState() 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") Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
val initialValue = if (default is Int) prefs.getInt(pref, default) val initialValue = if (default is Int || default is Float)
else if (default is Float) prefs.getFloat(pref, default) getPrefOfType(prefs, pref, default)
else throw IllegalArgumentException("only float and int are supported") else throw IllegalArgumentException("only float and int are supported")
var showDialog by remember { mutableStateOf(false) } var showDialog by remember { mutableStateOf(false) }
@ -230,6 +234,58 @@ fun <T: Number> SliderPreference(
) )
} }
@Composable
fun <T: Any> ListPreference(
def: PrefDef,
items: List<Pair<String, T>>,
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 <T: Any> 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 <T: Any> 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 @Preview
@Composable @Composable
private fun PreferencePreview() { private fun PreferencePreview() {

View file

@ -14,9 +14,11 @@ import kotlinx.coroutines.flow.MutableStateFlow
// todo // todo
// more pref screens // more pref screens
// other super-custom things // debug
// toolbar key customizer (missing from toolbar screen) // appearance
// icon selector // colors
// personal dictionary
// languages (maybe separately)
// consider IME insets when searching // consider IME insets when searching
// improve performance when loading screens with many settings (lazyColumn?) // 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 // 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 // -> 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!) // adjust layout a little, there is too much empty space and titles are too large (dialogs!)
// check dialogs have the same colors // check dialogs have the same colors
// list preference -> we can make auto_correct_threshold a float directly
// maybe later // maybe later
// weird problem with app sometimes closing on back, but that's related to "old" settings (don't care if all are removed) // 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 // 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? // search only in current pref screen, except when in main?
// try getting rid of appcompat stuff (activity, dialogs, ...) // 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: // preliminary results:
// looks ok (ugly M3 switches) // looks ok (ugly M3 switches)

View file

@ -11,6 +11,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import helium314.keyboard.settings.screens.AboutScreen import helium314.keyboard.settings.screens.AboutScreen
import helium314.keyboard.settings.screens.AdvancedSettingsScreen
import helium314.keyboard.settings.screens.GestureTypingScreen import helium314.keyboard.settings.screens.GestureTypingScreen
import helium314.keyboard.settings.screens.MainSettingsScreen import helium314.keyboard.settings.screens.MainSettingsScreen
import helium314.keyboard.settings.screens.PreferencesScreen import helium314.keyboard.settings.screens.PreferencesScreen
@ -52,6 +53,7 @@ fun SettingsNavHost(
onClickPreferences = { navController.navigate(SettingsDestination.Preferences) }, onClickPreferences = { navController.navigate(SettingsDestination.Preferences) },
onClickToolbar = { navController.navigate(SettingsDestination.Toolbar) }, onClickToolbar = { navController.navigate(SettingsDestination.Toolbar) },
onClickGestureTyping = { navController.navigate(SettingsDestination.GestureTyping) }, onClickGestureTyping = { navController.navigate(SettingsDestination.GestureTyping) },
onClickAdvanced = { navController.navigate(SettingsDestination.Advanced) },
onClickBack = ::goBack, onClickBack = ::goBack,
) )
} }
@ -80,6 +82,16 @@ fun SettingsNavHost(
onClickBack = ::goBack 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 Preferences = "preferences"
const val Toolbar = "toolbar" const val Toolbar = "toolbar"
const val GestureTyping = "gesture_typing" const val GestureTyping = "gesture_typing"
const val Advanced = "advanced"
const val Debug = "debug"
val navTarget = MutableStateFlow(Settings) val navTarget = MutableStateFlow(Settings)
private val navScope = CoroutineScope(Dispatchers.Default) private val navScope = CoroutineScope(Dispatchers.Default)

View file

@ -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 { }
}
}
}

View file

@ -38,6 +38,7 @@ fun MainSettingsScreen(
onClickPreferences: () -> Unit, onClickPreferences: () -> Unit,
onClickToolbar: () -> Unit, onClickToolbar: () -> Unit,
onClickGestureTyping: () -> Unit, onClickGestureTyping: () -> Unit,
onClickAdvanced: () -> Unit,
onClickBack: () -> Unit, onClickBack: () -> Unit,
) { ) {
val ctx = LocalContext.current val ctx = LocalContext.current
@ -80,7 +81,18 @@ fun MainSettingsScreen(
) { ) {
Icon( Icon(
painter = painterResource(R.drawable.ic_arrow_left), 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 contentDescription = null
) )
} }
@ -148,7 +160,7 @@ fun Activity.switchTo(fragment: androidx.fragment.app.Fragment) {
private fun PreviewScreen() { private fun PreviewScreen() {
Theme(true) { Theme(true) {
Surface { Surface {
MainSettingsScreen({}, {}, {}, {}, {}, {}) MainSettingsScreen({}, {}, {}, {}, {}, {}, {})
} }
} }
} }

View file

@ -25,6 +25,7 @@ import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.UserDictionaryListFragment import helium314.keyboard.latin.settings.UserDictionaryListFragment
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.ListPreference
import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.NonSettingsPrefs
import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.PrefDef
import helium314.keyboard.settings.Preference import helium314.keyboard.settings.Preference
@ -130,33 +131,13 @@ fun createCorrectionPrefs(context: Context) = listOf(
Settings.PREF_AUTO_CORRECTION_CONFIDENCE, Settings.PREF_AUTO_CORRECTION_CONFIDENCE,
R.string.auto_correction_confidence, R.string.auto_correction_confidence,
) { def -> ) { def ->
var showDialog by remember { mutableStateOf(false) }
// todo: arrays are arranged in a rather absurd way... this should be improved // todo: arrays are arranged in a rather absurd way... this should be improved
val items = listOf( val items = listOf(
stringResource(R.string.auto_correction_threshold_mode_modest) to "0", 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_aggressive) to "1",
stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2", stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2",
) )
val prefs = LocalContext.current.prefs() ListPreference(def, items, "0")
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 }
)
}
}, },
PrefDef(context, PrefDef(context,
Settings.PREF_AUTO_CAP, Settings.PREF_AUTO_CAP,