From d5863485f936bddf9a3d261d6a696acc90f45c06 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Tue, 25 Feb 2020 19:28:53 +0100 Subject: [PATCH] [API/Edudziennik] Fix getting attendance for the second semester. --- .../data/web/EdudziennikWebAttendance.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebAttendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebAttendance.kt index 48836e6e..92545117 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebAttendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebAttendance.kt @@ -27,8 +27,15 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik, private const val TAG = "EdudziennikWebAttendance" } - init { data.profile?.also { profile -> - webGet(TAG, data.studentEndpoint + "Presence", semester = -1) { text -> + private var requestSemester: Int? = null + + init { + if (profile?.empty == true && data.currentSemester == 2) requestSemester = 1 + getAttendances() + } + + private fun getAttendances() { data.profile?.also { profile -> + webGet(TAG, data.studentEndpoint + "Presence", semester = requestSemester) { text -> val attendanceTypes = EDUDZIENNIK_ATTENDANCE_TYPES.find(text)?.get(1)?.split(',')?.map { val type = EDUDZIENNIK_ATTENDANCE_TYPE.find(it.trim()) @@ -91,8 +98,13 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik, } } - data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE, SYNC_ALWAYS) - onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) + if (profile.empty && requestSemester == 1 && data.currentSemester == 2) { + requestSemester = null + getAttendances() + } else { + data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE, SYNC_ALWAYS) + onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) + } } } ?: onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) } }