make settings work more like they should

This commit is contained in:
Helium314 2025-02-02 17:58:18 +01:00
parent bc5b9b4efc
commit d31bca1208
8 changed files with 77 additions and 14 deletions

View file

@ -15,6 +15,9 @@ import kotlinx.coroutines.flow.MutableStateFlow
// todo (roughly in order) // todo (roughly in order)
// make all prefs actually work // make all prefs actually work
// appearance
// advanced
// preferences
// try moving the recomposition of pref change somewhere else, so it's not duplicated everywhere // 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) // make the pref lists more compact (compare with old settings)
// try making text size similar to old state (also in dialogs) // try making text size similar to old state (also in dialogs)

View file

@ -148,6 +148,6 @@ object SettingsDestination {
navTarget.value = Settings navTarget.value = Settings
navScope.launch { delay(10); navTarget.value = target } navScope.launch { delay(10); navTarget.value = target }
} else } else
navTarget.value = About navTarget.value = target
} }
} }

View file

@ -2,13 +2,17 @@ package helium314.keyboard.settings.screens
import android.content.Context import android.content.Context
import android.os.Build import android.os.Build
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.BuildConfig
@ -206,7 +210,13 @@ fun createAdvancedPrefs(context: Context) = listOf(
Preference( Preference(
name = it.title, name = it.title,
onClick = { SettingsDestination.navigateTo(SettingsDestination.Debug) } onClick = { SettingsDestination.navigateTo(SettingsDestination.Debug) }
) ) {
Icon(
painter = painterResource(R.drawable.ic_arrow_left),
modifier = Modifier.scale(-1f, 1f),
contentDescription = null
)
}
}, },
PrefDef(context, Settings.PREF_EMOJI_MAX_SDK, R.string.prefs_key_emoji_max_sdk) { PrefDef(context, Settings.PREF_EMOJI_MAX_SDK, R.string.prefs_key_emoji_max_sdk) {
SliderPreference( SliderPreference(

View file

@ -3,7 +3,12 @@ package helium314.keyboard.settings.screens
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable 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.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -22,6 +27,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.dialogs.ConfirmationDialog
import helium314.keyboard.settings.keyboardNeedsReload import helium314.keyboard.settings.keyboardNeedsReload
@Composable @Composable
@ -30,9 +36,10 @@ fun DebugScreen(
) { ) {
SearchPrefScreen( SearchPrefScreen(
onClickBack = onClickBack, onClickBack = onClickBack,
title = stringResource(R.string.settings_screen_toolbar), title = stringResource(R.string.debug_settings_title),
) { ) {
SettingsActivity2.allPrefs.map[DebugSettings.PREF_SHOW_DEBUG_SETTINGS]!!.Preference() if (!BuildConfig.DEBUG)
SettingsActivity2.allPrefs.map[DebugSettings.PREF_SHOW_DEBUG_SETTINGS]!!.Preference()
SettingsActivity2.allPrefs.map[DebugSettings.PREF_DEBUG_MODE]!!.Preference() SettingsActivity2.allPrefs.map[DebugSettings.PREF_DEBUG_MODE]!!.Preference()
SettingsActivity2.allPrefs.map[DebugSettings.PREF_SHOW_SUGGESTION_INFOS]!!.Preference() SettingsActivity2.allPrefs.map[DebugSettings.PREF_SHOW_SUGGESTION_INFOS]!!.Preference()
SettingsActivity2.allPrefs.map[DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH]!!.Preference() SettingsActivity2.allPrefs.map[DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH]!!.Preference()
@ -52,21 +59,41 @@ fun createDebugPrefs(context: Context) = listOf(
name = def.title, name = def.title,
pref = def.key, pref = def.key,
default = false, default = false,
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME)
) { if (!it) prefs.edit().putBoolean(DebugSettings.PREF_DEBUG_MODE, false).apply() } ) { if (!it) prefs.edit().putBoolean(DebugSettings.PREF_DEBUG_MODE, false).apply() }
}, },
PrefDef(context, DebugSettings.PREF_DEBUG_MODE, R.string.prefs_debug_mode) { def -> PrefDef(context, DebugSettings.PREF_DEBUG_MODE, R.string.prefs_debug_mode) { def ->
val prefs = LocalContext.current.prefs() val prefs = LocalContext.current.prefs()
SwitchPreference(def, false) { var showConfirmDialog by remember { mutableStateOf(false) }
needsRestart = true SwitchPreference(
name = def.title,
pref = def.key,
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
default = false,
) {
if (!it) prefs.edit().putBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false).apply() if (!it) prefs.edit().putBoolean(DebugSettings.PREF_SHOW_SUGGESTION_INFOS, false).apply()
showConfirmDialog = true
}
if (showConfirmDialog) {
ConfirmationDialog(
onDismissRequest = { showConfirmDialog = false },
onConfirmed = { Runtime.getRuntime().exit(0) },
text = { Text(stringResource(R.string.message_restart_required)) }
)
} }
}, },
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) { keyboardNeedsReload = true } SwitchPreference(def, false) { keyboardNeedsReload = 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 } var showConfirmDialog by remember { mutableStateOf(false) }
SwitchPreference(def, false) { showConfirmDialog = true }
if (showConfirmDialog) {
ConfirmationDialog(
onDismissRequest = { showConfirmDialog = false },
onConfirmed = { Runtime.getRuntime().exit(0) },
text = { Text(stringResource(R.string.message_restart_required)) }
)
}
}, },
PrefDef(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def -> PrefDef(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def ->
SwitchPreference(def, false) SwitchPreference(def, false)
@ -95,6 +122,3 @@ private fun Preview() {
} }
} }
} }
// todo: actually use it
var needsRestart = false

View file

@ -71,10 +71,19 @@ fun createGestureTypingPrefs(context: Context) = listOf(
) )
}, },
PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary) { PrefDef(context, Settings.PREF_GESTURE_FLOATING_PREVIEW_DYNAMIC, R.string.gesture_floating_preview_text, R.string.gesture_floating_preview_dynamic_summary) {
val ctx = LocalContext.current
SwitchPreference( SwitchPreference(
def = it, def = it,
default = true default = true
) { keyboardNeedsReload = true } ) {
// is this complexity and 2 pref keys for one setting really needed?
// default value is based on system reduced motion
val default = Settings.readGestureDynamicPreviewDefault(ctx)
val followingSystem = it == default
// allow the default to be overridden
ctx.prefs().edit().putBoolean(Settings.PREF_GESTURE_DYNAMIC_PREVIEW_FOLLOW_SYSTEM, followingSystem).apply()
keyboardNeedsReload = 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(

View file

@ -81,7 +81,13 @@ fun MainSettingsScreen(
name = stringResource(R.string.settings_screen_gesture), name = stringResource(R.string.settings_screen_gesture),
onClick = onClickGestureTyping, onClick = onClickGestureTyping,
icon = R.drawable.ic_settings_gesture_foreground icon = R.drawable.ic_settings_gesture_foreground
) ) {
Icon(
painter = painterResource(R.drawable.ic_arrow_left),
modifier = Modifier.scale(-1f, 1f),
contentDescription = null
)
}
Preference( Preference(
name = stringResource(R.string.settings_screen_correction), name = stringResource(R.string.settings_screen_correction),
onClick = onClickTextCorrection, onClick = onClickTextCorrection,

View file

@ -7,6 +7,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -16,7 +17,9 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
@ -97,7 +100,13 @@ fun createCorrectionPrefs(context: Context) = listOf(
Preference( Preference(
name = stringResource(R.string.edit_personal_dictionary), name = stringResource(R.string.edit_personal_dictionary),
onClick = { ctx.getActivity()?.switchTo(UserDictionaryListFragment()) }, onClick = { ctx.getActivity()?.switchTo(UserDictionaryListFragment()) },
) ) {
Icon(
painter = painterResource(R.drawable.ic_arrow_left),
modifier = Modifier.scale(-1f, 1f),
contentDescription = null
)
}
}, },
PrefDef(context, PrefDef(context,
Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE, Settings.PREF_BLOCK_POTENTIALLY_OFFENSIVE,

View file

@ -968,4 +968,6 @@ New dictionary:
<string name="customize_icons">Customize icons</string> <string name="customize_icons">Customize icons</string>
<!-- Confirmation message when resetting all custom icons --> <!-- Confirmation message when resetting all custom icons -->
<string name="customize_icons_reset_message">Really reset all customized icons?</string> <string name="customize_icons_reset_message">Really reset all customized icons?</string>
<!-- Dialog message when restart of the app is required (sometimes actually does start again) -->
<string name="message_restart_required">A restart is required to apply the changes. Quit now?</string>
</resources> </resources>