From da9abecce47063379ed3d651b7a9c6ce84ec434f Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Fri, 15 Mar 2024 10:15:07 -0500 Subject: [PATCH] Check for updates when settings is launched, show update more often and auto-dismiss it --- java/src/org/futo/inputmethod/latin/LatinIME.kt | 1 + .../src/org/futo/inputmethod/latin/uix/UixManager.kt | 12 ++++++++++++ .../latin/uix/settings/SettingsActivity.kt | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index 1c83c1682..a54dddee9 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -332,6 +332,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save super.onStartInputView(info, restarting) latinIMELegacy.onStartInputView(info, restarting) + lifecycleScope.launch { uixManager.showUpdateNoticeIfNeeded() } } override fun onFinishInputView(finishingInput: Boolean) { diff --git a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt index 3c1530317..ba514fd7e 100644 --- a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt +++ b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt @@ -168,6 +168,8 @@ class UixManager(private val latinIME: LatinIME) { private val keyboardManagerForAction = UixActionKeyboardManager(this, latinIME) private var mainKeyboardHidden = false + + private var numSuggestionsSinceNotice = 0 private var currentNotice: MutableState = mutableStateOf(null) var currWindowActionWindow: ActionWindow? = null @@ -395,6 +397,7 @@ class UixManager(private val latinIME: LatinIME) { suspend fun showUpdateNoticeIfNeeded() { val updateInfo = retrieveSavedLastUpdateCheckResult(latinIME) if(updateInfo != null && updateInfo.isNewer()) { + numSuggestionsSinceNotice = 0 currentNotice.value = object : ImportantNotice { @Composable override fun getText(): String { @@ -474,10 +477,19 @@ class UixManager(private val latinIME: LatinIME) { fun setSuggestions(suggestedWords: SuggestedWords?, rtlSubtype: Boolean) { this.suggestedWords = suggestedWords setContent() + + if(currentNotice.value != null) { + numSuggestionsSinceNotice += 1 + if(numSuggestionsSinceNotice > 4) { + currentNotice.value?.onDismiss(latinIME) + } + } } @RequiresApi(Build.VERSION_CODES.R) fun onInlineSuggestionsResponse(response: InlineSuggestionsResponse): Boolean { + currentNotice.value?.onDismiss(latinIME) + inlineSuggestions = response.inlineSuggestions.map { latinIME.inflateInlineSuggestion(it) } diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/SettingsActivity.kt b/java/src/org/futo/inputmethod/latin/uix/settings/SettingsActivity.kt index d6e7a3851..13c4d3731 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/SettingsActivity.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/SettingsActivity.kt @@ -42,6 +42,7 @@ import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme import org.futo.inputmethod.latin.uix.urlEncode import org.futo.inputmethod.latin.xlm.ModelPaths +import org.futo.inputmethod.updates.checkForUpdateAndSaveToPreferences import java.io.File private fun Context.isInputMethodEnabled(): Boolean { @@ -166,6 +167,10 @@ class SettingsActivity : ComponentActivity() { } } + lifecycleScope.launch { + checkForUpdateAndSaveToPreferences(applicationContext) + } + deferGetSetting(THEME_KEY) { val themeOptionFromSettings = ThemeOptions[it] val themeOption = when {