Make manual update notice smarter, add toggle to disable reminders

This commit is contained in:
Aleksandras Kostarevas 2024-04-29 20:38:51 -04:00
parent 147f711138
commit ecaf9df340
4 changed files with 69 additions and 29 deletions

View File

@ -58,8 +58,10 @@ import org.futo.inputmethod.latin.uix.actions.EmojiAction
import org.futo.inputmethod.latin.uix.settings.SettingsActivity
import org.futo.inputmethod.latin.uix.theme.ThemeOption
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
import org.futo.inputmethod.updates.DEFER_MANUAL_UPDATE_UNTIL
import org.futo.inputmethod.updates.MANUAL_UPDATE_PERIOD_MS
import org.futo.inputmethod.updates.DISABLE_UPDATE_REMINDER
import org.futo.inputmethod.updates.autoDeferManualUpdateIfNeeded
import org.futo.inputmethod.updates.deferManualUpdate
import org.futo.inputmethod.updates.isManualUpdateTimeExpired
import org.futo.inputmethod.updates.openManualUpdateCheck
import org.futo.inputmethod.updates.retrieveSavedLastUpdateCheckResult
import java.util.Locale
@ -435,35 +437,38 @@ class UixManager(private val latinIME: LatinIME) {
suspend fun showUpdateNoticeIfNeeded() {
if(!BuildConfig.UPDATE_CHECKING) return
autoDeferManualUpdateIfNeeded(latinIME)
val updateInfo = retrieveSavedLastUpdateCheckResult(latinIME)
if(updateInfo != null && updateInfo.isNewer()) {
numSuggestionsSinceNotice = 0
currentNotice.value = object : ImportantNotice {
@Composable
override fun getText(): String {
return "Update available: ${updateInfo.nextVersionString}"
}
override fun onDismiss(context: Context) {
currentNotice.value = null
}
override fun onOpen(context: Context) {
currentNotice.value = null
val intent = Intent(context, SettingsActivity::class.java)
intent.putExtra("navDest", "update")
if(context !is Activity) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if(!latinIME.getSetting(DISABLE_UPDATE_REMINDER)) {
numSuggestionsSinceNotice = 0
currentNotice.value = object : ImportantNotice {
@Composable
override fun getText(): String {
return "Update available: ${updateInfo.nextVersionString}"
}
context.startActivity(intent)
override fun onDismiss(context: Context) {
currentNotice.value = null
}
override fun onOpen(context: Context) {
currentNotice.value = null
val intent = Intent(context, SettingsActivity::class.java)
intent.putExtra("navDest", "update")
if (context !is Activity) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
}
}
}
} else {
val defermentTime = latinIME.getSetting(DEFER_MANUAL_UPDATE_UNTIL, Long.MAX_VALUE)
if(System.currentTimeMillis() > defermentTime) {
if(isManualUpdateTimeExpired(latinIME)) {
numSuggestionsSinceNotice = 0
currentNotice.value = object : ImportantNotice {
@Composable
@ -480,10 +485,7 @@ class UixManager(private val latinIME: LatinIME) {
context.openManualUpdateCheck()
runBlocking {
latinIME.setSetting(
DEFER_MANUAL_UPDATE_UNTIL,
System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS
)
deferManualUpdate(latinIME)
}
}
}

View File

@ -23,6 +23,7 @@ import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.latin.uix.settings.SettingToggleDataStore
import org.futo.inputmethod.latin.uix.settings.SettingToggleRaw
import org.futo.inputmethod.latin.uix.settings.useDataStore
import org.futo.inputmethod.updates.DISABLE_UPDATE_REMINDER
val IS_DEVELOPER = SettingsKey(booleanPreferencesKey("isDeveloperMode"), false)
@ -38,6 +39,8 @@ fun DeveloperScreen(navController: NavHostController = rememberNavController())
SettingToggleDataStore(title = "Developer mode", setting = IS_DEVELOPER)
SettingToggleDataStore(title = "Disable all update reminders", setting = DISABLE_UPDATE_REMINDER)
SettingToggleDataStore(
title = "Touch typing mode",
subtitle = "Hides all keys. Touch typists only! Recommended to disable emoji key and enable key borders",

View File

@ -17,15 +17,44 @@ import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.navigation.NavHostController
import org.futo.inputmethod.latin.BuildConfig
import org.futo.inputmethod.latin.uix.SettingsKey
import org.futo.inputmethod.latin.uix.getSetting
import org.futo.inputmethod.latin.uix.setSetting
import org.futo.inputmethod.latin.uix.settings.SettingItem
import org.futo.inputmethod.latin.uix.settings.useDataStore
val LAST_UPDATE_CHECK_RESULT = stringPreferencesKey("last_update_check_result")
val LAST_UPDATE_CHECK_FAILED = booleanPreferencesKey("last_update_check_failed")
val DISABLE_UPDATE_REMINDER = SettingsKey(booleanPreferencesKey("disable_update_reminder"), false)
val DEFER_MANUAL_UPDATE_UNTIL = longPreferencesKey("defer_manual_update_until")
const val MANUAL_UPDATE_PERIOD_MS = 1000L * 60L * 60L * 24L * 14L // Every two weeks
suspend fun deferManualUpdate(context: Context) {
context.setSetting(
DEFER_MANUAL_UPDATE_UNTIL,
System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS
)
}
suspend fun isManualUpdateTimeExpired(context: Context): Boolean {
if(context.getSetting(DISABLE_UPDATE_REMINDER)) {
return false
}
val defermentTime = context.getSetting(DEFER_MANUAL_UPDATE_UNTIL, Long.MAX_VALUE)
return (System.currentTimeMillis() > defermentTime)
}
val LAST_VERSION = longPreferencesKey("last_version")
suspend fun autoDeferManualUpdateIfNeeded(context: Context) {
if(context.getSetting(LAST_VERSION, 0L) != BuildConfig.VERSION_CODE.toLong()) {
context.setSetting(LAST_VERSION, BuildConfig.VERSION_CODE.toLong())
deferManualUpdate(context)
}
}
fun Context.openURI(uri: String, newTask: Boolean = false) {
try {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
@ -40,7 +69,11 @@ fun Context.openURI(uri: String, newTask: Boolean = false) {
}
fun Context.openManualUpdateCheck() {
openURI("https://voiceinput.futo.org/SuperSecretKeyboard/manual_update?version=${BuildConfig.VERSION_CODE}", newTask = true)
if(BuildConfig.IS_PLAYSTORE_BUILD) {
openURI("https://keyboard.futo.org/manual_update?version=${BuildConfig.VERSION_CODE}&build=playstore", newTask = true)
} else {
openURI("https://keyboard.futo.org/manual_update?version=${BuildConfig.VERSION_CODE}", newTask = true)
}
}
@Composable

View File

@ -92,6 +92,8 @@ suspend fun checkForUpdateAndSaveToPreferences(context: Context): Boolean {
}
suspend fun retrieveSavedLastUpdateCheckResult(context: Context): UpdateResult? {
if(!BuildConfig.UPDATE_CHECKING) return null
return UpdateResult.fromString(context.getSetting(LAST_UPDATE_CHECK_RESULT, ""))
}