diff --git a/app/src/keyboards/java/be/scri/helpers/KeyboardLanguageMappingConstants.kt b/app/src/keyboards/java/be/scri/helpers/KeyboardLanguageMappingConstants.kt index 72ffd571..475aef1f 100644 --- a/app/src/keyboards/java/be/scri/helpers/KeyboardLanguageMappingConstants.kt +++ b/app/src/keyboards/java/be/scri/helpers/KeyboardLanguageMappingConstants.kt @@ -84,6 +84,7 @@ object KeyboardLanguageMappingConstants { mapOf( "EN" to mapOf( + "recently_used" to ENInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to ENInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to ENInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to ENInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -96,6 +97,7 @@ object KeyboardLanguageMappingConstants { ), "ES" to mapOf( + "recently_used" to ESInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to ESInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to ESInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to ESInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -108,6 +110,7 @@ object KeyboardLanguageMappingConstants { ), "DE" to mapOf( + "recently_used" to DEInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to DEInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to DEInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to DEInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -120,6 +123,7 @@ object KeyboardLanguageMappingConstants { ), "IT" to mapOf( + "recently_used" to ITInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to ITInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to ITInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to ITInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -132,6 +136,7 @@ object KeyboardLanguageMappingConstants { ), "FR" to mapOf( + "recently_used" to FRInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to FRInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to FRInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to FRInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -144,6 +149,7 @@ object KeyboardLanguageMappingConstants { ), "PT" to mapOf( + "recently_used" to PTInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to PTInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to PTInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to PTInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -156,6 +162,7 @@ object KeyboardLanguageMappingConstants { ), "RU" to mapOf( + "recently_used" to RUInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to RUInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to RUInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to RUInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, @@ -168,6 +175,7 @@ object KeyboardLanguageMappingConstants { ), "SV" to mapOf( + "recently_used" to SVInterfaceVariables.RECENTLY_USED_EMOJI_HEADER, "smileys_emotion" to SVInterfaceVariables.SMILEYS_EMOTIONS_EMOJI_HEADER, "people_body" to SVInterfaceVariables.PEOPLE_BODY_EMOJI_HEADER, "animals_nature" to SVInterfaceVariables.ANIMALS_NATURE_EMOJI_HEADER, diff --git a/app/src/keyboards/java/be/scri/helpers/RecentEmojiHelper.kt b/app/src/keyboards/java/be/scri/helpers/RecentEmojiHelper.kt new file mode 100644 index 00000000..ad0dc3e7 --- /dev/null +++ b/app/src/keyboards/java/be/scri/helpers/RecentEmojiHelper.kt @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +package be.scri.helpers + +import android.content.Context + +private const val PREFS_NAME = "recent_emojis" +private const val KEY_RECENT = "recent_emoji_list" +private const val MAX_RECENT = 30 + +fun recordRecentEmoji( + context: Context, + emoji: String, +) { + val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + val current = + prefs + .getString(KEY_RECENT, "")!! + .split(",") + .filter { it.isNotBlank() } + .toMutableList() + current.remove(emoji) + current.add(0, emoji) + while (current.size > MAX_RECENT) current.removeAt(current.lastIndex) + prefs.edit().putString(KEY_RECENT, current.joinToString(",")).apply() +} + +fun getRecentEmojis(context: Context): List { + val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + return prefs.getString(KEY_RECENT, "")!!.split(",").filter { it.isNotBlank() } +} diff --git a/app/src/keyboards/java/be/scri/helpers/english/ENInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/english/ENInterfaceVariables.kt index dca8f86f..7c7cc4ce 100644 --- a/app/src/keyboards/java/be/scri/helpers/english/ENInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/english/ENInterfaceVariables.kt @@ -90,4 +90,5 @@ object ENInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objects" const val SYMBOLS_EMOJI_HEADER = "Symbols" const val FLAGS_EMOJI_HEADER = "Flags" + const val RECENTLY_USED_EMOJI_HEADER = "Recently Used" } diff --git a/app/src/keyboards/java/be/scri/helpers/french/FRInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/french/FRInterfaceVariables.kt index 8a214666..949b352d 100644 --- a/app/src/keyboards/java/be/scri/helpers/french/FRInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/french/FRInterfaceVariables.kt @@ -92,4 +92,5 @@ object FRInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objets" const val SYMBOLS_EMOJI_HEADER = "Symboles" const val FLAGS_EMOJI_HEADER = "Drapeaux" + const val RECENTLY_USED_EMOJI_HEADER = "Récemment Utilisés" } diff --git a/app/src/keyboards/java/be/scri/helpers/german/DEInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/german/DEInterfaceVariables.kt index 8da90ab3..9d7a3340 100644 --- a/app/src/keyboards/java/be/scri/helpers/german/DEInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/german/DEInterfaceVariables.kt @@ -91,4 +91,5 @@ object DEInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objekte" const val SYMBOLS_EMOJI_HEADER = "Symbole" const val FLAGS_EMOJI_HEADER = "Flaggen" + const val RECENTLY_USED_EMOJI_HEADER = "Zuletzt Verwendet" } diff --git a/app/src/keyboards/java/be/scri/helpers/italian/ITInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/italian/ITInterfaceVariables.kt index 3fd3cefd..ee1b9f33 100644 --- a/app/src/keyboards/java/be/scri/helpers/italian/ITInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/italian/ITInterfaceVariables.kt @@ -73,4 +73,5 @@ object ITInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Oggetti" const val SYMBOLS_EMOJI_HEADER = "Simboli" const val FLAGS_EMOJI_HEADER = "Bandiere" + const val RECENTLY_USED_EMOJI_HEADER = "Usati di Recente" } diff --git a/app/src/keyboards/java/be/scri/helpers/portuguese/PTInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/portuguese/PTInterfaceVariables.kt index 2d4a91a7..b6e3db36 100644 --- a/app/src/keyboards/java/be/scri/helpers/portuguese/PTInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/portuguese/PTInterfaceVariables.kt @@ -73,4 +73,5 @@ object PTInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objetos" const val SYMBOLS_EMOJI_HEADER = "Símbolos" const val FLAGS_EMOJI_HEADER = "Bandeiras" + const val RECENTLY_USED_EMOJI_HEADER = "Usados Recentemente" } diff --git a/app/src/keyboards/java/be/scri/helpers/russian/RUInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/russian/RUInterfaceVariables.kt index e503ca00..a4a5d0af 100644 --- a/app/src/keyboards/java/be/scri/helpers/russian/RUInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/russian/RUInterfaceVariables.kt @@ -73,4 +73,5 @@ object RUInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Предметы" const val SYMBOLS_EMOJI_HEADER = "Символы" const val FLAGS_EMOJI_HEADER = "Флаги" + const val RECENTLY_USED_EMOJI_HEADER = "Недавно Использованные" } diff --git a/app/src/keyboards/java/be/scri/helpers/spanish/ESInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/spanish/ESInterfaceVariables.kt index ce59cfbe..cdaca1f5 100644 --- a/app/src/keyboards/java/be/scri/helpers/spanish/ESInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/spanish/ESInterfaceVariables.kt @@ -94,4 +94,5 @@ object ESInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objetos" const val SYMBOLS_EMOJI_HEADER = "Símbolos" const val FLAGS_EMOJI_HEADER = "Banderas" + const val RECENTLY_USED_EMOJI_HEADER = "Usados Recientemente" } diff --git a/app/src/keyboards/java/be/scri/helpers/swedish/SVInterfaceVariables.kt b/app/src/keyboards/java/be/scri/helpers/swedish/SVInterfaceVariables.kt index e6387177..901e90c7 100644 --- a/app/src/keyboards/java/be/scri/helpers/swedish/SVInterfaceVariables.kt +++ b/app/src/keyboards/java/be/scri/helpers/swedish/SVInterfaceVariables.kt @@ -73,4 +73,5 @@ object SVInterfaceVariables { const val OBJECTS_EMOJI_HEADER = "Objekt" const val SYMBOLS_EMOJI_HEADER = "Symboler" const val FLAGS_EMOJI_HEADER = "Flaggor" + const val RECENTLY_USED_EMOJI_HEADER = "Nyligen Använda" } diff --git a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt index 4fe40d65..563a1656 100644 --- a/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt +++ b/app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt @@ -38,6 +38,7 @@ import be.scri.helpers.PreferencesHelper import be.scri.helpers.PreferencesHelper.getIsDarkModeOrNot import be.scri.helpers.english.ENInterfaceVariables.ALREADY_PLURAL_MSG import be.scri.helpers.getCategoryIconRes +import be.scri.helpers.getRecentEmojis import be.scri.helpers.parseRawEmojiSpecsFile import be.scri.models.ScribeState import be.scri.services.GeneralKeyboardIME @@ -878,8 +879,17 @@ class KeyboardUIManager( emojis: List, language: String, ) { + val recentEmojiChars = getRecentEmojis(context) + val recentEmojiData = recentEmojiChars.mapNotNull { char -> emojis.find { it.emoji == char } } + val emojiCategories = prepareEmojiCategories(emojis) - val emojiItems = prepareEmojiItems(emojiCategories) + val categoriesWithRecents = + if (recentEmojiData.isNotEmpty()) { + linkedMapOf("recently_used" to recentEmojiData) + emojiCategories + } else { + emojiCategories + } + val emojiItems = prepareEmojiItems(categoriesWithRecents) val categoryHeaders = (emojiCategoryHeaders["EN"] ?: emptyMap()) + (emojiCategoryHeaders[getLanguageAlias(language)] ?: emptyMap()) @@ -902,7 +912,7 @@ class KeyboardUIManager( listener.onEmojiSelected(emojiData.emoji) } - setupEmojiCategoryStrip(emojiCategories, emojiItems, emojiLayoutManager) + setupEmojiCategoryStrip(categoriesWithRecents, emojiItems, emojiLayoutManager) } /** diff --git a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt index 7b34094e..57ec1f8f 100644 --- a/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt +++ b/app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt @@ -68,6 +68,7 @@ import be.scri.helpers.SuggestionHandler import be.scri.helpers.clipboard.ClipboardHandler import be.scri.helpers.data.AutocompletionDataManager import be.scri.helpers.english.ENInterfaceVariables.ALREADY_PLURAL_MSG +import be.scri.helpers.recordRecentEmoji import be.scri.helpers.ui.KeyboardUIManager import be.scri.models.ScribeLanguage import be.scri.models.ScribeState @@ -872,6 +873,7 @@ abstract class GeneralKeyboardIME( override fun onEmojiSelected(emoji: String) { if (emoji.isNotEmpty()) { + recordRecentEmoji(this, emoji) insertEmoji(emoji, currentInputConnection, emojiKeywords, emojiMaxKeywordLength) } } diff --git a/app/src/main/java/be/scri/helpers/EmojiHelper.kt b/app/src/main/java/be/scri/helpers/EmojiHelper.kt index f2e035ba..fca1b156 100644 --- a/app/src/main/java/be/scri/helpers/EmojiHelper.kt +++ b/app/src/main/java/be/scri/helpers/EmojiHelper.kt @@ -94,5 +94,6 @@ fun getCategoryIconRes(category: String): Int = "objects" -> R.drawable.ic_emoji_objects "symbols" -> R.drawable.ic_emoji_symbols "flags" -> R.drawable.ic_emoji_flags + "recently_used" -> R.drawable.counter_clockwise_icon else -> R.drawable.ic_emoji_vector }