finish basics of appearance screen

This commit is contained in:
Helium314 2025-02-01 09:19:58 +01:00
parent 12d411c294
commit e016d13410
3 changed files with 94 additions and 14 deletions

View file

@ -72,4 +72,9 @@ object NonSettingsPrefs {
const val BACKUP_RESTORE = "backup_restore"
const val DEBUG_SETTINGS = "screen_debug"
const val LOAD_GESTURE_LIB = "load_gesture_library"
const val ADJUST_COLORS = "adjust_colors"
const val ADJUST_COLORS_NIGHT = "adjust_colors_night"
const val BACKGROUND_IMAGE = "background_image"
const val BACKGROUND_IMAGE_LANDSCAPE = "background_image_landscape"
const val CUSTOM_FONT = "custom_font"
}

View file

@ -15,17 +15,20 @@ import kotlinx.coroutines.flow.MutableStateFlow
// todo (roughly in order)
// make all prefs actually work
// 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)
// 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
// the prefDef and AllPrefs, also be clear about pref <-> key <-> prefKey (all used, probably should be latter)
// 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
// consider that stuff in composables can get called quite often on any changes
// -> use remember for things that are slow, but be careful about things that can change (e.g. values derived from prefs)
// 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
@ -49,6 +52,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
// 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)
// allow users to add custom themes instead of only having a single one (maybe also switchable in colors settings)
// 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

View file

@ -16,18 +16,21 @@ import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R
import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.settings.SettingsValues
import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs
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
@ -35,22 +38,45 @@ import helium314.keyboard.settings.Theme
fun AppearanceScreen(
onClickBack: () -> Unit,
) {
val prefs = LocalContext.current.prefs()
val ctx = LocalContext.current
val prefs = ctx.prefs()
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
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 dayNightMode = Settings.readDayNightPref(prefs, ctx.resources)
val lightTheme = prefs.getString(Settings.PREF_THEME_COLORS, KeyboardTheme.THEME_LIGHT)
val darkTheme = prefs.getString(Settings.PREF_THEME_COLORS_NIGHT, KeyboardTheme.THEME_DARK)
SearchPrefScreen(
onClickBack = onClickBack,
title = stringResource(R.string.settings_screen_appearance),
) {
PreferenceCategory(stringResource(R.string.settings_screen_theme)) {
SettingsActivity2.allPrefs.map[Settings.PREF_THEME_STYLE]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_ICON_STYLE]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_CUSTOM_ICON_NAMES]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_THEME_COLORS]!!.Preference()
if (lightTheme == KeyboardTheme.THEME_USER)
SettingsActivity2.allPrefs.map[NonSettingsPrefs.ADJUST_COLORS]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_THEME_KEY_BORDERS]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_THEME_DAY_NIGHT]!!.Preference()
if (dayNightMode)
SettingsActivity2.allPrefs.map[Settings.PREF_THEME_COLORS_NIGHT]!!.Preference()
if (dayNightMode && darkTheme == KeyboardTheme.THEME_USER_NIGHT)
SettingsActivity2.allPrefs.map[NonSettingsPrefs.ADJUST_COLORS_NIGHT]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_NAVBAR_COLOR]!!.Preference()
SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKGROUND_IMAGE]!!.Preference()
SettingsActivity2.allPrefs.map[NonSettingsPrefs.BACKGROUND_IMAGE_LANDSCAPE]!!.Preference()
}
PreferenceCategory(stringResource(R.string.settings_category_miscellaneous)) {
SettingsActivity2.allPrefs.map[Settings.PREF_ENABLE_SPLIT_KEYBOARD]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_SPLIT_SPACER_SCALE]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_NARROW_KEY_GAPS]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_NARROW_KEY_GAPS]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_KEYBOARD_HEIGHT_SCALE]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_BOTTOM_PADDING_SCALE]!!.Preference()
SettingsActivity2.allPrefs.map[Settings.PREF_SPACE_BAR_TEXT]!!.Preference()
SettingsActivity2.allPrefs.map[NonSettingsPrefs.CUSTOM_FONT]!!.Preference()
}
SettingsActivity2.allPrefs.map[Settings.PREF_GESTURE_INPUT]!!.Preference()
}
}
@ -112,15 +138,14 @@ fun createAppearancePrefs(context: Context) = listOf(
KeyboardTheme.THEME_DARK
)
},
// todo: non-settings pref
PrefDef(context, "theme_select_colors", R.string.select_user_colors, R.string.select_user_colors_summary) { def ->
PrefDef(context, NonSettingsPrefs.ADJUST_COLORS, R.string.select_user_colors, R.string.select_user_colors_summary) { def ->
Preference(
name = def.title,
description = def.description,
onClick = { SettingsDestination.navigateTo(SettingsDestination.Colors) }
)
},
PrefDef(context, "theme_select_colors_night", R.string.select_user_colors_night, R.string.select_user_colors_summary) { def ->
PrefDef(context, NonSettingsPrefs.ADJUST_COLORS_NIGHT, R.string.select_user_colors_night, R.string.select_user_colors_summary) { def ->
Preference(
name = def.title,
description = def.description,
@ -136,16 +161,14 @@ fun createAppearancePrefs(context: Context) = listOf(
PrefDef(context, Settings.PREF_NAVBAR_COLOR, R.string.theme_navbar, R.string.day_night_mode_summary) { def ->
SwitchPreference(def, Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
},
// todo: non-settings pref
PrefDef(context, "custom_background_image", R.string.customize_background_image) { def ->
PrefDef(context, NonSettingsPrefs.BACKGROUND_IMAGE, R.string.customize_background_image) { def ->
var showDialog by remember { mutableStateOf(false) }
Preference(
name = def.title,
onClick = { showDialog = true }
) // todo: create and show the dialog
},
// todo: non-settings pref
PrefDef(context, "custom_background_image_landscape", R.string.customize_background_image_landscape, R.string.summary_customize_background_image_landscape) { def ->
PrefDef(context, NonSettingsPrefs.BACKGROUND_IMAGE_LANDSCAPE, R.string.customize_background_image_landscape, R.string.summary_customize_background_image_landscape) { def ->
var showDialog by remember { mutableStateOf(false) }
Preference(
name = def.title,
@ -153,7 +176,55 @@ fun createAppearancePrefs(context: Context) = listOf(
onClick = { showDialog = true }
) // todo: create and show the dialog
},
// todo: add misc category, then add functionality, then add to the actual screen
PrefDef(context, Settings.PREF_ENABLE_SPLIT_KEYBOARD, R.string.enable_split_keyboard) {
SwitchPreference(it, false)
},
PrefDef(context, Settings.PREF_SPLIT_SPACER_SCALE, R.string.split_spacer_scale) {
SliderPreference(
name = it.title,
pref = it.key,
default = SettingsValues.DEFAULT_SIZE_SCALE,
range = 0.5f..2f,
description = { "${(100 * it).toInt()}%" }
)
},
PrefDef(context, Settings.PREF_NARROW_KEY_GAPS, R.string.prefs_narrow_key_gaps) {
SwitchPreference(it, false)
},
PrefDef(context, Settings.PREF_KEYBOARD_HEIGHT_SCALE, R.string.prefs_keyboard_height_scale) {
SliderPreference(
name = it.title,
pref = it.key,
default = SettingsValues.DEFAULT_SIZE_SCALE,
range = 0.5f..1.5f,
description = { "${(100 * it).toInt()}%" }
)
},
PrefDef(context, Settings.PREF_BOTTOM_PADDING_SCALE, R.string.prefs_bottom_padding_scale) {
SliderPreference(
name = it.title,
pref = it.key,
default = SettingsValues.DEFAULT_SIZE_SCALE,
range = 0f..5f,
description = { "${(100 * it).toInt()}%" }
)
},
PrefDef(context, Settings.PREF_SPACE_BAR_TEXT, R.string.prefs_space_bar_text) { def ->
var showDialog by remember { mutableStateOf(false) }
val prefs = LocalContext.current.prefs()
Preference(
name = def.title,
onClick = { showDialog = true },
description = prefs.getString(def.key, "")
) // todo: create and show the dialog
},
PrefDef(context, NonSettingsPrefs.CUSTOM_FONT, R.string.custom_font) { def ->
var showDialog by remember { mutableStateOf(false) }
Preference(
name = def.title,
onClick = { showDialog = true },
) // todo: create and show the dialog
},
)
@Preview