diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt index b98440ea..8a169ee7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt @@ -63,7 +63,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List) { data.metadataList.add( Metadata( data.profileId, - Metadata.TYPE_EVENT, + if (type == Event.TYPE_HOMEWORK) Metadata.TYPE_HOMEWORK else Metadata.TYPE_EVENT, id, data.profile?.empty ?: false, data.profile?.empty ?: false diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt new file mode 100644 index 00000000..797b45e0 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt @@ -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) { + 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)) + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiMain.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiMain.kt index d73e8d60..6fe77b5c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiMain.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiMain.kt @@ -30,6 +30,7 @@ class PodlasieApiMain(override val data: DataPodlasie, json.getJsonArray("Marks")?.asJsonObjectList()?.let { PodlasieApiGrades(data, it) } json.getJsonArray("MarkFinal")?.asJsonObjectList()?.let { PodlasieApiFinalGrades(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) onSuccess(ENDPOINT_PODLASIE_API_MAIN)