mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-22 14:34:44 +01:00
[Firebase/Librus] Implement Librus push registration and receiving. Fix not passing lastSync to endpoint.
This commit is contained in:
parent
aa5e225148
commit
67be456bb0
@ -567,7 +567,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
|
|||||||
EdziennikTask.syncProfile(
|
EdziennikTask.syncProfile(
|
||||||
App.profileId,
|
App.profileId,
|
||||||
listOf(navTargetId to fragmentParam),
|
listOf(navTargetId to fragmentParam),
|
||||||
arguments
|
arguments = arguments
|
||||||
).enqueue(this)
|
).enqueue(this)
|
||||||
}
|
}
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
@ -7,7 +7,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.EndpointTimer
|
|||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_NEVER
|
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_NEVER
|
||||||
|
|
||||||
fun Data.prepare(loginMethods: List<LoginMethod>, features: List<Feature>, featureIds: List<Int>, viewId: Int?) {
|
fun Data.prepare(loginMethods: List<LoginMethod>, features: List<Feature>, featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?) {
|
||||||
val data = this
|
val data = this
|
||||||
|
|
||||||
val possibleLoginMethods = data.loginMethods.toMutableList()
|
val possibleLoginMethods = data.loginMethods.toMutableList()
|
||||||
@ -46,13 +46,18 @@ fun Data.prepare(loginMethods: List<LoginMethod>, features: List<Feature>, featu
|
|||||||
// add all endpoint IDs and required login methods, filtering using timers
|
// add all endpoint IDs and required login methods, filtering using timers
|
||||||
.onEach { feature ->
|
.onEach { feature ->
|
||||||
feature.endpointIds.forEach { endpoint ->
|
feature.endpointIds.forEach { endpoint ->
|
||||||
|
if (onlyEndpoints?.contains(endpoint.first) == false)
|
||||||
|
return@forEach
|
||||||
(data.endpointTimers
|
(data.endpointTimers
|
||||||
.singleOrNull { it.endpointId == endpoint.first } ?: EndpointTimer(data.profile?.id
|
.singleOrNull { it.endpointId == endpoint.first } ?: EndpointTimer(data.profile?.id
|
||||||
?: -1, endpoint.first))
|
?: -1, endpoint.first))
|
||||||
.let { timer ->
|
.let { timer ->
|
||||||
if (timer.nextSync == SYNC_ALWAYS ||
|
if (
|
||||||
(viewId != null && timer.viewId == viewId) ||
|
onlyEndpoints?.contains(endpoint.first) == true ||
|
||||||
(timer.nextSync != SYNC_NEVER && timer.nextSync < timestamp)) {
|
timer.nextSync == SYNC_ALWAYS ||
|
||||||
|
viewId != null && timer.viewId == viewId ||
|
||||||
|
timer.nextSync != SYNC_NEVER && timer.nextSync < timestamp
|
||||||
|
) {
|
||||||
data.targetEndpointIds[endpoint.first] = timer.lastSync
|
data.targetEndpointIds[endpoint.first] = timer.lastSync
|
||||||
requiredLoginMethods.add(endpoint.second)
|
requiredLoginMethods.add(endpoint.second)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
|
|
||||||
fun firstLogin(loginStore: LoginStore) = EdziennikTask(-1, FirstLoginRequest(loginStore))
|
fun firstLogin(loginStore: LoginStore) = EdziennikTask(-1, FirstLoginRequest(loginStore))
|
||||||
fun sync() = EdziennikTask(-1, SyncRequest())
|
fun sync() = EdziennikTask(-1, SyncRequest())
|
||||||
fun syncProfile(profileId: Int, viewIds: List<Pair<Int, Int>>? = null, arguments: JsonObject? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds, arguments))
|
fun syncProfile(profileId: Int, viewIds: List<Pair<Int, Int>>? = null, onlyEndpoints: List<Int>? = null, arguments: JsonObject? = null) = EdziennikTask(profileId, SyncProfileRequest(viewIds, onlyEndpoints, arguments))
|
||||||
fun syncProfileList(profileList: List<Int>) = EdziennikTask(-1, SyncProfileListRequest(profileList))
|
fun syncProfileList(profileList: List<Int>) = EdziennikTask(-1, SyncProfileListRequest(profileList))
|
||||||
fun messageGet(profileId: Int, message: MessageFull) = EdziennikTask(profileId, MessageGetRequest(message))
|
fun messageGet(profileId: Int, message: MessageFull) = EdziennikTask(profileId, MessageGetRequest(message))
|
||||||
fun messageSend(profileId: Int, recipients: List<Teacher>, subject: String, text: String) = EdziennikTask(profileId, MessageSendRequest(recipients, subject, text))
|
fun messageSend(profileId: Int, recipients: List<Teacher>, subject: String, text: String) = EdziennikTask(profileId, MessageSendRequest(recipients, subject, text))
|
||||||
@ -85,6 +85,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
featureIds = request.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) }
|
featureIds = request.viewIds?.flatMap { Features.getIdsByView(it.first, it.second) }
|
||||||
?: Features.getAllIds(),
|
?: Features.getAllIds(),
|
||||||
viewId = request.viewIds?.get(0)?.first,
|
viewId = request.viewIds?.get(0)?.first,
|
||||||
|
onlyEndpoints = request.onlyEndpoints,
|
||||||
arguments = request.arguments)
|
arguments = request.arguments)
|
||||||
is MessageGetRequest -> edziennikInterface?.getMessage(request.message)
|
is MessageGetRequest -> edziennikInterface?.getMessage(request.message)
|
||||||
is MessageSendRequest -> edziennikInterface?.sendMessage(request.recipients, request.subject, request.text)
|
is MessageSendRequest -> edziennikInterface?.sendMessage(request.recipients, request.subject, request.text)
|
||||||
@ -106,7 +107,7 @@ open class EdziennikTask(override val profileId: Int, val request: Any) : IApiTa
|
|||||||
|
|
||||||
data class FirstLoginRequest(val loginStore: LoginStore)
|
data class FirstLoginRequest(val loginStore: LoginStore)
|
||||||
class SyncRequest
|
class SyncRequest
|
||||||
data class SyncProfileRequest(val viewIds: List<Pair<Int, Int>>? = null, val arguments: JsonObject? = null)
|
data class SyncProfileRequest(val viewIds: List<Pair<Int, Int>>? = null, val onlyEndpoints: List<Int>? = null, val arguments: JsonObject? = null)
|
||||||
data class SyncProfileListRequest(val profileList: List<Int>)
|
data class SyncProfileListRequest(val profileList: List<Int>)
|
||||||
data class MessageGetRequest(val message: MessageFull)
|
data class MessageGetRequest(val message: MessageFull)
|
||||||
data class MessageSendRequest(val recipients: List<Teacher>, val subject: String, val text: String)
|
data class MessageSendRequest(val recipients: List<Teacher>, val subject: String, val text: String)
|
||||||
|
@ -52,9 +52,9 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(edudziennikLoginMethods, EdudziennikFeatures, featureIds, viewId)
|
data.prepare(edudziennikLoginMethods, EdudziennikFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,15 +28,14 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_START -> {
|
ENDPOINT_EDUDZIENNIK_WEB_START -> {
|
||||||
|
@ -54,9 +54,9 @@ class Idziennik(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(idziennikLoginMethods, IdziennikFeatures, featureIds, viewId)
|
data.prepare(idziennikLoginMethods, IdziennikFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,15 +31,14 @@ class IdziennikData(val data: DataIdziennik, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
ENDPOINT_IDZIENNIK_WEB_TIMETABLE -> {
|
ENDPOINT_IDZIENNIK_WEB_TIMETABLE -> {
|
||||||
|
@ -191,6 +191,16 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
|||||||
get() { mApiTokenExpiryTime = mApiTokenExpiryTime ?: profile?.getStudentData("accountTokenTime", 0L); return mApiTokenExpiryTime ?: 0L }
|
get() { mApiTokenExpiryTime = mApiTokenExpiryTime ?: profile?.getStudentData("accountTokenTime", 0L); return mApiTokenExpiryTime ?: 0L }
|
||||||
set(value) { mApiTokenExpiryTime = value; profile?.putStudentData("accountTokenTime", value) ?: return; }
|
set(value) { mApiTokenExpiryTime = value; profile?.putStudentData("accountTokenTime", value) ?: return; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A push device ID, generated by Librus when registering
|
||||||
|
* a FCM token. I don't really know if this has any use,
|
||||||
|
* but it may be worthy to save that ID.
|
||||||
|
*/
|
||||||
|
private var mPushDeviceId: Int? = null
|
||||||
|
var pushDeviceId: Int
|
||||||
|
get() { mPushDeviceId = mPushDeviceId ?: profile?.getStudentData("pushDeviceId", 0); return mPushDeviceId ?: 0 }
|
||||||
|
set(value) { mPushDeviceId = value; profile?.putStudentData("pushDeviceId", value) ?: return; }
|
||||||
|
|
||||||
/* _____ _
|
/* _____ _
|
||||||
/ ____| (_)
|
/ ____| (_)
|
||||||
| (___ _ _ _ __ ___ _ __ __ _ _ __ _
|
| (___ _ _ _ __ ___ _ __ __ _ _ __ _
|
||||||
|
@ -56,9 +56,9 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(librusLoginMethods, LibrusFeatures, featureIds, viewId)
|
data.prepare(librusLoginMethods, LibrusFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +53,6 @@ const val ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK = 2030
|
|||||||
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVED = 3010
|
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVED = 3010
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_SENT = 3020
|
const val ENDPOINT_LIBRUS_MESSAGES_SENT = 3020
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_TRASH = 3030
|
const val ENDPOINT_LIBRUS_MESSAGES_TRASH = 3030
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_RECEIVERS = 3040
|
|
||||||
const val ENDPOINT_LIBRUS_MESSAGES_GET = 3040
|
|
||||||
|
|
||||||
val LibrusFeatures = listOf(
|
val LibrusFeatures = listOf(
|
||||||
|
|
||||||
|
@ -32,15 +32,14 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
/**
|
/**
|
||||||
@ -82,7 +81,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_lessons)
|
data.startProgress(R.string.edziennik_progress_endpoint_lessons)
|
||||||
LibrusApiLessons(data, lastSync, onSuccess)
|
LibrusApiLessons(data, lastSync, onSuccess)
|
||||||
}
|
}
|
||||||
// TODO push config
|
ENDPOINT_LIBRUS_API_PUSH_CONFIG -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_push_config)
|
||||||
|
LibrusApiPushConfig(data, lastSync, onSuccess)
|
||||||
|
}
|
||||||
ENDPOINT_LIBRUS_API_TIMETABLES -> {
|
ENDPOINT_LIBRUS_API_TIMETABLES -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
||||||
LibrusApiTimetables(data, lastSync, onSuccess)
|
LibrusApiTimetables(data, lastSync, onSuccess)
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kuba Szczodrzyński 2020-2-21.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.JsonObject
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_PUSH_CONFIG
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.getInt
|
||||||
|
import pl.szczodrzynski.edziennik.getJsonObject
|
||||||
|
|
||||||
|
class LibrusApiPushConfig(override val data: DataLibrus,
|
||||||
|
override val lastSync: Long?,
|
||||||
|
val onSuccess: (endpointId: Int) -> Unit
|
||||||
|
) : LibrusApi(data, lastSync) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "LibrusApiPushConfig"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.app.config.sync.tokenLibrus?.also { tokenLibrus ->
|
||||||
|
apiGet(TAG, "ChangeRegister", payload = JsonObject(
|
||||||
|
"provider" to "FCM",
|
||||||
|
"device" to tokenLibrus,
|
||||||
|
"sendPush" to "1",
|
||||||
|
"appVersion" to 4
|
||||||
|
)) { json ->
|
||||||
|
json.getJsonObject("ChangeRegister")?.getInt("Id")?.let { data.pushDeviceId = it }
|
||||||
|
|
||||||
|
// sync always: this endpoint has .shouldSync set
|
||||||
|
data.setSyncNext(ENDPOINT_LIBRUS_API_PUSH_CONFIG, SYNC_ALWAYS)
|
||||||
|
data.app.config.sync.tokenLibrusList =
|
||||||
|
data.app.config.sync.tokenLibrusList + profileId
|
||||||
|
onSuccess(ENDPOINT_LIBRUS_API_PUSH_CONFIG)
|
||||||
|
}
|
||||||
|
} ?: onSuccess(ENDPOINT_LIBRUS_API_PUSH_CONFIG) }
|
||||||
|
}
|
@ -8,8 +8,9 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
|||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi
|
||||||
|
|
||||||
class LibrusApiTemplate(override val data: DataLibrus,
|
class LibrusApiTemplate(override val data: DataLibrus,
|
||||||
val onSuccess: () -> Unit
|
override val lastSync: Long?,
|
||||||
) : LibrusApi(data, null) {
|
val onSuccess: (endpointId: Int) -> Unit
|
||||||
|
) : LibrusApi(data, lastSync) {
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "LibrusApi"
|
const val TAG = "LibrusApi"
|
||||||
}
|
}
|
||||||
@ -18,7 +19,7 @@ class LibrusApiTemplate(override val data: DataLibrus,
|
|||||||
/*apiGet(TAG, "") { json ->
|
/*apiGet(TAG, "") { json ->
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess(ENDPOINT_LIBRUS_API_)
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,9 +56,9 @@ class Mobidziennik(val app: App, val profile: Profile?, val loginStore: LoginSto
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(mobidziennikLoginMethods, MobidziennikFeatures, featureIds, viewId)
|
data.prepare(mobidziennikLoginMethods, MobidziennikFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,15 +30,14 @@ class MobidziennikData(val data: DataMobidziennik, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
ENDPOINT_MOBIDZIENNIK_API_MAIN -> {
|
ENDPOINT_MOBIDZIENNIK_API_MAIN -> {
|
||||||
|
@ -51,9 +51,9 @@ class Template(val app: App, val profile: Profile?, val loginStore: LoginStore,
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(templateLoginMethods, TemplateFeatures, featureIds, viewId)
|
data.prepare(templateLoginMethods, TemplateFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
d(TAG, "LoginMethod IDs: ${data.targetLoginMethodIds}")
|
||||||
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
d(TAG, "Endpoint IDs: ${data.targetEndpointIds}")
|
||||||
TemplateLogin(data) {
|
TemplateLogin(data) {
|
||||||
|
@ -33,15 +33,14 @@ class TemplateData(val data: DataTemplate, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
ENDPOINT_TEMPLATE_WEB_SAMPLE -> {
|
ENDPOINT_TEMPLATE_WEB_SAMPLE -> {
|
||||||
|
@ -55,9 +55,9 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
|_| |_| |_|\___| /_/ \_\_|\__, |\___/|_| |_|\__|_| |_|_| |_| |_|
|
||||||
__/ |
|
__/ |
|
||||||
|__*/
|
|__*/
|
||||||
override fun sync(featureIds: List<Int>, viewId: Int?, arguments: JsonObject?) {
|
override fun sync(featureIds: List<Int>, viewId: Int?, onlyEndpoints: List<Int>?, arguments: JsonObject?) {
|
||||||
data.arguments = arguments
|
data.arguments = arguments
|
||||||
data.prepare(vulcanLoginMethods, VulcanFeatures, featureIds, viewId)
|
data.prepare(vulcanLoginMethods, VulcanFeatures, featureIds, viewId, onlyEndpoints)
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,15 +28,14 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val id = data.targetEndpointIds.firstKey()
|
val id = data.targetEndpointIds.firstKey()
|
||||||
data.targetEndpointIds.remove(id)
|
val lastSync = data.targetEndpointIds.remove(id)
|
||||||
useEndpoint(id) { endpointId ->
|
useEndpoint(id, lastSync) { endpointId ->
|
||||||
data.progress(data.progressStep)
|
data.progress(data.progressStep)
|
||||||
nextEndpoint(onSuccess)
|
nextEndpoint(onSuccess)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun useEndpoint(endpointId: Int, onSuccess: (endpointId: Int) -> Unit) {
|
private fun useEndpoint(endpointId: Int, lastSync: Long?, onSuccess: (endpointId: Int) -> Unit) {
|
||||||
val lastSync = data.targetEndpointIds[endpointId]
|
|
||||||
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
Utils.d(TAG, "Using endpoint $endpointId. Last sync time = $lastSync")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
ENDPOINT_VULCAN_API_UPDATE_SEMESTER -> {
|
ENDPOINT_VULCAN_API_UPDATE_SEMESTER -> {
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.interfaces
|
package pl.szczodrzynski.edziennik.data.api.interfaces
|
||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.AnnouncementFull
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.full.MessageFull
|
||||||
|
|
||||||
interface EdziennikInterface {
|
interface EdziennikInterface {
|
||||||
fun sync(featureIds: List<Int>, viewId: Int? = null, arguments: JsonObject? = null)
|
fun sync(featureIds: List<Int>, viewId: Int? = null, onlyEndpoints: List<Int>? = null, arguments: JsonObject? = null)
|
||||||
fun getMessage(message: MessageFull)
|
fun getMessage(message: MessageFull)
|
||||||
fun sendMessage(recipients: List<Teacher>, subject: String, text: String)
|
fun sendMessage(recipients: List<Teacher>, subject: String, text: String)
|
||||||
fun markAllAnnouncementsAsRead()
|
fun markAllAnnouncementsAsRead()
|
||||||
|
@ -87,7 +87,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||||||
if (remoteMessage.getData().get("id_wiadomosci") != null) {
|
if (remoteMessage.getData().get("id_wiadomosci") != null) {
|
||||||
|
|
||||||
d(TAG, "Syncing profile " + profile.getId());
|
d(TAG, "Syncing profile " + profile.getId());
|
||||||
EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app);
|
EdziennikTask.Companion.syncProfile(profile.getId(), null, null, null).enqueue(app);
|
||||||
} else {
|
} else {
|
||||||
/*app.notifier.add(new Notification(app.getContext(), remoteMessage.getData().get("message"))
|
/*app.notifier.add(new Notification(app.getContext(), remoteMessage.getData().get("message"))
|
||||||
.withProfileData(profile.id, profile.name)
|
.withProfileData(profile.id, profile.name)
|
||||||
@ -98,7 +98,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||||||
app.notifier.postAll(profile);
|
app.notifier.postAll(profile);
|
||||||
app.saveConfig("notifications");*/
|
app.saveConfig("notifications");*/
|
||||||
d(TAG, "Syncing profile " + profile.getId());
|
d(TAG, "Syncing profile " + profile.getId());
|
||||||
EdziennikTask.Companion.syncProfile(profile.getId(), null, null).enqueue(app);
|
EdziennikTask.Companion.syncProfile(profile.getId(), null, null, null).enqueue(app);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.firebase
|
package pl.szczodrzynski.edziennik.data.firebase
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
|
import pl.szczodrzynski.edziennik.MainActivity
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_LIBRUS
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
import pl.szczodrzynski.edziennik.data.api.edziennik.EdziennikTask
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.task.IApiTask
|
import pl.szczodrzynski.edziennik.data.api.task.IApiTask
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
import pl.szczodrzynski.edziennik.data.db.entity.Profile
|
||||||
import pl.szczodrzynski.edziennik.getString
|
import pl.szczodrzynski.edziennik.getString
|
||||||
@ -23,14 +26,44 @@ class SzkolnyLibrusFirebase(val app: App, val profiles: List<Profile>, val messa
|
|||||||
"objectType": "Calendars/TeacherFreeDays",
|
"objectType": "Calendars/TeacherFreeDays",
|
||||||
}*/
|
}*/
|
||||||
init { run {
|
init { run {
|
||||||
val apiLogin = message.data.getString("userId") ?: return@run
|
val type = message.data.getString("objectType") ?: return@run
|
||||||
|
val accountLogin = message.data.getString("userId")?.replace("u", "") ?: return@run
|
||||||
|
|
||||||
val tasks = profiles.filter {
|
/* ./src/store/modules/helpers/change-processor.js */
|
||||||
it.getStudentData("accountLogin", "") == apiLogin
|
val endpoints = when (type) {
|
||||||
}.map {
|
"Notes" -> listOf(ENDPOINT_LIBRUS_API_NOTICES)
|
||||||
EdziennikTask.syncProfile(it.id)
|
"Grades" -> listOf(ENDPOINT_LIBRUS_API_NORMAL_GRADES, ENDPOINT_LIBRUS_API_NORMAL_GRADE_CATEGORIES, ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS)
|
||||||
|
"PointGrades" -> listOf(ENDPOINT_LIBRUS_API_POINT_GRADES, ENDPOINT_LIBRUS_API_POINT_GRADE_CATEGORIES)
|
||||||
|
"DescriptiveGrades" -> listOf(ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES)
|
||||||
|
"DescriptiveGrades/Text/Categories" -> listOf(ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADE_CATEGORIES)
|
||||||
|
"DescriptiveTextGrades" -> listOf(ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADES)
|
||||||
|
"TextGrades" -> listOf(ENDPOINT_LIBRUS_API_TEXT_GRADES)
|
||||||
|
"BehaviourGrades/Points" -> listOf(ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES, ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_CATEGORIES, ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADE_COMMENTS)
|
||||||
|
"BehaviourGrades" -> listOf()
|
||||||
|
"Attendances" -> listOf(ENDPOINT_LIBRUS_API_ATTENDANCES)
|
||||||
|
"HomeWorks" -> listOf(ENDPOINT_LIBRUS_API_EVENTS)
|
||||||
|
"ParentTeacherConferences" -> listOf(ENDPOINT_LIBRUS_API_PT_MEETINGS)
|
||||||
|
"Calendars/ClassFreeDays" -> listOf(ENDPOINT_LIBRUS_API_CLASS_FREE_DAYS)
|
||||||
|
"Calendars/TeacherFreeDays" -> listOf(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS)
|
||||||
|
"Calendars/SchoolFreeDays" -> listOf(ENDPOINT_LIBRUS_API_SCHOOL_FREE_DAYS)
|
||||||
|
"Calendars/Substitutions" -> listOf(ENDPOINT_LIBRUS_API_TIMETABLES)
|
||||||
|
"HomeWorkAssignments" -> listOf(ENDPOINT_LIBRUS_API_HOMEWORK, ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK)
|
||||||
|
"SchoolNotices" -> listOf(ENDPOINT_LIBRUS_API_ANNOUNCEMENTS)
|
||||||
|
"Messages" -> listOf(ENDPOINT_LIBRUS_MESSAGES_RECEIVED)
|
||||||
|
"LuckyNumbers" -> listOf(ENDPOINT_LIBRUS_API_LUCKY_NUMBER)
|
||||||
|
"Timetables" -> listOf(ENDPOINT_LIBRUS_API_TIMETABLES)
|
||||||
|
else -> return@run
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (endpoints.isEmpty())
|
||||||
|
return@run
|
||||||
|
|
||||||
|
val tasks = profiles.filter {
|
||||||
|
it.loginStoreType == LOGIN_TYPE_LIBRUS &&
|
||||||
|
it.getStudentData("accountLogin", "")?.replace("u", "") == accountLogin
|
||||||
|
}.map {
|
||||||
|
EdziennikTask.syncProfile(it.id, listOf(MainActivity.DRAWER_ITEM_HOME to 0), onlyEndpoints = endpoints)
|
||||||
|
}
|
||||||
IApiTask.enqueueAll(app, tasks)
|
IApiTask.enqueueAll(app, tasks)
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user