move extension functions and update todo

This commit is contained in:
Helium314 2025-02-01 08:35:14 +01:00
parent 8e624408f1
commit 5e7482085f
13 changed files with 100 additions and 114 deletions

View file

@ -1,6 +1,9 @@
package helium314.keyboard.latin.utils package helium314.keyboard.latin.utils
import android.content.Context import android.content.Context
import android.content.ContextWrapper
import android.content.SharedPreferences
import androidx.activity.ComponentActivity
// generic extension functions // generic extension functions
@ -13,10 +16,9 @@ inline fun <T> Iterable<T>.sumOf(selector: (T) -> Float): Float {
return sum return sum
} }
// todo: string instead of CharSequence for compose? because resource STRINGs should be strings anyway... fun CharSequence.getStringResourceOrName(prefix: String, context: Context): String {
fun CharSequence.getStringResourceOrName(prefix: String, context: Context): CharSequence {
val resId = context.resources.getIdentifier(prefix + this, "string", context.packageName) val resId = context.resources.getIdentifier(prefix + this, "string", context.packageName)
return if (resId == 0) this else context.getString(resId) return if (resId == 0) this.toString() else context.getString(resId)
} }
/** /**
@ -55,3 +57,14 @@ fun <T> MutableList<T>.replaceFirst(predicate: (T) -> Boolean, with: (T) -> T) {
val i = indexOfFirst(predicate) val i = indexOfFirst(predicate)
if (i >= 0) this[i] = with(this[i]) if (i >= 0) this[i] = with(this[i])
} }
fun Context.getActivity(): ComponentActivity? {
val componentActivity = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
return componentActivity
}
fun Context.prefs(): SharedPreferences = DeviceProtectedUtils.getSharedPreferences(this)

View file

@ -2,12 +2,8 @@
package helium314.keyboard.settings package helium314.keyboard.settings
import android.content.Context import android.content.Context
import android.content.ContextWrapper
import android.content.SharedPreferences
import androidx.activity.ComponentActivity
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
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.createAdvancedPrefs
import helium314.keyboard.settings.screens.createAppearancePrefs import helium314.keyboard.settings.screens.createAppearancePrefs
@ -62,18 +58,6 @@ private fun createPrefDefs(context: Context) = createAboutPrefs(context) +
createGestureTypingPrefs(context) + createAdvancedPrefs(context) + createDebugPrefs(context) + createGestureTypingPrefs(context) + createAdvancedPrefs(context) + createDebugPrefs(context) +
createAppearancePrefs(context) createAppearancePrefs(context)
// todo: move somewhere else
fun Context.getActivity(): ComponentActivity? {
val componentActivity = when (this) {
is ComponentActivity -> this
is ContextWrapper -> baseContext.getActivity()
else -> null
}
return componentActivity
}
fun Context.prefs(): SharedPreferences = DeviceProtectedUtils.getSharedPreferences(this)
object NonSettingsPrefs { object NonSettingsPrefs {
const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary" const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary"
const val APP = "app" const val APP = "app"
@ -89,7 +73,3 @@ object NonSettingsPrefs {
const val DEBUG_SETTINGS = "screen_debug" const val DEBUG_SETTINGS = "screen_debug"
const val LOAD_GESTURE_LIB = "load_gesture_library" const val LOAD_GESTURE_LIB = "load_gesture_library"
} }
@JvmField
// todo: maybe better name it "reloadKeyboard"?
var themeChanged = false

View file

@ -39,6 +39,8 @@ import androidx.compose.ui.unit.dp
import androidx.core.content.edit 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.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.dialogs.ListPickerDialog import helium314.keyboard.settings.dialogs.ListPickerDialog
import helium314.keyboard.settings.dialogs.SliderDialog import helium314.keyboard.settings.dialogs.SliderDialog

View file

@ -10,72 +10,63 @@ import androidx.compose.ui.platform.ComposeView
import androidx.core.view.isGone import androidx.core.view.isGone
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.prefs
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
// todo // todo (roughly in order)
// make all prefs actually work // make all prefs actually work
// make the pref lists more compact (compare with old settings)
// try making text size similar to old state (also in dialogs)
// check whether dialogs have the same colors, i think currently it's a bit inconsistent
// rename both settingsActivities
// work on todos in other files
// use better / more structured and clear names and arrangement of files
// animations when stuff (dis)appears
// LaunchedEffect, AnimatedVisibility
// performance
// find a nice way of testing (probably add logs for measuring time and recompositions)
// consider that stuff in composables can get called quite often on any changes -> use remember for things that are slow
// improve performance when loading screens with many settings (lazyColumn?)
// first check whether it's really necessary (test advanced or correction screen normal and with lazyColumn)
// screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding
// lazyColumn also has a "key", this should be used and be the pref name (or maybe title because that's also for category separators)
// nice arrows (in top bar, and as next-screen indicator)
// PRs adding prefs -> need to do before continuing // PRs adding prefs -> need to do before continuing
// 1319 (soon) // 1319 (soon)
// 1263 (no response for 3 weeks) // 1263 (no response for 3 weeks)
// merge main to implement all the new settings // merge main to implement all the new settings
// consider IME insets when searching // consider IME insets when searching
// consider that stuff in composables can get called quite often on any changes -> use remember for things that are slow (maybe add test logging)
// dialogs should be rememberSaveable to survive display orientation change and stuff? // dialogs should be rememberSaveable to survive display orientation change and stuff?
// default buttons for toolbar key(s) customizer and toolbar reorder dialog // default buttons for toolbar key(s) customizer and toolbar reorder dialog
// try making old fragment back stuff work better, and try the different themes (with and without top bar)
// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it?
// consider using simple list picker dialog (but the "full" one is probably better for language settings stuff)
// spdx headers everywhere
// what should be done, but not in this PR
// in general: changes to anything outside the new settings (unless necessary), and changes to how screens / fragments work
// re-organize screens, no need to keep exactly the same arrangement
// language settings (should change more than just move to compose)
// user dictionary settings (or maybe leave old state for a while?)
// color settings (should at least change how colors are stored, and have a color search/filter)
// one single place for default values (to be used in composables and settings)
// make auto_correct_threshold a float directly with the list pref (needs pref upgrade)
// using context.prefs() outside settings
// merge PREF_TOOLBAR_CUSTOM_KEY_CODES and PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES into one pref (don't forget settings upgrade)
// adjust debug settings
// have them in main screen?
// allow users to find the individual settings in search even if debug settings are not enabled?
// later
// improve performance when loading screens with many settings (lazyColumn?)
// first check whether it's really necessary (test advanced or correction screen normal and with lazyColumn)
// screens could have a lazy column of preferences and category separators, and the list has an if-setting-then-null for hiding
// lazyColumn also has the key, this should be used! and must be unique
// nice arrows (in top bar, and as next-screen indicator)
// animations when stuff (dis)appears
// LaunchedEffect, AnimatedVisibility
// remove PrefScreen if not used
// rename some classes
// split the preferences in allPrefs.createDefs into multiple files, this will get horribly long
// maybe have sub-lists in the pref screens using the settings?
// spdx headers everywhere (except DragDropColumn, which is from stackoverflow without explicit license)
// changes to anything but the compose settings package should not be in the initial PR
// commit them separately if possible
// though some might be necessary
// toolbar key enabled state can be wrong
// go to correction settings, open search, toggle autocorrect toolbar key, and then toggle setting
// -> now toolbar key always has the wrong state
// color settings needs a color search
// more convenient access to prefs
// merge PREF_TOOLBAR_CUSTOM_KEY_CODES and PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES
// should be single pref containing both
// needs settings upgrade of course...
// consider disabled settings & search // consider disabled settings & search
// don't show -> users confused // don't show -> users confused
// show as disabled -> users confused // show as disabled -> users confused
// show (but change will not do anything because another setting needs to be enabled first) // show (but change will not do anything because another setting needs to be enabled first)
// -> users confused, but probably better than the 2 above // -> last is probably best, but people will probably open issues no matter what
// 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 (needs pref upgrade
// actually test all the settings
// when starting keyboard from settings, initially there is the "old" background color before compose stuff starts
// language settings (separate commit / PR, should change more than just move to compose)
// user dictionary settings (separate commit / PR, or maybe leave old state for a while?)
// color settings (separate commit / PR, should at least change how colors are stored)
// one single place for default values (to be used in composables and settings)
// better a separate commit
// maybe later // maybe do after the PR
// weird problem with app sometimes closing on back, but that's related to "old" settings (don't care if all are removed before next release) // bottom dummy text field (though we have the search now anyway, and thus maybe don't need it)
// bottom text field (though we have the search now anyway)
// remove navHost? but probably too useful to have...
// lazyColumn for prefs (or just in category?)
// should improve loading time for screens with many settings
// but needs a bit of work for probably not so much benefit
// 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
// exclude all debug settings from search results if they are not enabled
// rearrange settings screens? now it should be very simple to do (definitely separate PR) // rearrange settings screens? now it should be very simple to do (definitely separate PR)
// preliminary results: // preliminary results:
@ -104,22 +95,25 @@ class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPrefere
if (Settings.getInstance().current == null) if (Settings.getInstance().current == null)
Settings.init(this) Settings.init(this)
// val cv = ComposeView(context = this)
allPrefs = AllPrefs(this) allPrefs = AllPrefs(this)
// setContentView(cv) // todo: later, but for showing both old and new style settings, the layout is better
// todo: when removing old settings completely, remove settings_activity.xml and supportFragmentManager stuff
// val cv = ComposeView(context = this)
// setContentView(cv)
setContentView(R.layout.settings_activity) setContentView(R.layout.settings_activity)
supportFragmentManager.addOnBackStackChangedListener { supportFragmentManager.addOnBackStackChangedListener {
updateContainerVisibility() updateContainerVisibility()
} }
// cv.setContent { // also later... // cv.setContent { // todo: when removing old settings
findViewById<ComposeView>(R.id.navHost).setContent { findViewById<ComposeView>(R.id.navHost).setContent {
Theme { Theme {
Surface { Surface {
SettingsNavHost( SettingsNavHost(
onClickBack = { onClickBack = {
if (supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null) // todo: remove after migration is complete // this.finish() // todo: when removing old settings
if (supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null)
this.finish() this.finish()
else supportFragmentManager.popBackStack() // todo: remove after migration is complete else supportFragmentManager.popBackStack()
} }
) )
} }
@ -127,7 +121,7 @@ class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPrefere
} }
} }
private fun updateContainerVisibility() { // todo: remove after migration is complete private fun updateContainerVisibility() { // todo: remove when removing old settings
findViewById<RelativeLayout>(R.id.settingsFragmentContainer).isGone = supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null findViewById<RelativeLayout>(R.id.settingsFragmentContainer).isGone = supportFragmentManager.findFragmentById(R.id.settingsFragmentContainer) == null
} }
@ -150,3 +144,6 @@ class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPrefere
prefChanged.value++ prefChanged.value++
} }
} }
@JvmField
var needsKeyboardReload = false

View file

@ -33,11 +33,11 @@ import helium314.keyboard.latin.utils.ToolbarKey
import helium314.keyboard.latin.utils.getCodeForToolbarKey import helium314.keyboard.latin.utils.getCodeForToolbarKey
import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick import helium314.keyboard.latin.utils.getCodeForToolbarKeyLongClick
import helium314.keyboard.latin.utils.getStringResourceOrName import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.latin.utils.readCustomKeyCodes import helium314.keyboard.latin.utils.readCustomKeyCodes
import helium314.keyboard.latin.utils.readCustomLongpressCodes import helium314.keyboard.latin.utils.readCustomLongpressCodes
import helium314.keyboard.latin.utils.writeCustomKeyCodes import helium314.keyboard.latin.utils.writeCustomKeyCodes
import helium314.keyboard.latin.utils.writeCustomLongpressCodes import helium314.keyboard.latin.utils.writeCustomLongpressCodes
import helium314.keyboard.settings.prefs
import helium314.keyboard.settings.screens.GetIcon import helium314.keyboard.settings.screens.GetIcon
// todo: // todo:
@ -63,7 +63,7 @@ fun ToolbarKeysCustomizer(
modifier = Modifier.clickable { showKeyCustomizer = it }.fillParentMaxWidth() modifier = Modifier.clickable { showKeyCustomizer = it }.fillParentMaxWidth()
) { ) {
KeyboardIconsSet.instance.GetIcon(it.name) KeyboardIconsSet.instance.GetIcon(it.name)
Text(it.name.lowercase().getStringResourceOrName("", ctx).toString()) Text(it.name.lowercase().getStringResourceOrName("", ctx))
} }
} }
} }
@ -102,7 +102,7 @@ private fun ToolbarKeyCustomizer(
) { Text(stringResource(android.R.string.ok)) } ) { Text(stringResource(android.R.string.ok)) }
}, },
dismissButton = { TextButton(onClick = onDismissRequest) { Text(stringResource(android.R.string.cancel)) } }, dismissButton = { TextButton(onClick = onDismissRequest) { Text(stringResource(android.R.string.cancel)) } },
title = { Text(key.name.lowercase().getStringResourceOrName("", ctx).toString()) }, title = { Text(key.name.lowercase().getStringResourceOrName("", ctx)) },
text = { text = {
Column { Column {
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {

View file

@ -27,6 +27,8 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.SpannableStringUtils import helium314.keyboard.latin.utils.SpannableStringUtils
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.NonSettingsPrefs
import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.PrefDef
@ -34,8 +36,6 @@ import helium314.keyboard.settings.Preference
import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SearchPrefScreen
import helium314.keyboard.settings.SettingsActivity2 import helium314.keyboard.settings.SettingsActivity2
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.getActivity
import helium314.keyboard.settings.prefs
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch

View file

@ -16,6 +16,7 @@ import helium314.keyboard.latin.R
import helium314.keyboard.latin.SystemBroadcastReceiver import helium314.keyboard.latin.SystemBroadcastReceiver
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.ListPreference import helium314.keyboard.settings.ListPreference
import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.NonSettingsPrefs
@ -28,8 +29,7 @@ import helium314.keyboard.settings.SettingsDestination
import helium314.keyboard.settings.SliderPreference import helium314.keyboard.settings.SliderPreference
import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.SwitchPreference
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.prefs import helium314.keyboard.settings.needsKeyboardReload
import helium314.keyboard.settings.themeChanged
@Composable @Composable
fun AdvancedSettingsScreen( fun AdvancedSettingsScreen(
@ -89,7 +89,6 @@ fun createAdvancedPrefs(context: Context) = listOf(
) )
}, },
PrefDef(context, Settings.PREF_SPACE_HORIZONTAL_SWIPE, R.string.show_horizontal_space_swipe) { def -> 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( val items = listOf(
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor", stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
stringResource(R.string.switch_language) to "switch_language", stringResource(R.string.switch_language) to "switch_language",
@ -99,7 +98,6 @@ fun createAdvancedPrefs(context: Context) = listOf(
ListPreference(def, items, "move_cursor") ListPreference(def, items, "move_cursor")
}, },
PrefDef(context, Settings.PREF_SPACE_VERTICAL_SWIPE, R.string.show_vertical_space_swipe) { def -> 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( val items = listOf(
stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor", stringResource(R.string.space_swipe_move_cursor_entry) to "move_cursor",
stringResource(R.string.switch_language) to "switch_language", stringResource(R.string.switch_language) to "switch_language",
@ -166,7 +164,6 @@ fun createAdvancedPrefs(context: Context) = listOf(
// if (showDialog) todo: show the currency customizer // if (showDialog) todo: show the currency customizer
}, },
PrefDef(context, Settings.PREF_MORE_POPUP_KEYS, R.string.show_popup_keys_title) { def -> 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( val items = listOf(
stringResource(R.string.show_popup_keys_normal) to "normal", stringResource(R.string.show_popup_keys_normal) to "normal",
stringResource(R.string.show_popup_keys_main) to "main", stringResource(R.string.show_popup_keys_main) to "main",
@ -232,7 +229,7 @@ fun createAdvancedPrefs(context: Context) = listOf(
else -> "version unknown" else -> "version unknown"
} }
}, },
onValueChanged = { themeChanged = true } onValueChanged = { needsKeyboardReload = true }
) )
}, },
PrefDef(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) { PrefDef(context, Settings.PREF_URL_DETECTION, R.string.url_detection_title, R.string.url_detection_summary) {

View file

@ -17,7 +17,9 @@ import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getStringResourceOrName import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.ListPreference import helium314.keyboard.settings.ListPreference
import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.PrefDef
@ -26,12 +28,8 @@ import helium314.keyboard.settings.PreferenceCategory
import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SearchPrefScreen
import helium314.keyboard.settings.SettingsActivity2 import helium314.keyboard.settings.SettingsActivity2
import helium314.keyboard.settings.SettingsDestination import helium314.keyboard.settings.SettingsDestination
import helium314.keyboard.settings.SliderPreference
import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.SwitchPreference
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.getActivity
import helium314.keyboard.settings.prefs
import helium314.keyboard.settings.themeChanged
@Composable @Composable
fun AppearanceScreen( fun AppearanceScreen(
@ -60,7 +58,7 @@ fun createAppearancePrefs(context: Context) = listOf(
PrefDef(context, Settings.PREF_THEME_STYLE, R.string.theme_style) { def -> PrefDef(context, Settings.PREF_THEME_STYLE, R.string.theme_style) { def ->
val ctx = LocalContext.current val ctx = LocalContext.current
val items = KeyboardTheme.STYLES.map { val items = KeyboardTheme.STYLES.map {
it.getStringResourceOrName("style_name_", ctx).toString() to it it.getStringResourceOrName("style_name_", ctx) to it
} }
ListPreference( ListPreference(
def, def,
@ -71,7 +69,7 @@ fun createAppearancePrefs(context: Context) = listOf(
PrefDef(context, Settings.PREF_ICON_STYLE, R.string.icon_style) { def -> PrefDef(context, Settings.PREF_ICON_STYLE, R.string.icon_style) { def ->
val ctx = LocalContext.current val ctx = LocalContext.current
val items = KeyboardTheme.STYLES.map { val items = KeyboardTheme.STYLES.map {
it.getStringResourceOrName("style_name_", ctx).toString() to it it.getStringResourceOrName("style_name_", ctx) to it
} }
ListPreference( ListPreference(
def, def,
@ -92,7 +90,7 @@ fun createAppearancePrefs(context: Context) = listOf(
val items = KeyboardTheme.COLORS.mapNotNull { val items = KeyboardTheme.COLORS.mapNotNull {
if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO) if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO)
return@mapNotNull null return@mapNotNull null
it.getStringResourceOrName("theme_name_", ctx).toString() to it it.getStringResourceOrName("theme_name_", ctx) to it
} }
ListPreference( ListPreference(
def, def,
@ -106,7 +104,7 @@ fun createAppearancePrefs(context: Context) = listOf(
val items = KeyboardTheme.COLORS.mapNotNull { val items = KeyboardTheme.COLORS.mapNotNull {
if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO) if (it == KeyboardTheme.THEME_HOLO_WHITE && currentStyle == KeyboardTheme.STYLE_HOLO)
return@mapNotNull null return@mapNotNull null
it.getStringResourceOrName("theme_name_", ctx).toString() to it it.getStringResourceOrName("theme_name_", ctx) to it
} }
ListPreference( ListPreference(
def, def,

View file

@ -13,6 +13,7 @@ import helium314.keyboard.latin.DictionaryFacilitator
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.DebugSettingsFragment import helium314.keyboard.latin.settings.DebugSettingsFragment
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.PrefDef
import helium314.keyboard.settings.Preference import helium314.keyboard.settings.Preference
@ -21,8 +22,7 @@ import helium314.keyboard.settings.SearchPrefScreen
import helium314.keyboard.settings.SettingsActivity2 import helium314.keyboard.settings.SettingsActivity2
import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.SwitchPreference
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.prefs import helium314.keyboard.settings.needsKeyboardReload
import helium314.keyboard.settings.themeChanged
@Composable @Composable
fun DebugScreen( fun DebugScreen(
@ -63,7 +63,7 @@ fun createDebugPrefs(context: Context) = listOf(
} }
}, },
PrefDef(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) { def -> PrefDef(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) { def ->
SwitchPreference(def, false) { themeChanged = true } SwitchPreference(def, false) { needsKeyboardReload = true }
}, },
PrefDef(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) { def -> PrefDef(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) { def ->
SwitchPreference(def, false) { needsRestart = true } SwitchPreference(def, false) { needsRestart = true }

View file

@ -11,6 +11,8 @@ import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.PrefDef import helium314.keyboard.settings.PrefDef
import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SearchPrefScreen
@ -18,9 +20,7 @@ import helium314.keyboard.settings.SettingsActivity2
import helium314.keyboard.settings.SliderPreference import helium314.keyboard.settings.SliderPreference
import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.SwitchPreference
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.getActivity import helium314.keyboard.settings.needsKeyboardReload
import helium314.keyboard.settings.prefs
import helium314.keyboard.settings.themeChanged
@Composable @Composable
fun GestureTypingScreen( fun GestureTypingScreen(
@ -74,7 +74,7 @@ fun createGestureTypingPrefs(context: Context) = listOf(
SwitchPreference( SwitchPreference(
def = it, def = it,
default = true default = true
) { themeChanged = true } ) { needsKeyboardReload = true }
}, },
PrefDef(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) { PrefDef(context, Settings.PREF_GESTURE_SPACE_AWARE, R.string.gesture_space_aware, R.string.gesture_space_aware_summary) {
SwitchPreference( SwitchPreference(
@ -106,7 +106,7 @@ fun createGestureTypingPrefs(context: Context) = listOf(
range = 100f..1900f, range = 100f..1900f,
description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) }, description = { stringResource(R.string.abbreviation_unit_milliseconds, (it + 100).toString()) },
// todo: 50 ms steps? // todo: 50 ms steps?
) { themeChanged = true } ) { needsKeyboardReload = true }
}, },
) )

View file

@ -25,11 +25,11 @@ import helium314.keyboard.latin.settings.LanguageSettingsFragment
import helium314.keyboard.latin.settings.PreferencesSettingsFragment import helium314.keyboard.latin.settings.PreferencesSettingsFragment
import helium314.keyboard.latin.settings.ToolbarSettingsFragment import helium314.keyboard.latin.settings.ToolbarSettingsFragment
import helium314.keyboard.latin.utils.JniUtils import helium314.keyboard.latin.utils.JniUtils
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.settings.Preference import helium314.keyboard.settings.Preference
import helium314.keyboard.settings.PreferenceCategory import helium314.keyboard.settings.PreferenceCategory
import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SearchPrefScreen
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.getActivity
@Composable @Composable
fun MainSettingsScreen( fun MainSettingsScreen(

View file

@ -24,6 +24,8 @@ import helium314.keyboard.latin.permissions.PermissionsUtil
import helium314.keyboard.latin.settings.Settings 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.latin.utils.getActivity
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.AllPrefs import helium314.keyboard.settings.AllPrefs
import helium314.keyboard.settings.ListPreference import helium314.keyboard.settings.ListPreference
import helium314.keyboard.settings.NonSettingsPrefs import helium314.keyboard.settings.NonSettingsPrefs
@ -35,10 +37,7 @@ import helium314.keyboard.settings.SettingsActivity2
import helium314.keyboard.settings.SwitchPreference import helium314.keyboard.settings.SwitchPreference
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.dialogs.ConfirmationDialog import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.ListPickerDialog import helium314.keyboard.settings.needsKeyboardReload
import helium314.keyboard.settings.getActivity
import helium314.keyboard.settings.prefs
import helium314.keyboard.settings.themeChanged
@Composable @Composable
fun TextCorrectionScreen( fun TextCorrectionScreen(
@ -205,7 +204,7 @@ fun createCorrectionPrefs(context: Context) = listOf(
R.string.bigram_prediction, R.string.bigram_prediction,
R.string.bigram_prediction_summary R.string.bigram_prediction_summary
) { ) {
SwitchPreference(it, true) { themeChanged = true } SwitchPreference(it, true) { needsKeyboardReload = true }
}, },
PrefDef(context, PrefDef(context,
Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER, Settings.PREF_CENTER_SUGGESTION_TEXT_TO_ENTER,

View file

@ -43,7 +43,7 @@ import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.dialogs.ReorderDialog import helium314.keyboard.settings.dialogs.ReorderDialog
import helium314.keyboard.settings.dialogs.ToolbarKeysCustomizer import helium314.keyboard.settings.dialogs.ToolbarKeysCustomizer
import helium314.keyboard.settings.prefs import helium314.keyboard.settings.prefs
import helium314.keyboard.settings.themeChanged import helium314.keyboard.settings.needsKeyboardReload
@Composable @Composable
fun ToolbarScreen( fun ToolbarScreen(
@ -123,7 +123,7 @@ fun createToolbarPrefs(context: Context) = listOf(
SwitchPreference( SwitchPreference(
def, def,
false, false,
) { themeChanged = true } ) { needsKeyboardReload = true }
}, },
PrefDef(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary) { def -> PrefDef(context, Settings.PREF_AUTO_SHOW_TOOLBAR, R.string.auto_show_toolbar, R.string.auto_show_toolbar_summary) { def ->
SwitchPreference( SwitchPreference(
@ -164,7 +164,7 @@ fun ToolbarKeyReorderDialog(
onConfirmed = { reorderedItems -> onConfirmed = { reorderedItems ->
val value = reorderedItems.joinToString(";") { it.name + "," + it.state } val value = reorderedItems.joinToString(";") { it.name + "," + it.state }
prefs.edit().putString(prefKey, value).apply() prefs.edit().putString(prefKey, value).apply()
themeChanged = true needsKeyboardReload = true
}, },
onDismissRequest = onDismiss, onDismissRequest = onDismiss,
items = items, items = items,
@ -173,7 +173,7 @@ fun ToolbarKeyReorderDialog(
var checked by remember { mutableStateOf(item.state) } var checked by remember { mutableStateOf(item.state) }
Row(verticalAlignment = Alignment.CenterVertically) { Row(verticalAlignment = Alignment.CenterVertically) {
KeyboardIconsSet.instance.GetIcon(item.name) KeyboardIconsSet.instance.GetIcon(item.name)
val text = item.name.lowercase().getStringResourceOrName("", ctx).toString() val text = item.name.lowercase().getStringResourceOrName("", ctx)
Text(text, Modifier.weight(1f)) Text(text, Modifier.weight(1f))
Switch( Switch(
checked = checked, checked = checked,