mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-19 05:16:56 -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 com.google.gson.JsonParser
|
||||||
import pl.szczodrzynski.edziennik.*
|
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.api.task.PostNotifications
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Notification
|
import pl.szczodrzynski.edziennik.data.db.entity.Notification
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
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.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
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("title") ?: "",
|
||||||
message.data.getString("message") ?: ""
|
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.*
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.szkolny.response.Update
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
@ -73,8 +74,9 @@ class UpdateWorker(val context: Context, val params: WorkerParameters) : Worker(
|
|||||||
WorkManager.getInstance(app).cancelAllWorkByTag(TAG)
|
WorkManager.getInstance(app).cancelAllWorkByTag(TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runNow(app: App) {
|
fun runNow(app: App, overrideUpdate: Update? = null) {
|
||||||
try {
|
try {
|
||||||
|
val update = if (overrideUpdate == null) {
|
||||||
val api = SzkolnyApi(app)
|
val api = SzkolnyApi(app)
|
||||||
val response = api.getUpdate("beta")
|
val response = api.getUpdate("beta")
|
||||||
if (response?.success != true)
|
if (response?.success != true)
|
||||||
@ -82,7 +84,9 @@ class UpdateWorker(val context: Context, val params: WorkerParameters) : Worker(
|
|||||||
val updates = response.data
|
val updates = response.data
|
||||||
if (updates?.isNotEmpty() != true)
|
if (updates?.isNotEmpty() != true)
|
||||||
return
|
return
|
||||||
val update = updates[0]
|
updates[0]
|
||||||
|
}
|
||||||
|
else overrideUpdate
|
||||||
|
|
||||||
app.config.update = update
|
app.config.update = update
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user