[APIv2] Update endpoint timer features

This commit is contained in:
Kuba Szczodrzyński 2019-10-05 13:12:35 +02:00
parent bb0a366ef1
commit ce921b9b85
5 changed files with 20 additions and 16 deletions

View File

@ -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.librus.login.LibrusLoginSynergia
import pl.szczodrzynski.edziennik.api.v2.models.LoginMethod 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_MOBIDZIENNIK = 1
const val LOGIN_TYPE_LIBRUS = 2 const val LOGIN_TYPE_LIBRUS = 2

View File

@ -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)) .singleOrNull { it.endpointId == endpoint.first } ?: EndpointTimer(data.profile?.id ?: -1, endpoint.first))
.let { timer -> .let { timer ->
if (timer.nextSync == SYNC_ALWAYS || if (timer.nextSync == SYNC_ALWAYS ||
(timer.nextSync == SYNC_IF_EXPLICIT && timer.viewId == viewId) || (timer.viewId == viewId) ||
(timer.nextSync == SYNC_IF_EXPLICIT_OR_ALL && viewId == null) ||
(timer.nextSync != SYNC_NEVER && timer.nextSync < timestamp)) { (timer.nextSync != SYNC_NEVER && timer.nextSync < timestamp)) {
data.targetEndpointIds.add(endpoint.first) data.targetEndpointIds.add(endpoint.first)
requiredLoginMethods.add(endpoint.second) requiredLoginMethods.add(endpoint.second)

View File

@ -234,17 +234,19 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
db.metadataDao().setSeen(messageMetadataList) 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 { EndpointTimer(profile?.id ?: -1, endpointId).apply {
syncedNow() syncedNow()
if (syncIn < 10) {
nextSync = syncIn if (syncIn != null) {
} if (syncIn < 10)
else { nextSync = syncIn
syncIn(syncIn) else
if (viewId != null) syncIn(syncIn)
syncWhenView(viewId, syncIfAll)
} }
if (viewId != null)
syncWhenView(viewId)
endpointTimers.add(this) endpointTimers.add(this)
} }
} }

View File

@ -9,8 +9,6 @@ import androidx.room.Entity
const val SYNC_NEVER = 0L const val SYNC_NEVER = 0L
const val SYNC_ALWAYS = 1L const val SYNC_ALWAYS = 1L
const val SYNC_IF_EXPLICIT = 2L
const val SYNC_IF_EXPLICIT_OR_ALL = 3L
@Entity(tableName = "endpointTimers", @Entity(tableName = "endpointTimers",
primaryKeys = ["profileId", "endpointId"]) primaryKeys = ["profileId", "endpointId"])
@ -47,16 +45,20 @@ data class EndpointTimer (
*/ */
fun syncIn(nextSyncIn: Long): EndpointTimer { fun syncIn(nextSyncIn: Long): EndpointTimer {
nextSync = System.currentTimeMillis() + nextSyncIn*1000 nextSync = System.currentTimeMillis() + nextSyncIn*1000
viewId = null
return this return this
} }
/** /**
* Set this timer to sync only if [viewId] is the only * Set this timer to sync only if [viewId] is the only
* selected feature during the current process. * 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 { fun syncWhenView(viewId: Int): EndpointTimer {
nextSync = if (syncIfAll) SYNC_IF_EXPLICIT_OR_ALL else SYNC_IF_EXPLICIT // set to never sync if nextSync is not already a timestamp
if (nextSync < 10) {
this.nextSync = SYNC_NEVER
}
this.viewId = viewId this.viewId = viewId
return this return this
} }

View File

@ -925,4 +925,5 @@
<string name="sync_action_syncing_grade_comments">Pobieranie komentarzy ocen</string> <string name="sync_action_syncing_grade_comments">Pobieranie komentarzy ocen</string>
<string name="settings_register_show_teacher_absences_text">Pokazuj nieobecności nauczycieli w Terminarzu</string> <string name="settings_register_show_teacher_absences_text">Pokazuj nieobecności nauczycieli w Terminarzu</string>
<string name="edziennik_progress_endpoint_school_info">Pobieram informacje o szkole...</string> <string name="edziennik_progress_endpoint_school_info">Pobieram informacje o szkole...</string>
<string name="edziennik_progress_endpoint_grades">Pobieranie ocen ucznia...</string>
</resources> </resources>