mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-22 06:24:44 +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() }
|
||||
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 val profileConfigs: HashMap<Int, ProfileConfig> = hashMapOf()
|
||||
init {
|
||||
@ -125,4 +130,4 @@ class Config(val db: AppDb) : CoroutineScope, AbstractConfig {
|
||||
db.configDao().add(ConfigEntry(-1, key, value))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.task
|
||||
|
||||
import pl.szczodrzynski.edziennik.App
|
||||
import pl.szczodrzynski.edziennik.HOUR
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||
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) {
|
||||
val startTime = System.currentTimeMillis()
|
||||
val notifications = Notifications(app, notificationList, profiles)
|
||||
|
||||
// create all e-register data notifications
|
||||
val notifications = Notifications(app, notificationList, profiles)
|
||||
notifications.run()
|
||||
// send notifications to web push, get shared events
|
||||
AppSync(app, notificationList, profiles, api).run()
|
||||
// create notifications for shared events (not present before app sync)
|
||||
notifications.sharedEventNotifications()
|
||||
|
||||
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
|
||||
val addedEvents = AppSync(app, notificationList, profiles, api).run()
|
||||
if (addedEvents > 0) {
|
||||
// create notifications for shared events (not present before app sync)
|
||||
notifications.sharedEventNotifications()
|
||||
}
|
||||
app.config.lastAppSync = System.currentTimeMillis()
|
||||
}
|
||||
d(TAG, "Created ${notificationList.count()} notifications.")
|
||||
|
||||
// update the database
|
||||
app.db.metadataDao().setAllNotified(true)
|
||||
app.db.notificationDao().addAll(notificationList)
|
||||
if (notificationList.isNotEmpty())
|
||||
app.db.notificationDao().addAll(notificationList)
|
||||
app.db.profileDao().setAllNotEmpty()
|
||||
|
||||
// post all notifications
|
||||
PostNotifications(app, notificationList)
|
||||
d(TAG, "SzkolnyTask: finished in ${System.currentTimeMillis()-startTime} ms.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user