forked from github/szkolny
[APIv2] Update endpoint timer features
This commit is contained in:
parent
bb0a366ef1
commit
ce921b9b85
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
||||
if (syncIn != null) {
|
||||
if (syncIn < 10)
|
||||
nextSync = syncIn
|
||||
}
|
||||
else {
|
||||
else
|
||||
syncIn(syncIn)
|
||||
if (viewId != null)
|
||||
syncWhenView(viewId, syncIfAll)
|
||||
}
|
||||
if (viewId != null)
|
||||
syncWhenView(viewId)
|
||||
|
||||
endpointTimers.add(this)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -925,4 +925,5 @@
|
||||
<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="edziennik_progress_endpoint_school_info">Pobieram informacje o szkole...</string>
|
||||
<string name="edziennik_progress_endpoint_grades">Pobieranie ocen ucznia...</string>
|
||||
</resources>
|
||||
|
Loading…
x
Reference in New Issue
Block a user