From aa06868a4e9c3e8e033e114f3cdac411f793996b Mon Sep 17 00:00:00 2001 From: "B.O.S.S" Date: Fri, 10 Dec 2021 21:48:11 +0100 Subject: [PATCH] [API/Librus] Fix LibrusApiTeacherFreeDays. (#123) * [API/Librus] Remove LibrusApiTeacherFreeDayTypes * [API/Librus] Fix LibrusApiTeacherFreeDay * [API/Librus] LibrusApiTeacherFreeDay: Clean up values of unused variables * [API/Librus] LibrusApiTeacherFreeDay: Remove unnecessary variables * [API/Librus] LibrusApiTeacherFreeDay: Assign null to 'name' object --- .../api/edziennik/librus/data/LibrusData.kt | 4 -- .../data/api/LibrusApiTeacherFreeDayTypes.kt | 43 ------------------- .../data/api/LibrusApiTeacherFreeDays.kt | 12 ++---- 3 files changed, 4 insertions(+), 55 deletions(-) delete mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDayTypes.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusData.kt index 877d803b..db72ddcc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/LibrusData.kt @@ -182,10 +182,6 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_pt_meetings) LibrusApiPtMeetings(data, lastSync, onSuccess) } - ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES -> { - data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_day_types) - LibrusApiTeacherFreeDayTypes(data, lastSync, onSuccess) - } ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS -> { data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days) LibrusApiTeacherFreeDays(data, lastSync, onSuccess) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDayTypes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDayTypes.kt deleted file mode 100644 index c87e71d8..00000000 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDayTypes.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) Kacper Ziubryniewicz 2019-10-19 - */ - -package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api - -import pl.szczodrzynski.edziennik.* -import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus -import pl.szczodrzynski.edziennik.data.api.edziennik.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES -import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusApi -import pl.szczodrzynski.edziennik.data.db.entity.TeacherAbsenceType -import pl.szczodrzynski.edziennik.ext.* - -class LibrusApiTeacherFreeDayTypes(override val data: DataLibrus, - override val lastSync: Long?, - val onSuccess: (endpointId: Int) -> Unit -) : LibrusApi(data, lastSync) { - companion object { - const val TAG = "LibrusApiTeacherFreeDayTypes" - } - - init { - apiGet(TAG, "TeacherFreeDays/Types") { json -> - val teacherAbsenceTypes = json.getJsonArray("Types")?.asJsonObjectList() - - teacherAbsenceTypes?.forEach { teacherAbsenceType -> - val id = teacherAbsenceType.getLong("Id") ?: return@forEach - val name = teacherAbsenceType.getString("Name") ?: return@forEach - - val teacherAbsenceTypeObject = TeacherAbsenceType( - profileId, - id, - name - ) - - data.teacherAbsenceTypes.put(id, teacherAbsenceTypeObject) - } - - data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES, 7 * DAY) - onSuccess(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES) - } - } -} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt index 54a3fb36..9ed38834 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/api/LibrusApiTeacherFreeDays.kt @@ -36,22 +36,18 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus, val id = teacherAbsence.getLong("Id") ?: return@forEach val teacherId = teacherAbsence.getJsonObject("Teacher")?.getLong("Id") ?: return@forEach - val type = teacherAbsence.getJsonObject("Type").getLong("Id") ?: return@forEach - val name = data.teacherAbsenceTypes.singleOrNull { it.id == type }?.name val dateFrom = Date.fromY_m_d(teacherAbsence.getString("DateFrom")) val dateTo = Date.fromY_m_d(teacherAbsence.getString("DateTo")) - val timeFrom = teacherAbsence.getString("TimeFrom")?.let { Time.fromH_m_s(it) } - val timeTo = teacherAbsence.getString("TimeTo")?.let { Time.fromH_m_s(it) } val teacherAbsenceObject = TeacherAbsence( profileId = profileId, id = id, - type = type, - name = name, + type = -1L, + name = null, dateFrom = dateFrom, dateTo = dateTo, - timeFrom = timeFrom, - timeTo = timeTo, + timeFrom = null, + timeTo = null, teacherId = teacherId )