mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Make manual update notice smarter, add toggle to disable reminders
This commit is contained in:
parent
147f711138
commit
ecaf9df340
@ -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.settings.SettingsActivity
|
||||||
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
||||||
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
||||||
import org.futo.inputmethod.updates.DEFER_MANUAL_UPDATE_UNTIL
|
import org.futo.inputmethod.updates.DISABLE_UPDATE_REMINDER
|
||||||
import org.futo.inputmethod.updates.MANUAL_UPDATE_PERIOD_MS
|
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.openManualUpdateCheck
|
||||||
import org.futo.inputmethod.updates.retrieveSavedLastUpdateCheckResult
|
import org.futo.inputmethod.updates.retrieveSavedLastUpdateCheckResult
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -435,35 +437,38 @@ class UixManager(private val latinIME: LatinIME) {
|
|||||||
suspend fun showUpdateNoticeIfNeeded() {
|
suspend fun showUpdateNoticeIfNeeded() {
|
||||||
if(!BuildConfig.UPDATE_CHECKING) return
|
if(!BuildConfig.UPDATE_CHECKING) return
|
||||||
|
|
||||||
|
autoDeferManualUpdateIfNeeded(latinIME)
|
||||||
|
|
||||||
val updateInfo = retrieveSavedLastUpdateCheckResult(latinIME)
|
val updateInfo = retrieveSavedLastUpdateCheckResult(latinIME)
|
||||||
if(updateInfo != null && updateInfo.isNewer()) {
|
if(updateInfo != null && updateInfo.isNewer()) {
|
||||||
numSuggestionsSinceNotice = 0
|
if(!latinIME.getSetting(DISABLE_UPDATE_REMINDER)) {
|
||||||
currentNotice.value = object : ImportantNotice {
|
numSuggestionsSinceNotice = 0
|
||||||
@Composable
|
currentNotice.value = object : ImportantNotice {
|
||||||
override fun getText(): String {
|
@Composable
|
||||||
return "Update available: ${updateInfo.nextVersionString}"
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
} else {
|
||||||
val defermentTime = latinIME.getSetting(DEFER_MANUAL_UPDATE_UNTIL, Long.MAX_VALUE)
|
if(isManualUpdateTimeExpired(latinIME)) {
|
||||||
if(System.currentTimeMillis() > defermentTime) {
|
|
||||||
numSuggestionsSinceNotice = 0
|
numSuggestionsSinceNotice = 0
|
||||||
currentNotice.value = object : ImportantNotice {
|
currentNotice.value = object : ImportantNotice {
|
||||||
@Composable
|
@Composable
|
||||||
@ -480,10 +485,7 @@ class UixManager(private val latinIME: LatinIME) {
|
|||||||
context.openManualUpdateCheck()
|
context.openManualUpdateCheck()
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
latinIME.setSetting(
|
deferManualUpdate(latinIME)
|
||||||
DEFER_MANUAL_UPDATE_UNTIL,
|
|
||||||
System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.SettingToggleDataStore
|
||||||
import org.futo.inputmethod.latin.uix.settings.SettingToggleRaw
|
import org.futo.inputmethod.latin.uix.settings.SettingToggleRaw
|
||||||
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
||||||
|
import org.futo.inputmethod.updates.DISABLE_UPDATE_REMINDER
|
||||||
|
|
||||||
|
|
||||||
val IS_DEVELOPER = SettingsKey(booleanPreferencesKey("isDeveloperMode"), false)
|
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 = "Developer mode", setting = IS_DEVELOPER)
|
||||||
|
|
||||||
|
SettingToggleDataStore(title = "Disable all update reminders", setting = DISABLE_UPDATE_REMINDER)
|
||||||
|
|
||||||
SettingToggleDataStore(
|
SettingToggleDataStore(
|
||||||
title = "Touch typing mode",
|
title = "Touch typing mode",
|
||||||
subtitle = "Hides all keys. Touch typists only! Recommended to disable emoji key and enable key borders",
|
subtitle = "Hides all keys. Touch typists only! Recommended to disable emoji key and enable key borders",
|
||||||
|
@ -17,15 +17,44 @@ import androidx.datastore.preferences.core.longPreferencesKey
|
|||||||
import androidx.datastore.preferences.core.stringPreferencesKey
|
import androidx.datastore.preferences.core.stringPreferencesKey
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import org.futo.inputmethod.latin.BuildConfig
|
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.SettingItem
|
||||||
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
||||||
|
|
||||||
val LAST_UPDATE_CHECK_RESULT = stringPreferencesKey("last_update_check_result")
|
val LAST_UPDATE_CHECK_RESULT = stringPreferencesKey("last_update_check_result")
|
||||||
val LAST_UPDATE_CHECK_FAILED = booleanPreferencesKey("last_update_check_failed")
|
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")
|
val DEFER_MANUAL_UPDATE_UNTIL = longPreferencesKey("defer_manual_update_until")
|
||||||
const val MANUAL_UPDATE_PERIOD_MS = 1000L * 60L * 60L * 24L * 14L // Every two weeks
|
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) {
|
fun Context.openURI(uri: String, newTask: Boolean = false) {
|
||||||
try {
|
try {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri))
|
||||||
@ -40,7 +69,11 @@ fun Context.openURI(uri: String, newTask: Boolean = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Context.openManualUpdateCheck() {
|
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
|
@Composable
|
||||||
|
@ -92,6 +92,8 @@ suspend fun checkForUpdateAndSaveToPreferences(context: Context): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun retrieveSavedLastUpdateCheckResult(context: Context): UpdateResult? {
|
suspend fun retrieveSavedLastUpdateCheckResult(context: Context): UpdateResult? {
|
||||||
|
if(!BuildConfig.UPDATE_CHECKING) return null
|
||||||
|
|
||||||
return UpdateResult.fromString(context.getSetting(LAST_UPDATE_CHECK_RESULT, ""))
|
return UpdateResult.fromString(context.getSetting(LAST_UPDATE_CHECK_RESULT, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user