mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Firebase] Implement handling app updates.
This commit is contained in:
parent
0fad12fea5
commit
ca60ceb2a7
@ -6,11 +6,13 @@ package pl.szczodrzynski.edziennik.data.firebase
|
||||
|
||||
import com.google.gson.JsonParser
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||
import pl.szczodrzynski.edziennik.data.api.task.PostNotifications
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Notification
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||
import pl.szczodrzynski.edziennik.sync.UpdateWorker
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
@ -34,6 +36,7 @@ class SzkolnyAppFirebase(val app: App, val profiles: List<Profile>, val message:
|
||||
message.data.getString("title") ?: "",
|
||||
message.data.getString("message") ?: ""
|
||||
)
|
||||
"appUpdate" -> UpdateWorker.runNow(app, app.gson.fromJson(message.data.get("update"), Update::class.java))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import kotlinx.coroutines.launch
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
@ -73,16 +74,19 @@ class UpdateWorker(val context: Context, val params: WorkerParameters) : Worker(
|
||||
WorkManager.getInstance(app).cancelAllWorkByTag(TAG)
|
||||
}
|
||||
|
||||
fun runNow(app: App) {
|
||||
fun runNow(app: App, overrideUpdate: Update? = null) {
|
||||
try {
|
||||
val api = SzkolnyApi(app)
|
||||
val response = api.getUpdate("beta")
|
||||
if (response?.success != true)
|
||||
return
|
||||
val updates = response.data
|
||||
if (updates?.isNotEmpty() != true)
|
||||
return
|
||||
val update = updates[0]
|
||||
val update = if (overrideUpdate == null) {
|
||||
val api = SzkolnyApi(app)
|
||||
val response = api.getUpdate("beta")
|
||||
if (response?.success != true)
|
||||
return
|
||||
val updates = response.data
|
||||
if (updates?.isNotEmpty() != true)
|
||||
return
|
||||
updates[0]
|
||||
}
|
||||
else overrideUpdate
|
||||
|
||||
app.config.update = update
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user