mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 04:46:44 -06:00
[App] Enable nightly app updates, check every 12 hours
This commit is contained in:
parent
095403cc76
commit
58d9dec33c
@ -103,7 +103,7 @@ class BuildManager(val app: App) : CoroutineScope {
|
|||||||
else -> Update.Type.RELEASE
|
else -> Update.Type.RELEASE
|
||||||
}
|
}
|
||||||
|
|
||||||
val devModeEasy = (isDaily || isNightly || isDebug) && !App.devMode
|
val devModeEasy = (releaseType == Update.Type.NIGHTLY || isDebug) && !App.devMode
|
||||||
|
|
||||||
fun fetchInstalledTime() {
|
fun fetchInstalledTime() {
|
||||||
if (app.config.appInstalledTime != 0L)
|
if (app.config.appInstalledTime != 0L)
|
||||||
|
@ -30,6 +30,31 @@ class UpdateManager(val app: App) : CoroutineScope {
|
|||||||
override val coroutineContext: CoroutineContext
|
override val coroutineContext: CoroutineContext
|
||||||
get() = job + Dispatchers.Default
|
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].
|
* Check for updates on the specified [maxChannel].
|
||||||
* If the running build is of "more-unstable" type,
|
* 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
|
* @return [update] if it's a newer version, null otherwise
|
||||||
*/
|
*/
|
||||||
fun process(update: Update?, notify: Boolean): Update? {
|
fun process(update: Update?, notify: Boolean): Update? {
|
||||||
if (update == null || update.versionCode <= BuildConfig.VERSION_CODE) {
|
if (update == null || !isApplicable(update)) {
|
||||||
app.config.update = null
|
app.config.update = null
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import kotlinx.coroutines.*
|
|||||||
import pl.szczodrzynski.edziennik.*
|
import pl.szczodrzynski.edziennik.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||||
import pl.szczodrzynski.edziennik.ext.DAY
|
import pl.szczodrzynski.edziennik.ext.DAY
|
||||||
|
import pl.szczodrzynski.edziennik.ext.HOUR
|
||||||
import pl.szczodrzynski.edziennik.ext.formatDate
|
import pl.szczodrzynski.edziennik.ext.formatDate
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -41,7 +42,11 @@ class UpdateWorker(val context: Context, val params: WorkerParameters) : Worker(
|
|||||||
if (!app.config.sync.notifyAboutUpdates) {
|
if (!app.config.sync.notifyAboutUpdates) {
|
||||||
return
|
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
|
val syncAt = System.currentTimeMillis() + syncInterval*1000
|
||||||
Timber.d("Scheduling work at ${syncAt.formatDate()}")
|
Timber.d("Scheduling work at ${syncAt.formatDate()}")
|
||||||
|
@ -29,9 +29,10 @@ class SignatureInterceptor(val app: App) : Interceptor {
|
|||||||
return chain.proceed(
|
return chain.proceed(
|
||||||
request.newBuilder()
|
request.newBuilder()
|
||||||
.header("X-ApiKey", app.config.apiKeyCustom?.takeValue() ?: API_KEY)
|
.header("X-ApiKey", app.config.apiKeyCustom?.takeValue() ?: API_KEY)
|
||||||
.header("X-AppBuild", BuildConfig.BUILD_TYPE)
|
.header("X-AppBuild", app.buildManager.buildType)
|
||||||
.header("X-AppFlavor", BuildConfig.FLAVOR)
|
.header("X-AppFlavor", app.buildManager.buildFlavor)
|
||||||
.header("X-AppVersion", BuildConfig.VERSION_CODE.toString())
|
.header("X-AppVersion", BuildConfig.VERSION_CODE.toString())
|
||||||
|
.header("X-AppReleaseType", app.buildManager.releaseType.name.lowercase())
|
||||||
.header("X-DeviceId", app.deviceId)
|
.header("X-DeviceId", app.deviceId)
|
||||||
.header("X-Signature", sign(timestamp, body, url))
|
.header("X-Signature", sign(timestamp, body, url))
|
||||||
.header("X-Timestamp", timestamp.toString())
|
.header("X-Timestamp", timestamp.toString())
|
||||||
|
@ -46,6 +46,6 @@ class UpdateAvailableDialog(
|
|||||||
|
|
||||||
override suspend fun onBeforeShow(): Boolean {
|
override suspend fun onBeforeShow(): Boolean {
|
||||||
// show only if app is older than available
|
// show only if app is older than available
|
||||||
return update == null || update.versionCode > BuildConfig.VERSION_CODE
|
return update == null || app.updateManager.isApplicable(update)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ class UpdateProgressDialog(
|
|||||||
override fun getNegativeButtonText() = R.string.cancel
|
override fun getNegativeButtonText() = R.string.cancel
|
||||||
|
|
||||||
override suspend fun onShow() {
|
override suspend fun onShow() {
|
||||||
EventBus.getDefault().register(this)
|
|
||||||
b.update = update
|
b.update = update
|
||||||
b.progress.progress = 0
|
b.progress.progress = 0
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, MainActivity>(
|
|||||||
|
|
||||||
val status = app.availabilityManager.check(app.profile, cacheOnly = true)?.status
|
val status = app.availabilityManager.check(app.profile, cacheOnly = true)?.status
|
||||||
val update = app.config.update
|
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))
|
items.add(0, HomeAvailabilityCard(102, app, activity, this, app.profile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class HomeAvailabilityCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// show "update available" when available OR version too old for the register
|
// 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.homeAvailabilityTitle.setText(R.string.home_availability_title)
|
||||||
b.homeAvailabilityText.setText(R.string.home_availability_text, update.versionName)
|
b.homeAvailabilityText.setText(R.string.home_availability_text, update.versionName)
|
||||||
b.homeAvailabilityUpdate.isVisible = !app.buildManager.isPlayRelease
|
b.homeAvailabilityUpdate.isVisible = !app.buildManager.isPlayRelease
|
||||||
@ -94,9 +94,7 @@ class HomeAvailabilityCard(
|
|||||||
}
|
}
|
||||||
|
|
||||||
b.homeAvailabilityUpdate.onClick {
|
b.homeAvailabilityUpdate.onClick {
|
||||||
if (update == null)
|
if (update == null || update.isOnGooglePlay)
|
||||||
return@onClick
|
|
||||||
if (update.isOnGooglePlay)
|
|
||||||
Utils.openGooglePlay(activity)
|
Utils.openGooglePlay(activity)
|
||||||
else
|
else
|
||||||
activity.startService(Intent(app, UpdateDownloaderService::class.java))
|
activity.startService(Intent(app, UpdateDownloaderService::class.java))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user