From 85b02a2e8832e7c1f8c10960385b357ea884de25 Mon Sep 17 00:00:00 2001 From: eranl <1707552+eranl@users.noreply.github.com> Date: Sun, 9 Mar 2025 00:53:07 +0200 Subject: [PATCH] Enable TLD hint Avoid TLD popups on tablet Revert to using set for TLDs, and insert default ones first Move setting one slot up Tweak setting description Update docs --- README.md | 2 -- .../layouts/functional/functional_keys.json | 2 +- .../keyboard_parser/LocaleKeyboardInfos.kt | 21 ++++++++++--------- .../keyboard_parser/floris/TextKeyData.kt | 2 ++ .../settings/screens/PreferencesScreen.kt | 6 +++--- app/src/main/res/values/strings.xml | 2 +- layouts.md | 2 +- 7 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index ae62abc0..113f49dc 100644 --- a/README.md +++ b/README.md @@ -100,8 +100,6 @@ __Planned features and improvements:__ * Add and enable emoji dictionaries by default (if available for language) * Clearer / more intuitive arrangement of settings * Maybe hide some less used settings by default (similar to color customization) -* Make use of the `.com` key in URL fields (currently only available for tablets) - * With language-dependent TLDs * [Bug fixes](https://github.com/Helium314/HeliBoard/issues?q=is%3Aissue+is%3Aopen+label%3Abug) __What will _not_ be added:__ diff --git a/app/src/main/assets/layouts/functional/functional_keys.json b/app/src/main/assets/layouts/functional/functional_keys.json index 6d28dd24..788e4479 100644 --- a/app/src/main/assets/layouts/functional/functional_keys.json +++ b/app/src/main/assets/layouts/functional/functional_keys.json @@ -15,7 +15,7 @@ { "$": "keyboard_state_selector", "emojiKeyEnabled": { "$": "keyboard_state_selector", "alphabet": { "label": "emoji" }}}, { "$": "keyboard_state_selector", "symbols": { "label": "numpad" }}, { "label": "space" }, - { "label": "period", "labelFlags": 1073741824 }, + { "label": "period" }, { "label": "action", "width": 0.15 } ] ] diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt index 50c2049c..eba17161 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/LocaleKeyboardInfos.kt @@ -89,12 +89,6 @@ class LocaleKeyboardInfos(dataStream: InputStream?, locale: Locale) { } } - fun addDefaultTlds(locale: Locale) { - if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country)) - tlds.add(0, ".eu") - tlds.addAll(0, defaultTlds.splitOnWhitespace()) - } - /** Pair(extraKeysLeft, extraKeysRight) */ fun getTabletExtraKeys(elementId: Int): Pair, List> { val flags = Key.LABEL_FLAGS_FONT_DEFAULT @@ -205,7 +199,6 @@ private fun createLocaleKeyTexts(context: Context, params: KeyboardParams, popup if (locale == params.mId.locale) return@forEach lkt.addFile(getStreamForLocale(locale, context), true) } - lkt.addDefaultTlds(params.mId.locale) when (popupKeysSetting) { POPUP_KEYS_MAIN -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_main.txt"), false) POPUP_KEYS_MORE -> lkt.addFile(context.assets.open("$LOCALE_TEXTS_FOLDER/more_popups_more.txt"), false) @@ -226,20 +219,28 @@ private fun getStreamForLocale(locale: Locale, context: Context) = } } -private fun getLocaleTlds(locale: Locale): ArrayList { +private fun getLocaleTlds(locale: Locale): LinkedHashSet { + val tlds = getDefaultTlds(locale) val ccLower = locale.country.lowercase() - val tlds = arrayListOf() if (ccLower.isEmpty() || locale.language == SubtypeLocaleUtils.NO_LANGUAGE) return tlds specialCountryTlds.forEach { if (ccLower != it.first) return@forEach tlds.addAll(it.second.splitOnWhitespace()) - return tlds + return@getLocaleTlds tlds } tlds.add(".$ccLower") return tlds } +private fun getDefaultTlds(locale: Locale): LinkedHashSet { + val tlds = linkedSetOf() + tlds.addAll(defaultTlds.splitOnWhitespace()) + if ((locale.language != "en" && euroLocales.matches(locale.language)) || euroCountries.matches(locale.country)) + tlds.add(".eu") + return tlds +} + fun clearCache() = localeKeyboardInfosCache.clear() // cache the texts, so they don't need to be read over and over diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index 5d00b93a..66eb4dc9 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -24,6 +24,7 @@ import helium314.keyboard.latin.common.StringUtils import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.spellcheck.AndroidSpellCheckerService import helium314.keyboard.latin.utils.InputTypeUtils +import helium314.keyboard.latin.utils.LayoutType import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.ToolbarKey import helium314.keyboard.latin.utils.getCodeForToolbarKey @@ -574,6 +575,7 @@ sealed interface KeyData : AbstractKeyData { private fun getPeriodPopups(params: KeyboardParams): SimplePopups = SimplePopups( if (Settings.getInstance().current.mShowTldPopupKeys + && params.mId.mSubtype.layouts[LayoutType.FUNCTIONAL] != "functional_keys_tablet" && params.mId.mMode in setOf(KeyboardId.MODE_URL, KeyboardId.MODE_EMAIL) ) params.mLocaleKeyboardInfos.tlds else getPunctuationPopupKeys(params) 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 19c03bbd..d7e88c84 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/PreferencesScreen.kt @@ -90,15 +90,15 @@ fun createPreferencesSettings(context: Context) = listOf( Setting(context, Settings.PREF_POPUP_KEYS_ORDER, R.string.popup_order) { ReorderSwitchPreference(it, Defaults.PREF_POPUP_KEYS_ORDER) }, - Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) { - SwitchPreference(it, Defaults.PREF_SHOW_POPUP_HINTS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() } - }, Setting( context, Settings.PREF_SHOW_TLD_POPUP_KEYS, R.string.show_tld_popup_keys, R.string.show_tld_popup_keys_summary ) { SwitchPreference(it, Defaults.PREF_SHOW_TLD_POPUP_KEYS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() } }, + Setting(context, Settings.PREF_SHOW_POPUP_HINTS, R.string.show_popup_hints, R.string.show_popup_hints_summary) { + SwitchPreference(it, Defaults.PREF_SHOW_POPUP_HINTS) { KeyboardSwitcher.getInstance().setThemeNeedsReload() } + }, Setting(context, Settings.PREF_POPUP_ON, R.string.popup_on_keypress) { SwitchPreference(it, Defaults.PREF_POPUP_ON) { KeyboardSwitcher.getInstance().reloadKeyboard() } }, diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 454fd16c..e6bb1d30 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -252,7 +252,7 @@ Show TLD popup keys - Replace period key popups with top level domains for URL and email inputs + Replace period key popups with top level domains when typing URLs and email addresses Number row Language diff --git a/layouts.md b/layouts.md index 2af0f562..b442e934 100644 --- a/layouts.md +++ b/layouts.md @@ -89,7 +89,7 @@ Usually the label is what is displayed on the key. However, there are some speci * _symbol_alpha_: toggle alpha / symbol keyboard * _numpad_: toggle numpad layout * _emoji_: switch to emoji view - * _com_: display common TLDs (.com and similar, currently not localized) + * _com_: display common TLDs (.com and similar, localized) * _language_switch_: language switch key * _action_: the action (enter) key * _delete_: delete key