From b849c696c5f5c5b7037a4f1d498d0b465ef7572a Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sat, 8 Feb 2025 21:28:40 +0100 Subject: [PATCH] use old way of restarting with debug settings and hide debug settings from search --- .../keyboard/settings/SettingsActivity.kt | 16 +++--- .../keyboard/settings/SettingsContainer.kt | 5 +- .../keyboard/settings/screens/DebugScreen.kt | 55 +++++++++---------- app/src/main/res/values/strings.xml | 2 - 4 files changed, 36 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index 68da01fe..50958195 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -13,9 +13,7 @@ import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.utils.prefs import kotlinx.coroutines.flow.MutableStateFlow -// todo (roughly in order) -// any way to get rid of the "old" background on starting settings? probably comes from app theme, can we avoid it? -// try making old fragment back stuff work better, and try the different themes (with and without top bar, it should only appear for old fragments) +// todo // calling KeyboardSwitcher.getInstance().forceUpdateKeyboardTheme(requireContext()) while keyboard is showing shows just full screen background // but reload while keyboard is showing would be great (isn't it at least semi-done when changing one-handed mode?) // bg image inconsistent about being on toolbar or not (is this new?) @@ -27,25 +25,25 @@ import kotlinx.coroutines.flow.MutableStateFlow // maybe related to lazy column? // PRs adding prefs -> need to finish and merge main before finishing this PR // 1263 (no response for several weeks now...) -// really use the restart dialog for debug settings stuff? -// could do it the old way, and hide debug settings from search // what should be done, but not in this PR +// merge PREF_TOOLBAR_CUSTOM_KEY_CODES and PREF_TOOLBAR_CUSTOM_LONGPRESS_CODES into one pref (don't forget settings upgrade) +// replace the setup wizard +// platformActivityTheme background color should align with compose background (also consider dynamic colors) +// probably no need for appcompat any more +// replace color settings (should at least change how colors are stored, and have a color search/filter) // 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) // 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) // does it make sense to put this into PrefDef? // 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) +// use context.prefs() outside settings // adjust debug settings // have them in main screen? // allow users to find the individual settings in search even if debug settings are not enabled? -// replace the setup wizard // consider disabled settings & search // don't show -> users confused diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt index a4efd9e2..923f4205 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt @@ -8,7 +8,6 @@ import helium314.keyboard.settings.screens.createAboutSettings import helium314.keyboard.settings.screens.createAdvancedSettings import helium314.keyboard.settings.screens.createAppearanceSettings import helium314.keyboard.settings.screens.createCorrectionSettings -import helium314.keyboard.settings.screens.createDebugSettings import helium314.keyboard.settings.screens.createGestureTypingSettings import helium314.keyboard.settings.screens.createPreferencesSettings import helium314.keyboard.settings.screens.createToolbarSettingss @@ -54,10 +53,10 @@ class Setting( } } +// intentionally not putting individual debug settings in here so user knows the context private fun createSettings(context: Context) = createAboutSettings(context) + createCorrectionSettings(context) + createPreferencesSettings(context) + createToolbarSettingss(context) + - createGestureTypingSettings(context) + createAdvancedSettings(context) + createDebugSettings(context) + - createAppearanceSettings(context) + createGestureTypingSettings(context) + createAdvancedSettings(context) + createAppearanceSettings(context) object SettingsWithoutKey { const val EDIT_PERSONAL_DICTIONARY = "edit_personal_dictionary" diff --git a/app/src/main/java/helium314/keyboard/settings/screens/DebugScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/DebugScreen.kt index 8f9e5b89..1a08bc23 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/DebugScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/DebugScreen.kt @@ -3,14 +3,10 @@ package helium314.keyboard.settings.screens import android.content.Context import android.content.Intent +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.material3.Surface -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -28,13 +24,15 @@ import helium314.keyboard.settings.SearchPrefScreen import helium314.keyboard.settings.SettingsActivity import helium314.keyboard.settings.preferences.SwitchPreference import helium314.keyboard.settings.Theme -import helium314.keyboard.settings.dialogs.ConfirmationDialog import helium314.keyboard.settings.keyboardNeedsReload +import helium314.keyboard.settings.preferences.PreferenceCategory @Composable fun DebugScreen( onClickBack: () -> Unit, ) { + val ctx = LocalContext.current + val settings = createDebugSettings(ctx) val items = listOfNotNull( if (!BuildConfig.DEBUG) DebugSettings.PREF_SHOW_DEBUG_SETTINGS else null, DebugSettings.PREF_DEBUG_MODE, @@ -44,13 +42,30 @@ fun DebugScreen( R.string.prefs_dump_dynamic_dicts ) + DictionaryFacilitator.DYNAMIC_DICTIONARY_TYPES.map { DebugSettingsFragment.PREF_KEY_DUMP_DICT_PREFIX + it } SearchPrefScreen( - onClickBack = onClickBack, + onClickBack = { + if (needsRestart) { + val intent = Intent.makeRestartActivityTask(ctx.packageManager.getLaunchIntentForPackage(ctx.packageName)?.component) + intent.setPackage(ctx.packageName) + ctx.startActivity(intent) + Runtime.getRuntime().exit(0) + } + onClickBack() + }, title = stringResource(R.string.debug_settings_title), prefs = items - ) + ) { + LazyColumn { + items(items, key = { it }) { item -> + if (item is Int) PreferenceCategory(stringResource(item)) + else settings.first { it.key == item }.Preference() + } + } + } } -fun createDebugSettings(context: Context) = listOf( +private var needsRestart = false + +private fun createDebugSettings(context: Context) = listOf( Setting(context, DebugSettings.PREF_SHOW_DEBUG_SETTINGS, R.string.prefs_show_debug_settings) { setting -> val prefs = LocalContext.current.prefs() SwitchPreference(setting, false) @@ -58,7 +73,6 @@ fun createDebugSettings(context: Context) = listOf( }, Setting(context, DebugSettings.PREF_DEBUG_MODE, R.string.prefs_debug_mode) { setting -> val prefs = LocalContext.current.prefs() - var showConfirmDialog by rememberSaveable { mutableStateOf(false) } SwitchPreference( name = setting.title, key = setting.key, @@ -66,29 +80,14 @@ fun createDebugSettings(context: Context) = listOf( default = false, ) { 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)) } - ) + needsRestart = true } }, Setting(context, DebugSettings.PREF_SHOW_SUGGESTION_INFOS, R.string.prefs_show_suggestion_infos) { SwitchPreference(it, false) { keyboardNeedsReload = true } }, Setting(context, DebugSettings.PREF_FORCE_NON_DISTINCT_MULTITOUCH, R.string.prefs_force_non_distinct_multitouch) { - var showConfirmDialog by rememberSaveable { mutableStateOf(false) } - SwitchPreference(it, false) { showConfirmDialog = true } - if (showConfirmDialog) { - ConfirmationDialog( - onDismissRequest = { showConfirmDialog = false }, - onConfirmed = { Runtime.getRuntime().exit(0) }, - text = { Text(stringResource(R.string.message_restart_required)) } - ) - } + SwitchPreference(it, false) { needsRestart = true } }, Setting(context, DebugSettings.PREF_SLIDING_KEY_INPUT_PREVIEW, R.string.sliding_key_input_preview, R.string.sliding_key_input_preview_summary) { def -> SwitchPreference(def, false) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b208d72..d9810832 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -982,6 +982,4 @@ New dictionary: Customize icons Really reset all customized icons? - - Application restart is required to apply the changes. Quit now?