From 1c9e059d89477ff5a12372442dfe551c4e248c6a Mon Sep 17 00:00:00 2001 From: LeanBitLab Date: Sat, 21 Nov 2026 22:01:44 +0530 Subject: [PATCH] feat(settings): reorganise settings so they are easier to find - Search long-press on AI Integration and Translation settings now opens their own screens instead of Advanced - Remove the duplicate swipe distance from Advanced (kept in Gesture typing) - Main screen: Toolbar joins the first card, AI Integration and Plugins get their own card - Move App Profiles to Advanced and Remember language per app to Languages - Move custom currency and timestamp format to Preferences > Additional keys - Appearance: keyboard height and split keyboard come right after Theme - Indent settings inside open fine-tune sections Refs #873 --- .../keyboard/settings/SearchScreen.kt | 30 ++++++- .../keyboard/settings/SettingsContainer.kt | 13 +-- .../keyboard/settings/SettingsNavHost.kt | 1 - .../settings/screens/AdvancedScreen.kt | 80 +++++++++---------- .../settings/screens/AppearanceScreen.kt | 40 +++++----- .../settings/screens/LanguageScreen.kt | 7 +- .../settings/screens/LibrariesHubScreen.kt | 51 +----------- .../settings/screens/MainSettingsScreen.kt | 51 +++++++----- .../settings/screens/PreferencesScreen.kt | 32 ++++++++ .../settings/SettingsContainerTest.kt | 16 ++++ 10 files changed, 177 insertions(+), 144 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt index 642a8bcb7e..fc878305bd 100644 --- a/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/SearchScreen.kt @@ -42,6 +42,9 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.drawBehind +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.geometry.Size import androidx.compose.ui.draw.rotate import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester @@ -49,6 +52,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import helium314.keyboard.latin.R import helium314.keyboard.settings.preferences.PreferenceCategory @@ -190,7 +194,17 @@ fun SearchSettingsScreen( // a setting further down in a large card is not on screen after scrolling to it val bringIntoView = remember { BringIntoViewRequester() } LaunchedEffect(highlightKey) { if (key == highlightKey) bringIntoView.bringIntoView() } - Box(Modifier.bringIntoViewRequester(bringIntoView).background(highlight)) { + val nestedLine = MaterialTheme.colorScheme.outlineVariant + val nestedModifier = if (!row.nested) Modifier else Modifier + // a guide line and an indent show that the setting belongs to the fine-tune section above + .drawBehind { + val lineWidth = 2.dp.toPx() + val x = 14.dp.toPx() + val left = if (layoutDirection == LayoutDirection.Rtl) size.width - x - lineWidth else x + drawRect(nestedLine, topLeft = Offset(left, 0f), size = Size(lineWidth, size.height)) + } + .padding(start = 20.dp) + Box(Modifier.bringIntoViewRequester(bringIntoView).background(highlight).then(nestedModifier)) { SettingsActivity.settingsContainer[key]?.Preference() } } @@ -228,14 +242,22 @@ fun SearchSettingsScreen( ) } -/** A row of a settings screen: the title of a category ([key] is null) or a setting; first and last row of a card */ -private data class SettingRow(val id: String, val titleRes: Int?, val key: String?, val first: Boolean = false, val last: Boolean = false) +/** + * A row of a settings screen: the title of a category ([key] is null) or a setting; first and last row of a card. + * [nested]: the setting is inside an open fine-tune section, i.e. after a fine-tune header in the same card. + */ +private data class SettingRow(val id: String, val titleRes: Int?, val key: String?, val first: Boolean = false, val last: Boolean = false, val nested: Boolean = false) private fun settingRows(groups: List>>): List = buildList { groups.forEachIndexed { index, (titleRes, keys) -> val group = buildList { if (titleRes != null) add(SettingRow("title_${index}_$titleRes", titleRes, null)) - keys.forEach { add(SettingRow("${index}_$it", null, it)) } + var inFineTune = false + keys.forEach { + val isFineTuneHeader = it.startsWith(FINE_TUNE_SECTION_PREFIX) + add(SettingRow("${index}_$it", null, it, nested = inFineTune && !isFineTuneHeader)) + if (isFineTuneHeader) inFineTune = true + } } group.forEachIndexed { i, row -> add(row.copy(first = i == 0, last = i == group.lastIndex)) } } diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt index d32b8b9a81..7e6c431d91 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsContainer.kt @@ -10,7 +10,9 @@ import helium314.keyboard.latin.utils.JniUtils import helium314.keyboard.latin.R import helium314.keyboard.settings.preferences.Preference import helium314.keyboard.settings.screens.createAboutSettings -import helium314.keyboard.settings.screens.createAdvancedSettings +import helium314.keyboard.settings.screens.createAIIntegrationSettings +import helium314.keyboard.settings.screens.createAdvancedScreenSettings +import helium314.keyboard.settings.screens.createTranslationSettings import helium314.keyboard.settings.screens.createAppearanceSettings import helium314.keyboard.settings.screens.createBackgroundServicesSettings import helium314.keyboard.settings.screens.createCorrectionSettings @@ -19,7 +21,6 @@ import helium314.keyboard.settings.screens.createGestureTypingSettings import helium314.keyboard.settings.screens.createLanguageSettings import helium314.keyboard.settings.screens.createLayoutSettings import helium314.keyboard.settings.screens.createOcrSettings -import helium314.keyboard.settings.screens.createLibrariesSettings import helium314.keyboard.settings.screens.createPreferencesSettings import helium314.keyboard.settings.screens.createSoundSettings import helium314.keyboard.settings.screens.createTextExpanderSettings @@ -143,19 +144,19 @@ private val modules = listOf( SettingsModule(SettingsWithoutKey.SCREEN_NAV_GESTURES, SettingsDestination.GestureTyping, R.string.settings_screen_gesture, iconRes = R.drawable.ic_settings_gesture, provider = ::createGestureTypingSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_TEXT_CORRECTION, SettingsDestination.TextCorrection, R.string.settings_screen_correction, iconRes = R.drawable.ic_settings_correction, provider = ::createCorrectionSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_SUGGESTIONS, SettingsDestination.Suggestions, R.string.settings_screen_suggestions, iconRes = R.drawable.ic_settings_suggestions, provider = ::createSuggestionsSettings), - SettingsModule(SettingsWithoutKey.SCREEN_NAV_AI_INTEGRATION, SettingsDestination.AIIntegration, R.string.settings_screen_ai_integration, iconRes = R.drawable.ic_proofread), + SettingsModule(SettingsWithoutKey.SCREEN_NAV_AI_INTEGRATION, SettingsDestination.AIIntegration, R.string.settings_screen_ai_integration, iconRes = R.drawable.ic_proofread, provider = ::createAIIntegrationSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_TEXT_EXPANDER, SettingsDestination.TextExpander, titleString = "Text Expander", iconRes = R.drawable.ic_edit, provider = ::createTextExpanderSettings), - SettingsModule(SettingsWithoutKey.SCREEN_NAV_ADVANCED, SettingsDestination.Advanced, R.string.settings_screen_advanced, iconRes = R.drawable.ic_settings_advanced, provider = ::createAdvancedSettings), + SettingsModule(SettingsWithoutKey.SCREEN_NAV_ADVANCED, SettingsDestination.Advanced, R.string.settings_screen_advanced, iconRes = R.drawable.ic_settings_advanced, provider = ::createAdvancedScreenSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_ABOUT, SettingsDestination.About, R.string.settings_screen_about, iconRes = R.drawable.ic_settings_about, provider = ::createAboutSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_OCR, SettingsDestination.OCR, R.string.ocr_settings_title, iconRes = R.drawable.ic_ocr, provider = ::createOcrSettings), - SettingsModule(SettingsWithoutKey.SCREEN_NAV_LIBRARIES, SettingsDestination.Libraries, R.string.libraries_hub_title, iconRes = R.drawable.ic_emoji_objects, provider = ::createLibrariesSettings), + SettingsModule(SettingsWithoutKey.SCREEN_NAV_LIBRARIES, SettingsDestination.Libraries, R.string.libraries_hub_title, iconRes = R.drawable.ic_emoji_objects), SettingsModule(SettingsWithoutKey.SCREEN_NAV_BACKGROUND_SERVICES, SettingsDestination.BackgroundServices, titleString = "Background Services", provider = ::createBackgroundServicesSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_DICTIONARIES, SettingsDestination.Dictionaries, R.string.dictionary_settings_category, iconRes = R.drawable.ic_dictionary), SettingsModule(SettingsWithoutKey.SCREEN_NAV_PERSONAL_DICTIONARIES, SettingsDestination.PersonalDictionaries, R.string.edit_personal_dictionary, iconRes = R.drawable.ic_dictionary), SettingsModule(SettingsWithoutKey.SCREEN_NAV_BLOCKED_WORDS, SettingsDestination.BlockedWords, R.string.edit_blocked_words, iconRes = R.drawable.ic_bin), SettingsModule(SettingsWithoutKey.SCREEN_NAV_SOUND, SettingsDestination.Sound, R.string.sound_packs_title, iconRes = R.drawable.ic_play_arrow, provider = ::createSoundSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_VOICE, SettingsDestination.OfflineVoice, R.string.voice_input_title, iconRes = R.drawable.sym_keyboard_voice_holo, provider = ::createVoiceSettings), - SettingsModule(SettingsWithoutKey.SCREEN_NAV_TRANSLATION, SettingsDestination.Translation, R.string.translation_settings_title, iconRes = R.drawable.ic_translate), + SettingsModule(SettingsWithoutKey.SCREEN_NAV_TRANSLATION, SettingsDestination.Translation, R.string.translation_settings_title, iconRes = R.drawable.ic_translate, provider = ::createTranslationSettings), SettingsModule(SettingsWithoutKey.SCREEN_NAV_HANDWRITING, SettingsDestination.Handwriting, R.string.libraries_hub_handwriting_title, iconRes = R.drawable.ic_edit), SettingsModule(SettingsWithoutKey.SCREEN_NAV_CJK, SettingsDestination.Cjk, R.string.cjk_settings_title, iconRes = R.drawable.ic_settings_languages), SettingsModule(SettingsWithoutKey.SCREEN_NAV_UPDATES, SettingsDestination.Updates, R.string.settings_screen_updates, iconRes = R.drawable.ic_settings_updates) diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt b/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt index 33e43cb664..4040c45a76 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsNavHost.kt @@ -129,7 +129,6 @@ fun SettingsNavHost( onClickOcr = { navController.navigate(SettingsDestination.OCR) }, onClickAIIntegration = { navController.navigate(SettingsDestination.AIIntegration) }, onClickSound = { navController.navigate(SettingsDestination.Sound) }, - onClickAppProfiles = { navController.navigate(SettingsDestination.AppQuirks) }, onClickCjk = { navController.navigate(SettingsDestination.Cjk) }, ) } diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt index 2a73bf45cb..dc4c6aa9c1 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AdvancedScreen.kt @@ -28,17 +28,13 @@ 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.keyboard.KeyboardActionListener -import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.KeyboardSwitcher import helium314.keyboard.keyboard.emoji.SupportedEmojis import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.R -import helium314.keyboard.latin.common.splitOnWhitespace import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.Defaults import helium314.keyboard.latin.settings.Settings -import helium314.keyboard.latin.utils.checkTimestampFormat import helium314.keyboard.latin.utils.prefs import helium314.keyboard.settings.fineTuneExpanded import helium314.keyboard.settings.dialogs.ConfirmationDialog @@ -60,7 +56,6 @@ import helium314.keyboard.settings.Theme import helium314.keyboard.settings.preferences.BackupRestorePreference import helium314.keyboard.settings.preferences.ExpandablePreference import helium314.keyboard.settings.preferences.LoadGestureLibPreference -import helium314.keyboard.settings.preferences.TextInputPreference import helium314.keyboard.settings.previewDark import androidx.core.content.edit import kotlinx.coroutines.flow.MutableStateFlow @@ -92,6 +87,7 @@ fun AdvancedSettingsScreen( // Primary Settings.PREF_ALWAYS_INCOGNITO_MODE, Settings.PREF_DISABLE_NETWORK, + SettingsWithoutKey.APP_QUIRKS, SettingsWithoutKey.BACKGROUND_SERVICES, SettingsWithoutKey.BACKUP_RESTORE, if (BuildConfig.DEBUG || prefs.getBoolean(DebugSettings.PREF_SHOW_DEBUG_SETTINGS, Defaults.PREF_SHOW_DEBUG_SETTINGS)) @@ -99,14 +95,9 @@ fun AdvancedSettingsScreen( Settings.PREF_EXPAND_FINE_TUNE_ADVANCED, // Fine-tune physical keyboards & experimental - if (fineTuneAdvancedExpanded && (Settings.readHorizontalSpaceSwipe(prefs) == KeyboardActionListener.SWIPE_SWITCH_LANGUAGE - || Settings.readFullKeyboardSwipe(prefs) != KeyboardActionListener.SWIPE_NO_ACTION)) - Settings.PREF_LANGUAGE_SWIPE_DISTANCE else null, if (fineTuneAdvancedExpanded) Settings.PREF_PHYSICAL_KEYBOARD_LAYOUT else null, if (fineTuneAdvancedExpanded) Settings.PREF_ENABLE_EMOJI_ALT_PHYSICAL_KEY else null, if (fineTuneAdvancedExpanded) Settings.PREF_PHYSICAL_KEYBOARD_SUGGESTION_SHORTCUTS else null, - if (fineTuneAdvancedExpanded) Settings.PREF_CUSTOM_CURRENCY_KEY else null, - if (fineTuneAdvancedExpanded) Settings.PREF_TIMESTAMP_FORMAT else null, if (fineTuneAdvancedExpanded) R.string.settings_category_experimental else null, if (fineTuneAdvancedExpanded) Settings.PREF_EMOJI_MAX_SDK else null, if (fineTuneAdvancedExpanded) Settings.PREF_URL_DETECTION else null, @@ -119,26 +110,43 @@ fun AdvancedSettingsScreen( ) } -@SuppressLint("ApplySharedPref") +// Settings defined below but shown on other screens: each list is registered with the screen +// that shows it, so a long press in the search opens that screen and not the advanced one. +private val translationSettingKeys = setOf( + SettingsWithoutKey.TRANSLATION_ENGINE, + SettingsWithoutKey.TRANSLATION_SOURCE_LANGUAGE, + SettingsWithoutKey.GEMINI_TARGET_LANGUAGE, +) +private val aiIntegrationSettingKeys = setOf( + SettingsWithoutKey.GEMINI_API_KEY, SettingsWithoutKey.GEMINI_MODEL, SettingsWithoutKey.AI_PROVIDER, + SettingsWithoutKey.GROQ_TOKEN, SettingsWithoutKey.GROQ_MODEL, + SettingsWithoutKey.HUGGINGFACE_TOKEN, SettingsWithoutKey.HUGGINGFACE_MODEL, SettingsWithoutKey.HUGGINGFACE_ENDPOINT, + SettingsWithoutKey.OPENAI_USE_MAX_COMPLETION_TOKENS, SettingsWithoutKey.OPENAI_OMIT_TEMPERATURE, + SettingsWithoutKey.AI_ALLOW_INSECURE_CONNECTIONS, SettingsWithoutKey.CLOUD_AI_MAX_TOKENS, + SettingsWithoutKey.TRANSLATE_GEMINI_MODEL, SettingsWithoutKey.TRANSLATE_GROQ_MODEL, SettingsWithoutKey.TRANSLATE_HUGGINGFACE_MODEL, + SettingsWithoutKey.VOICE_GEMINI_MODEL, SettingsWithoutKey.VOICE_GROQ_MODEL, SettingsWithoutKey.VOICE_HUGGINGFACE_MODEL, + SettingsWithoutKey.CUSTOM_AI_KEYS, SettingsWithoutKey.LOAD_OFFLINE_AI_PLUGIN, + SettingsWithoutKey.OFFLINE_KEEP_MODEL_LOADED, SettingsWithoutKey.OFFLINE_MODEL_PATH, +) + +fun createAdvancedScreenSettings(context: Context) = + createAdvancedSettings(context).filter { it.key !in aiIntegrationSettingKeys && it.key !in translationSettingKeys } + +fun createAIIntegrationSettings(context: Context) = createAdvancedSettings(context).filter { it.key in aiIntegrationSettingKeys } + +fun createTranslationSettings(context: Context) = createAdvancedSettings(context).filter { it.key in translationSettingKeys } + /** Keeps the saved model in a fetched model list, so the setting still shows it if the provider no longer lists it */ private fun withSavedModel(items: List>, savedModel: String) = if (savedModel.isBlank() || items.any { it.second == savedModel }) items else items + (savedModel to savedModel) -fun createAdvancedSettings(context: Context) = listOfNotNull( +@SuppressLint("ApplySharedPref") +private fun createAdvancedSettings(context: Context) = listOfNotNull( Setting(context, Settings.PREF_ALWAYS_INCOGNITO_MODE, R.string.incognito, R.string.prefs_force_incognito_mode_summary) { SwitchPreference(it, Defaults.PREF_ALWAYS_INCOGNITO_MODE) { KeyboardSwitcher.getInstance().setThemeNeedsReload() } }, - Setting(context, Settings.PREF_LANGUAGE_SWIPE_DISTANCE, R.string.prefs_language_swipe_distance) { setting -> - SliderPreference( - name = setting.title, - key = setting.key, - default = Defaults.PREF_LANGUAGE_SWIPE_DISTANCE, - range = 2f..18f, - description = { it.toString() } - ) - }, Setting(context, Settings.PREF_PHYSICAL_KEYBOARD_LAYOUT, R.string.prefs_physical_keyboard_layout, R.string.prefs_physical_keyboard_layout_summary) { setting -> val items = listOf( @@ -171,29 +179,16 @@ fun createAdvancedSettings(context: Context) = listOfNotNull( ) ListPreference(setting, items, Defaults.PREF_PHYSICAL_KEYBOARD_SUGGESTION_SHORTCUTS) }, - Setting(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { setting -> - var showDialog by rememberSaveable { mutableStateOf(false) } - Preference( - name = setting.title, - onClick = { showDialog = true } - ) - if (showDialog) { - val prefs = LocalContext.current.prefs() - TextInputDialog( - onDismissRequest = { showDialog = false }, - textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) }, - initialText = prefs.getString(setting.key, Defaults.PREF_CUSTOM_CURRENCY_KEY) ?: Defaults.PREF_CUSTOM_CURRENCY_KEY, - onConfirmed = { prefs.edit { putString(setting.key, it) }; KeyboardLayoutSet.onSystemLocaleChanged() }, - title = { Text(stringResource(R.string.customize_currencies)) }, - neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null, - onNeutral = { prefs.edit { remove(setting.key)}; KeyboardLayoutSet.onSystemLocaleChanged() }, - checkTextValid = { text -> text.splitOnWhitespace().none { it.length > 8 } } - ) - } - }, Setting(context, SettingsWithoutKey.BACKUP_RESTORE, R.string.backup_restore_title) { BackupRestorePreference(it) }, + Setting(context, SettingsWithoutKey.APP_QUIRKS, R.string.app_quirks_title) { + Preference( + name = it.title, + description = stringResource(R.string.app_quirks_summary), + onClick = { SettingsDestination.navigateTo(SettingsDestination.AppQuirks) } + ) { NextScreenIcon() } + }, Setting(context, SettingsWithoutKey.BACKGROUND_SERVICES, R.string.background_services_title) { Preference( name = it.title, @@ -201,9 +196,6 @@ fun createAdvancedSettings(context: Context) = listOfNotNull( onClick = { SettingsDestination.navigateTo(SettingsDestination.BackgroundServices) } ) { NextScreenIcon() } }, - Setting(context, Settings.PREF_TIMESTAMP_FORMAT, R.string.timestamp_format_title) { setting -> - TextInputPreference(setting, Defaults.PREF_TIMESTAMP_FORMAT) { checkTimestampFormat(it) } - }, Setting(context, SettingsWithoutKey.DEBUG_SETTINGS, R.string.debug_settings_title) { Preference( name = it.title, diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt index 11cc5ecb5b..5246c73490 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AppearanceScreen.kt @@ -105,32 +105,13 @@ fun AppearanceScreen( if (fineTuneThemeExpanded) Settings.PREF_CUSTOM_ICON_NAMES else null, if (fineTuneThemeExpanded) Settings.PREF_CLEAR_CLIPBOARD_ICON else null, - // Key appearance - R.string.settings_category_key_appearance, - Settings.PREF_SHOW_HINTS, - Settings.PREF_POPUP_KEYS_ORDER, - Settings.PREF_POPUP_ON, - Settings.PREF_EXPAND_FINE_TUNE_KEY_PREVIEWS, - if (fineTuneKeyPreviewsExpanded && popupOnEnabled) - Settings.PREF_KEY_PREVIEW_WIDTH_SCALE else null, - if (fineTuneKeyPreviewsExpanded && popupOnEnabled) - Settings.PREF_KEY_PREVIEW_HEIGHT_SCALE else null, - if (fineTuneKeyPreviewsExpanded && popupOnEnabled) - Settings.PREF_KEY_PREVIEW_RADIUS else null, - if (fineTuneKeyPreviewsExpanded) Settings.PREF_POPUP_KEYS_VERTICAL_OFFSET_PERCENT else null, - if (fineTuneKeyPreviewsExpanded) Settings.PREF_ANIMATION_SPEED_SCALE else null, - if (fineTuneKeyPreviewsExpanded && showHintsEnabled) - Settings.PREF_POPUP_KEYS_LABELS_ORDER else null, - if (fineTuneKeyPreviewsExpanded) Settings.PREF_SHOW_POPUP_HINTS else null, - if (fineTuneKeyPreviewsExpanded) Settings.PREF_SHOW_TLD_POPUP_KEYS else null, - // Keyboard sizing, layout & fonts R.string.settings_category_miscellaneous, Settings.PREF_KEYBOARD_HEIGHT_SCALE_PREFIX, + Settings.PREF_ENABLE_SPLIT_KEYBOARD, SettingsWithoutKey.CUSTOM_FONT, SettingsWithoutKey.CUSTOM_EMOJI_FONT, Settings.PREF_SPACE_BAR_TEXT, - Settings.PREF_ENABLE_SPLIT_KEYBOARD, Settings.PREF_EXPAND_FINE_TUNE_FOLDABLE, if (fineTuneFoldableExpanded) Settings.PREF_UNFOLDED_KEYBOARD_HEIGHT_SCALE_PREFIX else null, if (fineTuneFoldableExpanded) Settings.PREF_ENABLE_SPLIT_KEYBOARD_UNFOLDED else null, @@ -153,6 +134,25 @@ fun AppearanceScreen( if (fineTuneKeyboardLayoutExpanded) Settings.PREF_SHOW_EMOJI_DESCRIPTIONS else null, if (fineTuneKeyboardLayoutExpanded && prefs.getFloat(Settings.PREF_EMOJI_FONT_SCALE, Defaults.PREF_EMOJI_FONT_SCALE) != 1f) Settings.PREF_EMOJI_KEY_FIT else null, + + // Key appearance + R.string.settings_category_key_appearance, + Settings.PREF_SHOW_HINTS, + Settings.PREF_POPUP_KEYS_ORDER, + Settings.PREF_POPUP_ON, + Settings.PREF_EXPAND_FINE_TUNE_KEY_PREVIEWS, + if (fineTuneKeyPreviewsExpanded && popupOnEnabled) + Settings.PREF_KEY_PREVIEW_WIDTH_SCALE else null, + if (fineTuneKeyPreviewsExpanded && popupOnEnabled) + Settings.PREF_KEY_PREVIEW_HEIGHT_SCALE else null, + if (fineTuneKeyPreviewsExpanded && popupOnEnabled) + Settings.PREF_KEY_PREVIEW_RADIUS else null, + if (fineTuneKeyPreviewsExpanded) Settings.PREF_POPUP_KEYS_VERTICAL_OFFSET_PERCENT else null, + if (fineTuneKeyPreviewsExpanded) Settings.PREF_ANIMATION_SPEED_SCALE else null, + if (fineTuneKeyPreviewsExpanded && showHintsEnabled) + Settings.PREF_POPUP_KEYS_LABELS_ORDER else null, + if (fineTuneKeyPreviewsExpanded) Settings.PREF_SHOW_POPUP_HINTS else null, + if (fineTuneKeyPreviewsExpanded) Settings.PREF_SHOW_TLD_POPUP_KEYS else null, ) } SearchSettingsScreen( diff --git a/app/src/main/java/helium314/keyboard/settings/screens/LanguageScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/LanguageScreen.kt index a6d9325025..2db194b47d 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/LanguageScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/LanguageScreen.kt @@ -62,6 +62,7 @@ import helium314.keyboard.latin.utils.LocaleUtils import helium314.keyboard.latin.utils.mainLayoutNameOrQwerty import helium314.keyboard.settings.Setting import helium314.keyboard.settings.preferences.ListPreference +import helium314.keyboard.settings.preferences.SwitchPreference import java.util.Locale @Composable @@ -77,7 +78,7 @@ fun LanguageScreen( SearchSettingsScreen( onClickBack = onClickBack, title = stringResource(R.string.language_and_layouts_title), - settings = listOf(Settings.PREF_APP_LANGUAGE) + settings = listOf(Settings.PREF_SAVE_SUBTYPE_PER_APP, Settings.PREF_APP_LANGUAGE) ) { Column( Modifier @@ -146,6 +147,7 @@ fun LanguageScreen( onClick = { SettingsDestination.navigateTo(SettingsDestination.Dictionaries) }, icon = R.drawable.ic_dictionary ) { NextScreenIcon() } + SettingsActivity.settingsContainer[Settings.PREF_SAVE_SUBTYPE_PER_APP]?.Preference() SettingsActivity.settingsContainer[Settings.PREF_APP_LANGUAGE]?.Preference() } } @@ -154,6 +156,9 @@ fun LanguageScreen( } fun createLanguageSettings(context: Context) = listOf( + Setting(context, Settings.PREF_SAVE_SUBTYPE_PER_APP, R.string.save_subtype_per_app) { + SwitchPreference(it, Defaults.PREF_SAVE_SUBTYPE_PER_APP, icon = R.drawable.ic_ime_switcher) + }, Setting(context, Settings.PREF_APP_LANGUAGE, R.string.app_language_title, R.string.app_language_summary) { ListPreference( it, diff --git a/app/src/main/java/helium314/keyboard/settings/screens/LibrariesHubScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/LibrariesHubScreen.kt index 7d62736cd0..5c0dcef435 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/LibrariesHubScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/LibrariesHubScreen.kt @@ -31,16 +31,12 @@ import helium314.keyboard.latin.sound.SoundPackUrls import helium314.keyboard.latin.translation.TranslationLoader import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.prefs -import android.content.Context import helium314.keyboard.settings.NextScreenIcon import helium314.keyboard.settings.SearchSettingsScreen -import helium314.keyboard.settings.Setting import helium314.keyboard.settings.SettingsActivity import helium314.keyboard.settings.SettingsDestination -import helium314.keyboard.settings.SettingsWithoutKey import helium314.keyboard.settings.preferences.Preference import helium314.keyboard.settings.preferences.PreferenceCategory -import helium314.keyboard.settings.preferences.SwitchPreference @Composable fun LibrariesHubScreen( @@ -51,7 +47,6 @@ fun LibrariesHubScreen( onClickOcr: () -> Unit = {}, onClickAIIntegration: () -> Unit = {}, onClickSound: () -> Unit = {}, - onClickAppProfiles: () -> Unit = { SettingsDestination.navigateTo(SettingsDestination.AppQuirks) }, onClickGif: () -> Unit = { SettingsDestination.navigateTo(SettingsDestination.Gif) }, onClickCjk: () -> Unit = { SettingsDestination.navigateTo(SettingsDestination.Cjk) }, ) { @@ -234,35 +229,7 @@ fun LibrariesHubScreen( } } - // Section 2: App Profiles - Card( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp, vertical = 8.dp), - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceContainer - ) - ) { - Column { - PreferenceCategory(stringResource(R.string.settings_category_app_profiles)) - - Preference( - name = stringResource(R.string.app_quirks_title), - description = stringResource(R.string.app_quirks_summary), - onClick = onClickAppProfiles, - icon = R.drawable.ic_settings_preferences - ) { NextScreenIcon() } - - SwitchPreference( - name = stringResource(R.string.save_subtype_per_app), - key = Settings.PREF_SAVE_SUBTYPE_PER_APP, - default = Defaults.PREF_SAVE_SUBTYPE_PER_APP, - icon = R.drawable.ic_ime_switcher - ) - } - } - - // Section 3: Storage & Maintenance + // Section 2: Storage & Maintenance Card( modifier = Modifier .fillMaxWidth() @@ -283,7 +250,7 @@ fun LibrariesHubScreen( } } - // Section 4: Documentation + // Section 3: Documentation Card( modifier = Modifier .fillMaxWidth() @@ -306,17 +273,3 @@ fun LibrariesHubScreen( } } } - -fun createLibrariesSettings(context: Context) = listOf( - Setting(context, Settings.PREF_SAVE_SUBTYPE_PER_APP, R.string.save_subtype_per_app) { - SwitchPreference(it, Defaults.PREF_SAVE_SUBTYPE_PER_APP, icon = R.drawable.ic_ime_switcher) - }, - Setting(context, SettingsWithoutKey.APP_QUIRKS, R.string.app_quirks_title) { - Preference( - name = stringResource(R.string.app_quirks_title), - description = stringResource(R.string.app_quirks_summary), - onClick = { SettingsDestination.navigateTo(SettingsDestination.AppQuirks) }, - icon = R.drawable.ic_settings_preferences - ) { NextScreenIcon() } - }, -) diff --git a/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt index 94ac581f91..a77b903d9a 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/MainSettingsScreen.kt @@ -190,7 +190,7 @@ fun MainSettingsScreen( } } - // Group 1: General (AI, Languages, Preferences, Appearance, Toolbar) + // Group 1: General (Languages, Appearance, Preferences, Toolbar) Card( modifier = Modifier .fillMaxWidth() @@ -200,34 +200,22 @@ fun MainSettingsScreen( ) ) { Column { - if (BuildConfig.FLAVOR == "standard" || BuildConfig.FLAVOR == "standardfull") { - Preference( - name = stringResource(R.string.settings_screen_ai_integration), - onClick = onClickAIIntegration, - icon = R.drawable.ic_proofread - ) { NextScreenIcon() } - } - Preference( - name = stringResource(R.string.plugins_title), - onClick = onClickLibraries, - icon = R.drawable.ic_emoji_objects - ) { NextScreenIcon() } Preference( name = stringResource(R.string.language_and_layouts_title), description = enabledSubtypesDescription, onClick = onClickLanguage, icon = R.drawable.ic_settings_languages ) { NextScreenIcon() } - Preference( - name = stringResource(R.string.settings_screen_preferences), - onClick = onClickPreferences, - icon = R.drawable.ic_settings_preferences - ) { NextScreenIcon() } Preference( name = stringResource(R.string.settings_screen_appearance), onClick = onClickAppearance, icon = R.drawable.ic_settings_appearance ) { NextScreenIcon() } + Preference( + name = stringResource(R.string.settings_screen_preferences), + onClick = onClickPreferences, + icon = R.drawable.ic_settings_preferences + ) { NextScreenIcon() } Preference( name = stringResource(R.string.settings_screen_toolbar), onClick = onClickToolbar, @@ -269,7 +257,32 @@ fun MainSettingsScreen( } } - // Group 3: Other (Advanced, About) + // Group 3: Extras (AI, Plugins) + Card( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 8.dp), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer + ) + ) { + Column { + if (BuildConfig.FLAVOR == "standard" || BuildConfig.FLAVOR == "standardfull") { + Preference( + name = stringResource(R.string.settings_screen_ai_integration), + onClick = onClickAIIntegration, + icon = R.drawable.ic_proofread + ) { NextScreenIcon() } + } + Preference( + name = stringResource(R.string.plugins_title), + onClick = onClickLibraries, + icon = R.drawable.ic_emoji_objects + ) { NextScreenIcon() } + } + } + + // Group 4: Other (Advanced, Updates, About) Card( modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt index 6efdae7329..b96e923eb0 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt @@ -47,6 +47,13 @@ import helium314.keyboard.settings.preferences.ListPreference import helium314.keyboard.settings.preferences.Preference import helium314.keyboard.settings.preferences.SliderPreference import helium314.keyboard.settings.preferences.SwitchPreference +import androidx.compose.material3.Text +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.core.content.edit +import helium314.keyboard.latin.common.splitOnWhitespace +import helium314.keyboard.latin.utils.checkTimestampFormat +import helium314.keyboard.settings.dialogs.TextInputDialog +import helium314.keyboard.settings.preferences.TextInputPreference import helium314.keyboard.settings.previewDark import kotlinx.coroutines.flow.MutableStateFlow import kotlin.math.roundToInt @@ -111,6 +118,8 @@ fun PreferencesScreen( if (fineTuneAdditionalKeysExpanded) Settings.PREF_DIRECT_IME_SWITCH_TARGET else null, if (fineTuneAdditionalKeysExpanded) Settings.PREF_REMOVE_REDUNDANT_POPUPS else null, if (fineTuneAdditionalKeysExpanded) Settings.PREF_MORE_POPUP_KEYS else null, + if (fineTuneAdditionalKeysExpanded) Settings.PREF_CUSTOM_CURRENCY_KEY else null, + if (fineTuneAdditionalKeysExpanded) Settings.PREF_TIMESTAMP_FORMAT else null, // Window modes R.string.settings_category_window_modes, @@ -140,6 +149,29 @@ fun PreferencesScreen( } fun createPreferencesSettings(context: Context) = listOf( + Setting(context, Settings.PREF_CUSTOM_CURRENCY_KEY, R.string.customize_currencies) { setting -> + var showDialog by rememberSaveable { mutableStateOf(false) } + Preference( + name = setting.title, + onClick = { showDialog = true } + ) + if (showDialog) { + val prefs = LocalContext.current.prefs() + TextInputDialog( + onDismissRequest = { showDialog = false }, + textInputLabel = { Text(stringResource(R.string.customize_currencies_detail)) }, + initialText = prefs.getString(setting.key, Defaults.PREF_CUSTOM_CURRENCY_KEY) ?: Defaults.PREF_CUSTOM_CURRENCY_KEY, + onConfirmed = { prefs.edit { putString(setting.key, it) }; KeyboardLayoutSet.onSystemLocaleChanged() }, + title = { Text(stringResource(R.string.customize_currencies)) }, + neutralButtonText = if (prefs.contains(setting.key)) stringResource(R.string.button_default) else null, + onNeutral = { prefs.edit { remove(setting.key)}; KeyboardLayoutSet.onSystemLocaleChanged() }, + checkTextValid = { text -> text.splitOnWhitespace().none { it.length > 8 } } + ) + } + }, + Setting(context, Settings.PREF_TIMESTAMP_FORMAT, R.string.timestamp_format_title) { setting -> + TextInputPreference(setting, Defaults.PREF_TIMESTAMP_FORMAT) { checkTimestampFormat(it) } + }, Setting(context, Settings.PREF_KEY_LONGPRESS_TIMEOUT, R.string.prefs_key_longpress_timeout_settings) { setting -> SliderPreference( name = setting.title, diff --git a/app/src/test/java/helium314/keyboard/settings/SettingsContainerTest.kt b/app/src/test/java/helium314/keyboard/settings/SettingsContainerTest.kt index 99f275c1e5..14b80b2527 100644 --- a/app/src/test/java/helium314/keyboard/settings/SettingsContainerTest.kt +++ b/app/src/test/java/helium314/keyboard/settings/SettingsContainerTest.kt @@ -30,6 +30,22 @@ class SettingsContainerTest { assertTrue(res.isNotEmpty()) } + @Test + fun searchJumpOpensTheScreenThatShowsTheSetting() { + val expected = mapOf( + SettingsWithoutKey.GEMINI_API_KEY to SettingsDestination.AIIntegration, + SettingsWithoutKey.AI_PROVIDER to SettingsDestination.AIIntegration, + SettingsWithoutKey.TRANSLATION_ENGINE to SettingsDestination.Translation, + SettingsWithoutKey.APP_QUIRKS to SettingsDestination.Advanced, + SettingsWithoutKey.BACKUP_RESTORE to SettingsDestination.Advanced, + helium314.keyboard.latin.settings.Settings.PREF_SAVE_SUBTYPE_PER_APP to SettingsDestination.Languages, + helium314.keyboard.latin.settings.Settings.PREF_LANGUAGE_SWIPE_DISTANCE to SettingsDestination.GestureTyping, + helium314.keyboard.latin.settings.Settings.PREF_CUSTOM_CURRENCY_KEY to SettingsDestination.Preferences, + helium314.keyboard.latin.settings.Settings.PREF_TIMESTAMP_FORMAT to SettingsDestination.Preferences, + ) + expected.forEach { (key, destination) -> assertEquals(key, destination, container.screenOf(key)) } + } + @Test fun testFilterPerformance() { val searches = listOf("a", "b", "c", "theme", "color", "sound", "vib", "dictionary", "key", "layout")