diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt index 859d7f20..d1f11822 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/VulcanFeatures.kt @@ -8,6 +8,7 @@ import pl.szczodrzynski.edziennik.data.api.* import pl.szczodrzynski.edziennik.data.api.models.Feature const val ENDPOINT_VULCAN_API_UPDATE_SEMESTER = 1000 +const val ENDPOINT_VULCAN_API_PUSH_CONFIG = 1005 const val ENDPOINT_VULCAN_API_DICTIONARIES = 1010 const val ENDPOINT_VULCAN_API_TIMETABLE = 1020 const val ENDPOINT_VULCAN_API_EVENTS = 1030 @@ -53,6 +54,13 @@ val VulcanFeatures = listOf( ENDPOINT_VULCAN_API_MESSAGES_SENT to LOGIN_METHOD_VULCAN_API ), listOf(LOGIN_METHOD_VULCAN_API)), + // push config + Feature(LOGIN_TYPE_VULCAN, FEATURE_PUSH_CONFIG, listOf( + ENDPOINT_VULCAN_API_PUSH_CONFIG to LOGIN_METHOD_VULCAN_API + ), listOf(LOGIN_METHOD_VULCAN_API)).withShouldSync { data -> + !data.app.config.sync.tokenVulcanList.contains(data.profileId) + }, + Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf( ENDPOINT_VULCAN_API_UPDATE_SEMESTER to LOGIN_METHOD_VULCAN_API, ENDPOINT_VULCAN_API_DICTIONARIES to LOGIN_METHOD_VULCAN_API diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanApi.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanApi.kt index 95110f82..3f755b01 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanApi.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanApi.kt @@ -68,6 +68,7 @@ open class VulcanApi(open val data: DataVulcan, open val lastSync: Long?) { is Long -> finalPayload.addProperty(name, value) is Float -> finalPayload.addProperty(name, value) is Char -> finalPayload.addProperty(name, value) + is Boolean -> finalPayload.addProperty(name, value) } } finalPayload.addProperty("RemoteMobileTimeKey", System.currentTimeMillis() / 1000) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt index 5035fcc9..b5deb178 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/VulcanData.kt @@ -42,6 +42,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_student_info) VulcanApiUpdateSemester(data, lastSync, onSuccess) } + ENDPOINT_VULCAN_API_PUSH_CONFIG -> { + data.startProgress(R.string.edziennik_progress_endpoint_push_config) + VulcanApiPushConfig(data, lastSync, onSuccess) + } ENDPOINT_VULCAN_API_DICTIONARIES -> { data.startProgress(R.string.edziennik_progress_endpoint_dictionaries) VulcanApiDictionaries(data, lastSync, onSuccess) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiPushConfig.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiPushConfig.kt new file mode 100644 index 00000000..b7e291e2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/api/VulcanApiPushConfig.kt @@ -0,0 +1,37 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2020-2-20. + */ + +package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api + +import pl.szczodrzynski.edziennik.data.api.VULCAN_API_ENDPOINT_PUSH +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_API_PUSH_CONFIG +import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanApi +import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS + +class VulcanApiPushConfig(override val data: DataVulcan, + override val lastSync: Long?, + val onSuccess: (endpointId: Int) -> Unit +) : VulcanApi(data, lastSync) { + companion object { + const val TAG = "VulcanApiPushConfig" + } + + init { data.app.config.sync.tokenVulcan?.also { tokenVulcan -> + apiGet(TAG, VULCAN_API_ENDPOINT_PUSH, parameters = mapOf( + "Token" to tokenVulcan, + "IdUczen" to data.studentId, + "PushOcena" to true, + "PushFrekwencja" to true, + "PushUwaga" to true, + "PushWiadomosc" to true + )) { _, _ -> + // sync always: this endpoint has .shouldSync set + data.setSyncNext(ENDPOINT_VULCAN_API_PUSH_CONFIG, SYNC_ALWAYS) + data.app.config.sync.tokenVulcanList = + data.app.config.sync.tokenVulcanList + profileId + onSuccess(ENDPOINT_VULCAN_API_PUSH_CONFIG) + } + } ?: onSuccess(ENDPOINT_VULCAN_API_PUSH_CONFIG) } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyMobidziennikFirebase.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyMobidziennikFirebase.kt index 212227eb..f102fc2a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyMobidziennikFirebase.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyMobidziennikFirebase.kt @@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_ATTENDANCE import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_BEHAVIOUR import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_GRADES import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_MESSAGES +import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_MOBIDZIENNIK import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask import pl.szczodrzynski.edziennik.data.api.task.IApiTask import pl.szczodrzynski.edziennik.data.db.entity.Message.TYPE_RECEIVED @@ -60,7 +61,8 @@ class SzkolnyMobidziennikFirebase(val app: App, val profiles: List, val } val tasks = profiles.filter { - it.getStudentData("globalId", 0L) == globalId + it.loginStoreType == LOGIN_TYPE_MOBIDZIENNIK && + it.getStudentData("globalId", 0L) == globalId }.map { EdziennikTask.syncProfile(it.id, listOf(viewIdPair)) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt index 562e17ea..a03a2199 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/firebase/SzkolnyVulcanFirebase.kt @@ -4,8 +4,13 @@ package pl.szczodrzynski.edziennik.data.firebase -import pl.szczodrzynski.edziennik.App +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_VULCAN +import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask +import pl.szczodrzynski.edziennik.data.api.task.IApiTask +import pl.szczodrzynski.edziennik.data.db.entity.Message import pl.szczodrzynski.edziennik.data.db.entity.Profile +import java.util.* class SzkolnyVulcanFirebase(val app: App, val profiles: List, val message: FirebaseService.Message) { /*{ @@ -20,7 +25,28 @@ class SzkolnyVulcanFirebase(val app: App, val profiles: List, val messa "title": "Frekwencja", "message: "Uczeń Janósz otrzymał nieobecność na 7 lekcji" }*/ - init { + init { run { + val data = message.data.getJsonObject("data") ?: return@run + val type = data.getString("table") ?: return@run + val studentId = data.getInt("pupilid") - } + /* pl.vulcan.uonetmobile.auxilary.enums.CDCPushEnum */ + val viewIdPair = when (type.toLowerCase(Locale.ROOT)) { + "wiadomosc" -> MainActivity.DRAWER_ITEM_MESSAGES to Message.TYPE_RECEIVED + "ocena" -> MainActivity.DRAWER_ITEM_GRADES to 0 + "uwaga" -> MainActivity.DRAWER_ITEM_BEHAVIOUR to 0 + "frekwencja" -> MainActivity.DRAWER_ITEM_ATTENDANCE to 0 + // this type is not even implemented in Dzienniczek+ + "sprawdzian" -> MainActivity.DRAWER_ITEM_AGENDA to 0 + else -> return@run + } + + val tasks = profiles.filter { + it.loginStoreType == LOGIN_TYPE_VULCAN && + it.getStudentData("studentId", 0) == studentId + }.map { + EdziennikTask.syncProfile(it.id, listOf(viewIdPair)) + } + IApiTask.enqueueAll(app, tasks) + }} }