[APIv2/Librus] Add getting teacher absences

This commit is contained in:
Kacper Ziubryniewicz 2019-10-18 23:56:03 +02:00
parent 8dc358b075
commit cf8afc03bc
4 changed files with 67 additions and 0 deletions

View File

@ -75,6 +75,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
data.startProgress(R.string.edziennik_progress_endpoint_classes)
LibrusApiClasses(data) { onSuccess() }
}
ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS -> {
data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days)
LibrusApiTeacherFreeDays(data) { onSuccess() }
}
else -> onSuccess()
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-10-4.
*/
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Time
class LibrusApiTeacherFreeDays(override val data: DataLibrus,
val onSuccess: () -> Unit) : LibrusApi(data) {
companion object {
const val TAG = "LibrusApiTeacherFreeDays"
}
init {
apiGet(TAG, "TeacherFreeDays") { json ->
val teacherAbsences = json.getJsonArray("TeacherFreeDays")
teacherAbsences?.forEach { teacherAbsenceEl ->
val teacherAbsence = teacherAbsenceEl.asJsonObject
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 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,
id,
teacherId,
type,
dateFrom,
dateTo,
timeFrom,
timeTo
)
data.teacherAbsenceList.add(teacherAbsenceObject)
}
data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS, SYNC_ALWAYS)
onSuccess()
}
}
}

View File

@ -31,6 +31,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.notification.Notification
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
import pl.szczodrzynski.edziennik.singleOrNull
import pl.szczodrzynski.edziennik.toSparseArray
@ -135,6 +136,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
val luckyNumberList = mutableListOf<LuckyNumber>()
val teacherAbsenceList = mutableListOf<TeacherAbsence>()
val messageList = mutableListOf<Message>()
val messageRecipientList = mutableListOf<MessageRecipient>()
val messageRecipientIgnoreList = mutableListOf<MessageRecipient>()
@ -174,6 +177,7 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
attendanceList.clear()
announcementList.clear()
luckyNumberList.clear()
teacherAbsenceList.clear()
messageList.clear()
messageRecipientList.clear()
messageRecipientIgnoreList.clear()
@ -232,6 +236,8 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore)
db.announcementDao().addAll(announcementList)
if (luckyNumberList.isNotEmpty())
db.luckyNumberDao().addAll(luckyNumberList)
if (teacherAbsenceList.isNotEmpty())
db.teacherAbsenceDao().addAll(teacherAbsenceList)
if (messageList.isNotEmpty())
db.messageDao().addAllIgnore(messageList)

View File

@ -948,4 +948,5 @@
<string name="edziennik_progress_endpoint_announcements">Pobieranie ogłoszeń szkolnych...</string>
<string name="edziennik_notification_api_first_login_title">Pierwsze logowanie</string>
<string name="edziennik_progress_endpoint_classes">Pobieranie informacji o klasie...</string>
<string name="edziennik_progress_endpoint_teacher_free_days">Pobieranie nieobecności nauczycieli...</string>
</resources>