Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions app/src/keyboards/java/be/scri/helpers/RecentEmojiHelper.kt
Original file line number Diff line number Diff line change
@@ -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<String> {
val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
return prefs.getString(KEY_RECENT, "")!!.split(",").filter { it.isNotBlank() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "Недавно Использованные"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
14 changes: 12 additions & 2 deletions app/src/keyboards/java/be/scri/helpers/ui/KeyboardUIManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -878,8 +879,17 @@ class KeyboardUIManager(
emojis: List<EmojiData>,
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())

Expand All @@ -902,7 +912,7 @@ class KeyboardUIManager(
listener.onEmojiSelected(emojiData.emoji)
}

setupEmojiCategoryStrip(emojiCategories, emojiItems, emojiLayoutManager)
setupEmojiCategoryStrip(categoriesWithRecents, emojiItems, emojiLayoutManager)
}

/**
Expand Down
2 changes: 2 additions & 0 deletions app/src/keyboards/java/be/scri/services/GeneralKeyboardIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -872,6 +873,7 @@ abstract class GeneralKeyboardIME(

override fun onEmojiSelected(emoji: String) {
if (emoji.isNotEmpty()) {
recordRecentEmoji(this, emoji)
insertEmoji(emoji, currentInputConnection, emojiKeywords, emojiMaxKeywordLength)
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/be/scri/helpers/EmojiHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading