forked from github/szkolny
[API/Podlasie] Add getting homework.
This commit is contained in:
parent
48873caecc
commit
deb54e4b24
@ -63,7 +63,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List<JsonObject>) {
|
|||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
Metadata(
|
Metadata(
|
||||||
data.profileId,
|
data.profileId,
|
||||||
Metadata.TYPE_EVENT,
|
if (type == Event.TYPE_HOMEWORK) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT,
|
||||||
id,
|
id,
|
||||||
data.profile?.empty ?: false,
|
data.profile?.empty ?: false,
|
||||||
data.profile?.empty ?: false
|
data.profile?.empty ?: false
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2020-5-14
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.data.api
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import pl.szczodrzynski.edziennik.crc32
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.podlasie.DataPodlasie
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.getString
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class PodlasieApiHomework(val data: DataPodlasie, val rows: List<JsonObject>) {
|
||||||
|
init {
|
||||||
|
rows.reversed().forEach { homework ->
|
||||||
|
val id = homework.getString("ExternalId")?.crc32() ?: return@forEach
|
||||||
|
val topic = homework.getString("Title")?.replace(""", "\"") ?: ""
|
||||||
|
val description = homework.getString("Message")?.replace(""", "\"") ?: ""
|
||||||
|
val date = Date.getToday()
|
||||||
|
val addedDate = System.currentTimeMillis()
|
||||||
|
|
||||||
|
val eventObject = Event(
|
||||||
|
profileId = data.profileId,
|
||||||
|
id = id,
|
||||||
|
date = date,
|
||||||
|
time = null,
|
||||||
|
topic = topic,
|
||||||
|
color = null,
|
||||||
|
type = Event.TYPE_HOMEWORK,
|
||||||
|
teacherId = -1,
|
||||||
|
subjectId = -1,
|
||||||
|
teamId = data.teamClass?.id ?: -1,
|
||||||
|
addedDate = addedDate
|
||||||
|
).apply {
|
||||||
|
homeworkBody = description
|
||||||
|
}
|
||||||
|
|
||||||
|
data.eventList.add(eventObject)
|
||||||
|
data.metadataList.add(
|
||||||
|
Metadata(
|
||||||
|
data.profileId,
|
||||||
|
Metadata.TYPE_HOMEWORK,
|
||||||
|
id,
|
||||||
|
data.profile?.empty ?: false,
|
||||||
|
data.profile?.empty ?: false
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK))
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ class PodlasieApiMain(override val data: DataPodlasie,
|
|||||||
json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) }
|
json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) }
|
||||||
json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) }
|
json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(data, it) }
|
||||||
json.getJsonArray("News")?.asJsonObjectList()?.let { PodlasieApiEvents(data, it) }
|
json.getJsonArray("News")?.asJsonObjectList()?.let { PodlasieApiEvents(data, it) }
|
||||||
|
json.getJsonArray("Tasks")?.asJsonObjectList()?.let { PodlasieApiHomework(data, it) }
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_PODLASIE_API_MAIN, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_PODLASIE_API_MAIN, SYNC_ALWAYS)
|
||||||
onSuccess(ENDPOINT_PODLASIE_API_MAIN)
|
onSuccess(ENDPOINT_PODLASIE_API_MAIN)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user