[App] Enable nightly app updates, check every 12 hours
Some checks failed
Schedule/dispatch / Build nightly release (APK) (push) Has been skipped
Schedule/dispatch / Check new changes (push) Failing after 26s

This commit is contained in:
Kuba Szczodrzyński 2024-07-08 20:48:39 +02:00
parent 095403cc76
commit 58d9dec33c
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
8 changed files with 40 additions and 12 deletions

View File

@ -103,7 +103,7 @@ class BuildManager(val app: App) : CoroutineScope {
else -> Update.Type.RELEASE
}
val devModeEasy = (isDaily || isNightly || isDebug) && !App.devMode
val devModeEasy = (releaseType == Update.Type.NIGHTLY || isDebug) && !App.devMode
fun fetchInstalledTime() {
if (app.config.appInstalledTime != 0L)

View File

@ -30,6 +30,31 @@ class UpdateManager(val app: App) : CoroutineScope {
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Default
fun isApplicable(update: Update): Boolean {
if (app.buildManager.isDebug)
return false // no updates on debug
if (update.versionCode > BuildConfig.VERSION_CODE)
return true
if (update.versionCode < BuildConfig.VERSION_CODE)
return false
if (update.versionName == BuildConfig.VERSION_NAME)
return false
if (app.buildManager.isNightly || app.buildManager.isDaily) {
val updateDate =
update.versionName
.replace("""\D""".toRegex(), "")
.padEnd(12, '9')
.toIntOrNull() ?: return false
val buildDate =
BuildConfig.VERSION_NAME
.replace("""\D""".toRegex(), "")
.padEnd(12, '9')
.toIntOrNull() ?: return false
return updateDate > buildDate
}
return false
}
/**
* Check for updates on the specified [maxChannel].
* If the running build is of "more-unstable" type,
@ -75,7 +100,7 @@ class UpdateManager(val app: App) : CoroutineScope {
* @return [update] if it's a newer version, null otherwise
*/
fun process(update: Update?, notify: Boolean): Update? {
if (update == null || update.versionCode <= BuildConfig.VERSION_CODE) {
if (update == null || !isApplicable(update)) {
app.config.update = null
return null
}

View File

@ -11,6 +11,7 @@ import kotlinx.coroutines.*
import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
import pl.szczodrzynski.edziennik.ext.DAY
import pl.szczodrzynski.edziennik.ext.HOUR
import pl.szczodrzynski.edziennik.ext.formatDate
import pl.szczodrzynski.edziennik.utils.Utils
import timber.log.Timber
@ -41,7 +42,11 @@ class UpdateWorker(val context: Context, val params: WorkerParameters) : Worker(
if (!app.config.sync.notifyAboutUpdates) {
return
}
val syncInterval = 4 * DAY;
val syncInterval =
if (app.buildManager.releaseType == Update.Type.NIGHTLY)
12 * HOUR
else
4 * DAY
val syncAt = System.currentTimeMillis() + syncInterval*1000
Timber.d("Scheduling work at ${syncAt.formatDate()}")

View File

@ -29,9 +29,10 @@ class SignatureInterceptor(val app: App) : Interceptor {
return chain.proceed(
request.newBuilder()
.header("X-ApiKey", app.config.apiKeyCustom?.takeValue() ?: API_KEY)
.header("X-AppBuild", BuildConfig.BUILD_TYPE)
.header("X-AppFlavor", BuildConfig.FLAVOR)
.header("X-AppBuild", app.buildManager.buildType)
.header("X-AppFlavor", app.buildManager.buildFlavor)
.header("X-AppVersion", BuildConfig.VERSION_CODE.toString())
.header("X-AppReleaseType", app.buildManager.releaseType.name.lowercase())
.header("X-DeviceId", app.deviceId)
.header("X-Signature", sign(timestamp, body, url))
.header("X-Timestamp", timestamp.toString())

View File

@ -46,6 +46,6 @@ class UpdateAvailableDialog(
override suspend fun onBeforeShow(): Boolean {
// show only if app is older than available
return update == null || update.versionCode > BuildConfig.VERSION_CODE
return update == null || app.updateManager.isApplicable(update)
}
}

View File

@ -35,7 +35,6 @@ class UpdateProgressDialog(
override fun getNegativeButtonText() = R.string.cancel
override suspend fun onShow() {
EventBus.getDefault().register(this)
b.update = update
b.progress.progress = 0

View File

@ -164,7 +164,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, MainActivity>(
val status = app.availabilityManager.check(app.profile, cacheOnly = true)?.status
val update = app.config.update
if (update != null && update.versionCode > BuildConfig.VERSION_CODE || status?.userMessage != null) {
if (update != null && app.updateManager.isApplicable(update) || status?.userMessage != null) {
items.add(0, HomeAvailabilityCard(102, app, activity, this, app.profile))
}

View File

@ -80,7 +80,7 @@ class HomeAvailabilityCard(
}
}
// show "update available" when available OR version too old for the register
else if (update != null && update.versionCode > BuildConfig.VERSION_CODE) {
else if (update != null && app.updateManager.isApplicable(update)) {
b.homeAvailabilityTitle.setText(R.string.home_availability_title)
b.homeAvailabilityText.setText(R.string.home_availability_text, update.versionName)
b.homeAvailabilityUpdate.isVisible = !app.buildManager.isPlayRelease
@ -94,9 +94,7 @@ class HomeAvailabilityCard(
}
b.homeAvailabilityUpdate.onClick {
if (update == null)
return@onClick
if (update.isOnGooglePlay)
if (update == null || update.isOnGooglePlay)
Utils.openGooglePlay(activity)
else
activity.startService(Intent(app, UpdateDownloaderService::class.java))