From 2a7535920efbd144fffdd3ea7876210468dc50ff Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Mon, 21 Oct 2019 00:27:24 +0200 Subject: [PATCH] [APIv2/Vulcan] Add getting team if it doesn't exist --- .../edziennik/api/v2/vulcan/data/VulcanApi.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/VulcanApi.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/VulcanApi.kt index 57602f45..de9574c4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/VulcanApi.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/vulcan/data/VulcanApi.kt @@ -12,6 +12,8 @@ import io.github.wulkanowy.signer.signContent import pl.szczodrzynski.edziennik.api.v2.* import pl.szczodrzynski.edziennik.api.v2.models.ApiError import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan +import pl.szczodrzynski.edziennik.data.db.modules.teams.Team +import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.Utils.d import pl.szczodrzynski.edziennik.utils.models.Date import java.net.HttpURLConnection @@ -34,6 +36,22 @@ open class VulcanApi(open val data: DataVulcan) { d(tag, "Request: Vulcan/Api - $url") + if (data.teamList.size() == 0) { + profile?.getStudentData("studentClassName", null)?.also { name -> + val id = Utils.crc16(name.toByteArray()).toLong() + + val teamObject = Team( + profileId, + id, + name, + Team.TYPE_CLASS, + "${data.schoolName}:$name", + -1 + ) + data.teamList.put(id, teamObject) + } + } + val startDate = when(profile?.empty) { true -> profile?.getSemesterStart(profile?.currentSemester ?: 1)?.stringY_m_d else -> Date.getToday().stepForward(0, -1, 0).stringY_m_d