Check for updates when settings is launched, show update more often and auto-dismiss it

This commit is contained in:
Aleksandras Kostarevas 2024-03-15 10:15:07 -05:00
parent 91a8e7eb92
commit da9abecce4
3 changed files with 18 additions and 0 deletions

View File

@ -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) {

View File

@ -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<ImportantNotice?> = 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)
}

View File

@ -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 {