From ce921b9b85620beab45358c606ee368df99350f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 5 Oct 2019 13:12:35 +0200 Subject: [PATCH] [APIv2] Update endpoint timer features --- .../edziennik/api/v2/LoginMethods.kt | 2 +- .../edziennik/api/v2/librus/Librus.kt | 3 +-- .../edziennik/api/v2/models/Data.kt | 18 ++++++++++-------- .../data/db/modules/api/EndpointTimer.kt | 12 +++++++----- app/src/main/res/values/strings.xml | 1 + 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/LoginMethods.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/LoginMethods.kt index f7a90179..0b700a88 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/LoginMethods.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/LoginMethods.kt @@ -10,7 +10,7 @@ import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLoginMessages import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLoginSynergia import pl.szczodrzynski.edziennik.api.v2.models.LoginMethod -val SYNERGIA_API_ENABLED = "true".toBoolean() +const val SYNERGIA_API_ENABLED = true const val LOGIN_TYPE_MOBIDZIENNIK = 1 const val LOGIN_TYPE_LIBRUS = 2 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt index 977c9415..012b4bac 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/Librus.kt @@ -91,8 +91,7 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va .singleOrNull { it.endpointId == endpoint.first } ?: EndpointTimer(data.profile?.id ?: -1, endpoint.first)) .let { timer -> if (timer.nextSync == SYNC_ALWAYS || - (timer.nextSync == SYNC_IF_EXPLICIT && timer.viewId == viewId) || - (timer.nextSync == SYNC_IF_EXPLICIT_OR_ALL && viewId == null) || + (timer.viewId == viewId) || (timer.nextSync != SYNC_NEVER && timer.nextSync < timestamp)) { data.targetEndpointIds.add(endpoint.first) requiredLoginMethods.add(endpoint.second) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt index d0c9de40..098375a4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt @@ -234,17 +234,19 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) db.metadataDao().setSeen(messageMetadataList) } - fun setSyncNext(endpointId: Int, syncIn: Long, viewId: Int? = null, syncIfAll: Boolean = false) { + fun setSyncNext(endpointId: Int, syncIn: Long? = null, viewId: Int? = null) { EndpointTimer(profile?.id ?: -1, endpointId).apply { syncedNow() - if (syncIn < 10) { - nextSync = syncIn - } - else { - syncIn(syncIn) - if (viewId != null) - syncWhenView(viewId, syncIfAll) + + if (syncIn != null) { + if (syncIn < 10) + nextSync = syncIn + else + syncIn(syncIn) } + if (viewId != null) + syncWhenView(viewId) + endpointTimers.add(this) } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/api/EndpointTimer.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/api/EndpointTimer.kt index 2cbd7c34..24344462 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/api/EndpointTimer.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/api/EndpointTimer.kt @@ -9,8 +9,6 @@ import androidx.room.Entity const val SYNC_NEVER = 0L const val SYNC_ALWAYS = 1L -const val SYNC_IF_EXPLICIT = 2L -const val SYNC_IF_EXPLICIT_OR_ALL = 3L @Entity(tableName = "endpointTimers", primaryKeys = ["profileId", "endpointId"]) @@ -47,16 +45,20 @@ data class EndpointTimer ( */ fun syncIn(nextSyncIn: Long): EndpointTimer { nextSync = System.currentTimeMillis() + nextSyncIn*1000 - viewId = null return this } /** * Set this timer to sync only if [viewId] is the only * selected feature during the current process. + * + * [viewId] may be [DRAWER_ITEM_HOME] to sync only if all features are selected. */ - fun syncWhenView(viewId: Int, syncIfAll: Boolean = false): EndpointTimer { - nextSync = if (syncIfAll) SYNC_IF_EXPLICIT_OR_ALL else SYNC_IF_EXPLICIT + fun syncWhenView(viewId: Int): EndpointTimer { + // set to never sync if nextSync is not already a timestamp + if (nextSync < 10) { + this.nextSync = SYNC_NEVER + } this.viewId = viewId return this } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be2863e0..bcdd253f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -925,4 +925,5 @@ Pobieranie komentarzy ocen Pokazuj nieobecności nauczycieli w Terminarzu Pobieram informacje o szkole... + Pobieranie ocen ucznia...