mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-22 22:44:45 +01:00
[API/Szkolny] Restrict AppSync to run only every 24 hours (if no WebPush needed).
This commit is contained in:
parent
54363ee919
commit
fc21d757c3
@ -100,6 +100,11 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
|
|||||||
get() { mWidgetConfigs = mWidgetConfigs ?: values.get("widgetConfigs", JsonObject()); return mWidgetConfigs ?: JsonObject() }
|
get() { mWidgetConfigs = mWidgetConfigs ?: values.get("widgetConfigs", JsonObject()); return mWidgetConfigs ?: JsonObject() }
|
||||||
set(value) { set("widgetConfigs", value); mWidgetConfigs = value }
|
set(value) { set("widgetConfigs", value); mWidgetConfigs = value }
|
||||||
|
|
||||||
|
private var mLastAppSync: Long? = null
|
||||||
|
var lastAppSync: Long
|
||||||
|
get() { mLastAppSync = mLastAppSync ?: values.get("lastAppSync", 0L); return mLastAppSync ?: 0L }
|
||||||
|
set(value) { set("lastAppSync", value); mLastAppSync = value }
|
||||||
|
|
||||||
private var rawEntries: List<ConfigEntry> = db.configDao().getAllNow()
|
private var rawEntries: List<ConfigEntry> = db.configDao().getAllNow()
|
||||||
private val profileConfigs: HashMap<Int, ProfileConfig> = hashMapOf()
|
private val profileConfigs: HashMap<Int, ProfileConfig> = hashMapOf()
|
||||||
init {
|
init {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.task
|
package pl.szczodrzynski.edziennik.data.api.task
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
|
import pl.szczodrzynski.edziennik.HOUR
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
|
||||||
@ -25,18 +26,30 @@ class SzkolnyTask(val app: App, val syncingProfiles: List<Profile>) : IApiTask(-
|
|||||||
|
|
||||||
internal fun run(taskCallback: EdziennikCallback) {
|
internal fun run(taskCallback: EdziennikCallback) {
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
val notifications = Notifications(app, notificationList, profiles)
|
|
||||||
// create all e-register data notifications
|
// create all e-register data notifications
|
||||||
|
val notifications = Notifications(app, notificationList, profiles)
|
||||||
notifications.run()
|
notifications.run()
|
||||||
|
|
||||||
|
val shouldAppSync = notificationList.isNotEmpty() || (System.currentTimeMillis() - app.config.lastAppSync > 24*HOUR*1000)
|
||||||
|
// do an AppSync every 24 hours, or if WebPush has a notification
|
||||||
|
if (shouldAppSync) {
|
||||||
// send notifications to web push, get shared events
|
// send notifications to web push, get shared events
|
||||||
AppSync(app, notificationList, profiles, api).run()
|
val addedEvents = AppSync(app, notificationList, profiles, api).run()
|
||||||
|
if (addedEvents > 0) {
|
||||||
// create notifications for shared events (not present before app sync)
|
// create notifications for shared events (not present before app sync)
|
||||||
notifications.sharedEventNotifications()
|
notifications.sharedEventNotifications()
|
||||||
|
}
|
||||||
|
app.config.lastAppSync = System.currentTimeMillis()
|
||||||
|
}
|
||||||
d(TAG, "Created ${notificationList.count()} notifications.")
|
d(TAG, "Created ${notificationList.count()} notifications.")
|
||||||
|
|
||||||
// update the database
|
// update the database
|
||||||
app.db.metadataDao().setAllNotified(true)
|
app.db.metadataDao().setAllNotified(true)
|
||||||
|
if (notificationList.isNotEmpty())
|
||||||
app.db.notificationDao().addAll(notificationList)
|
app.db.notificationDao().addAll(notificationList)
|
||||||
app.db.profileDao().setAllNotEmpty()
|
app.db.profileDao().setAllNotEmpty()
|
||||||
|
|
||||||
// post all notifications
|
// post all notifications
|
||||||
PostNotifications(app, notificationList)
|
PostNotifications(app, notificationList)
|
||||||
d(TAG, "SzkolnyTask: finished in ${System.currentTimeMillis()-startTime} ms.")
|
d(TAG, "SzkolnyTask: finished in ${System.currentTimeMillis()-startTime} ms.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user