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 667683c1..d9cf3662 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 @@ -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.login.LibrusLogin 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.Feature 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.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) { LibrusFeatures.filter { - it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods) - } - .let { - endpointList.addAll(it) - } + 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) + } } val timestamp = System.currentTimeMillis() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt index 123eba43..c8687faa 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/mobidziennik/Mobidziennik.kt @@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.App import pl.szczodrzynski.edziennik.api.v2.* import pl.szczodrzynski.edziennik.api.v2.interfaces.EdziennikCallback 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.login.MobidziennikLogin 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.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) { 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() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Feature.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Feature.kt index b8d9b8a7..91ac6563 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Feature.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Feature.kt @@ -1,5 +1,8 @@ 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. * @@ -20,4 +23,14 @@ data class Feature( val requiredLoginMethods: List ) { 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 + } } \ No newline at end of file diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt index a703f73a..a639e65e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/template/Template.kt @@ -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.interfaces.EdziennikCallback 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.Feature import pl.szczodrzynski.edziennik.api.v2.template.data.TemplateData import pl.szczodrzynski.edziennik.api.v2.template.login.TemplateLogin 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.SYNC_ALWAYS 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.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) { - TemplateFeatures.filter { - it.featureId == featureId && possibleLoginMethods.containsAll(it.requiredLoginMethods) + VulcanFeatures.filter { + 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() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt index c88023e5..d5af284f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/Vulcan.kt @@ -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.interfaces.EdziennikCallback 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.Feature 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.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) { 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()