[API/Edudziennik] Fix getting attendance for the second semester.

This commit is contained in:
Kacper Ziubryniewicz 2020-02-25 19:28:53 +01:00
parent afc88d316b
commit d5863485f9

View File

@ -27,8 +27,15 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
private const val TAG = "EdudziennikWebAttendance" private const val TAG = "EdudziennikWebAttendance"
} }
init { data.profile?.also { profile -> private var requestSemester: Int? = null
webGet(TAG, data.studentEndpoint + "Presence", semester = -1) { text ->
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 attendanceTypes = EDUDZIENNIK_ATTENDANCE_TYPES.find(text)?.get(1)?.split(',')?.map {
val type = EDUDZIENNIK_ATTENDANCE_TYPE.find(it.trim()) val type = EDUDZIENNIK_ATTENDANCE_TYPE.find(it.trim())
@ -91,8 +98,13 @@ class EdudziennikWebAttendance(override val data: DataEdudziennik,
} }
} }
if (profile.empty && requestSemester == 1 && data.currentSemester == 2) {
requestSemester = null
getAttendances()
} else {
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE, SYNC_ALWAYS) data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE, SYNC_ALWAYS)
onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE)
} }
}
} ?: onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) } } ?: onSuccess(ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE) }
} }