mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[APIv2] Add Feature priority setter and shouldSync method.
This commit is contained in:
parent
0875d13737
commit
b0fb87acdb
@ -13,6 +13,7 @@ import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusData
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusData
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLogin
|
import pl.szczodrzynski.edziennik.api.v2.librus.login.LibrusLogin
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librusLoginMethods
|
import pl.szczodrzynski.edziennik.api.v2.librusLoginMethods
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.MobidziennikFeatures
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.*
|
import pl.szczodrzynski.edziennik.data.db.modules.api.*
|
||||||
@ -63,14 +64,15 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
data.targetEndpointIds.clear()
|
data.targetEndpointIds.clear()
|
||||||
data.targetLoginMethodIds.clear()
|
data.targetLoginMethodIds.clear()
|
||||||
|
|
||||||
// get all endpoints for every feature, only if possible to login
|
// get all endpoints for every feature, only if possible to login and possible/necessary to sync
|
||||||
for (featureId in featureIds) {
|
for (featureId in featureIds) {
|
||||||
LibrusFeatures.filter {
|
LibrusFeatures.filter {
|
||||||
it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods)
|
it.featureId == featureId // feature ID matches
|
||||||
}
|
&& possibleLoginMethods.containsAll(it.requiredLoginMethods) // is possible to login
|
||||||
.let {
|
&& it.shouldSync?.invoke(profile, loginStore) ?: true // is necessary/possible to sync
|
||||||
endpointList.addAll(it)
|
}.let {
|
||||||
}
|
endpointList.addAll(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val timestamp = System.currentTimeMillis()
|
val timestamp = System.currentTimeMillis()
|
||||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.App
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.*
|
import pl.szczodrzynski.edziennik.api.v2.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.LibrusFeatures
|
||||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikData
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikData
|
||||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.login.MobidziennikLogin
|
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.login.MobidziennikLogin
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
@ -64,14 +65,15 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
data.targetEndpointIds.clear()
|
data.targetEndpointIds.clear()
|
||||||
data.targetLoginMethodIds.clear()
|
data.targetLoginMethodIds.clear()
|
||||||
|
|
||||||
// get all endpoints for every feature, only if possible to login
|
// get all endpoints for every feature, only if possible to login and possible/necessary to sync
|
||||||
for (featureId in featureIds) {
|
for (featureId in featureIds) {
|
||||||
MobidziennikFeatures.filter {
|
MobidziennikFeatures.filter {
|
||||||
it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods)
|
it.featureId == featureId // feature ID matches
|
||||||
|
&& possibleLoginMethods.containsAll(it.requiredLoginMethods) // is possible to login
|
||||||
|
&& it.shouldSync?.invoke(profile, loginStore) ?: true // is necessary/possible to sync
|
||||||
|
}.let {
|
||||||
|
endpointList.addAll(it)
|
||||||
}
|
}
|
||||||
.let {
|
|
||||||
endpointList.addAll(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val timestamp = System.currentTimeMillis()
|
val timestamp = System.currentTimeMillis()
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package pl.szczodrzynski.edziennik.api.v2.models
|
package pl.szczodrzynski.edziennik.api.v2.models
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Endpoint descriptor class.
|
* A Endpoint descriptor class.
|
||||||
*
|
*
|
||||||
@ -20,4 +23,14 @@ data class Feature(
|
|||||||
val requiredLoginMethods: List<Int>
|
val requiredLoginMethods: List<Int>
|
||||||
) {
|
) {
|
||||||
var priority = endpointIds.size
|
var priority = endpointIds.size
|
||||||
|
fun withPriority(priority: Int): Feature {
|
||||||
|
this.priority = priority
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
var shouldSync: ((Profile?, LoginStore) -> Boolean)? = null
|
||||||
|
fun withShouldSync(shouldSync: ((Profile?, LoginStore) -> Boolean)?): Feature {
|
||||||
|
this.shouldSync = shouldSync
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
@ -10,11 +10,13 @@ import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_NOT_NEEDED
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_NOT_NEEDED
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.LibrusFeatures
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
||||||
import pl.szczodrzynski.edziennik.api.v2.template.data.TemplateData
|
import pl.szczodrzynski.edziennik.api.v2.template.data.TemplateData
|
||||||
import pl.szczodrzynski.edziennik.api.v2.template.login.TemplateLogin
|
import pl.szczodrzynski.edziennik.api.v2.template.login.TemplateLogin
|
||||||
import pl.szczodrzynski.edziennik.api.v2.templateLoginMethods
|
import pl.szczodrzynski.edziennik.api.v2.templateLoginMethods
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.VulcanFeatures
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.EndpointTimer
|
import pl.szczodrzynski.edziennik.data.db.modules.api.EndpointTimer
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_NEVER
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_NEVER
|
||||||
@ -66,14 +68,15 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
data.targetEndpointIds.clear()
|
data.targetEndpointIds.clear()
|
||||||
data.targetLoginMethodIds.clear()
|
data.targetLoginMethodIds.clear()
|
||||||
|
|
||||||
// get all endpoints for every feature, only if possible to login
|
// get all endpoints for every feature, only if possible to login and possible/necessary to sync
|
||||||
for (featureId in featureIds) {
|
for (featureId in featureIds) {
|
||||||
TemplateFeatures.filter {
|
VulcanFeatures.filter {
|
||||||
it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods)
|
it.featureId == featureId // feature ID matches
|
||||||
|
&& possibleLoginMethods.containsAll(it.requiredLoginMethods) // is possible to login
|
||||||
|
&& it.shouldSync?.invoke(profile, loginStore) ?: true // is necessary/possible to sync
|
||||||
|
}.let {
|
||||||
|
endpointList.addAll(it)
|
||||||
}
|
}
|
||||||
.let {
|
|
||||||
endpointList.addAll(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val timestamp = System.currentTimeMillis()
|
val timestamp = System.currentTimeMillis()
|
||||||
|
@ -10,6 +10,7 @@ import pl.szczodrzynski.edziennik.api.v2.CODE_INTERNAL_LIBRUS_ACCOUNT_410
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_NOT_NEEDED
|
import pl.szczodrzynski.edziennik.api.v2.LOGIN_METHOD_NOT_NEEDED
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikInterface
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.librus.LibrusFeatures
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
import pl.szczodrzynski.edziennik.api.v2.models.Feature
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanData
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanData
|
||||||
@ -66,14 +67,15 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
data.targetEndpointIds.clear()
|
data.targetEndpointIds.clear()
|
||||||
data.targetLoginMethodIds.clear()
|
data.targetLoginMethodIds.clear()
|
||||||
|
|
||||||
// get all endpoints for every feature, only if possible to login
|
// get all endpoints for every feature, only if possible to login and possible/necessary to sync
|
||||||
for (featureId in featureIds) {
|
for (featureId in featureIds) {
|
||||||
VulcanFeatures.filter {
|
VulcanFeatures.filter {
|
||||||
it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods)
|
it.featureId == featureId // feature ID matches
|
||||||
|
&& possibleLoginMethods.containsAll(it.requiredLoginMethods) // is possible to login
|
||||||
|
&& it.shouldSync?.invoke(profile, loginStore) ?: true // is necessary/possible to sync
|
||||||
|
}.let {
|
||||||
|
endpointList.addAll(it)
|
||||||
}
|
}
|
||||||
.let {
|
|
||||||
endpointList.addAll(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val timestamp = System.currentTimeMillis()
|
val timestamp = System.currentTimeMillis()
|
||||||
|
Loading…
Reference in New Issue
Block a user