Add option for emoji suggestions

This commit is contained in:
Aleksandras Kostarevas 2024-03-13 16:50:53 -05:00
parent e209eefd48
commit e424f36529
3 changed files with 18 additions and 3 deletions

View File

@ -124,7 +124,7 @@ val SUGGESTION_BLACKLIST = SettingsKey(
default = setOf()
)
val BLACKLIST_BADWORDS = SettingsKey(
key = booleanPreferencesKey("blacklistBadWords"),
val SHOW_EMOJI_SUGGESTIONS = SettingsKey(
key = booleanPreferencesKey("suggestEmojis"),
default = true
)

View File

@ -9,8 +9,10 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.settings.Settings
import org.futo.inputmethod.latin.uix.SHOW_EMOJI_SUGGESTIONS
import org.futo.inputmethod.latin.uix.settings.ScreenTitle
import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore
import org.futo.inputmethod.latin.uix.settings.SettingToggleSharedPrefs
@Preview
@ -20,6 +22,11 @@ fun TypingScreen(navController: NavHostController = rememberNavController()) {
ScrollableList {
ScreenTitle("Typing Preferences", showBack = true, navController)
SettingToggleDataStore(
title = "Emoji Suggestions",
subtitle = "Suggest emojis while you're typing",
setting = SHOW_EMOJI_SUGGESTIONS
)
SettingToggleSharedPrefs(
title = stringResource(R.string.auto_cap),
subtitle = stringResource(R.string.auto_cap_summary),

View File

@ -29,6 +29,7 @@ import org.futo.inputmethod.latin.common.Constants
import org.futo.inputmethod.latin.inputlogic.InputLogic
import org.futo.inputmethod.latin.settings.Settings
import org.futo.inputmethod.latin.settings.SettingsValuesForSuggestion
import org.futo.inputmethod.latin.uix.SHOW_EMOJI_SUGGESTIONS
import org.futo.inputmethod.latin.uix.SettingsKey
import org.futo.inputmethod.latin.uix.USE_TRANSFORMER_FINETUNING
import org.futo.inputmethod.latin.uix.actions.PersistentEmojiState
@ -81,6 +82,7 @@ public class LanguageModelFacilitator(
private val userDictionary = UserDictionaryObserver(context)
private val emojiData = PersistentEmojiState()
private var shouldSuggestEmojis = SHOW_EMOJI_SUGGESTIONS.default
private var languageModel: LanguageModel? = null
data class PredictionInputValues(
val composedData: ComposedData,
@ -267,7 +269,7 @@ public class LanguageModelFacilitator(
}
}
if(values.composedData.mTypedWord.isNotEmpty()) {
if(values.composedData.mTypedWord.isNotEmpty() && shouldSuggestEmojis) {
(getEmojiCandidate(values.composedData.mTypedWord)
?: maxWord?.let { getEmojiCandidate(it.mWord) }
?: maxWordDict?.let { getEmojiCandidate(it.mWord) })?.let {
@ -348,6 +350,12 @@ public class LanguageModelFacilitator(
emojiData.loadEmojis(context)
}
launch {
withContext(Dispatchers.Default) {
context.getSettingFlow(SHOW_EMOJI_SUGGESTIONS).collect { shouldSuggestEmojis = it }
}
}
scheduleTrainingWorkerBackground(context)
}