diff --git a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt index 5932ec948..6bf142e8f 100644 --- a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt +++ b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt @@ -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) } } } diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt index bffe53b80..997dba50c 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt @@ -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", diff --git a/java/src/org/futo/inputmethod/updates/Update.kt b/java/src/org/futo/inputmethod/updates/Update.kt index ce87e1d6a..6ccae498b 100644 --- a/java/src/org/futo/inputmethod/updates/Update.kt +++ b/java/src/org/futo/inputmethod/updates/Update.kt @@ -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 diff --git a/java/src/org/futo/inputmethod/updates/UpdateChecking.kt b/java/src/org/futo/inputmethod/updates/UpdateChecking.kt index a162fbd8f..19fdfd26e 100644 --- a/java/src/org/futo/inputmethod/updates/UpdateChecking.kt +++ b/java/src/org/futo/inputmethod/updates/UpdateChecking.kt @@ -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, "")) }