[APIv2/Librus] Add getting classes

This commit is contained in:
Kacper Ziubryniewicz 2019-10-14 14:04:02 +02:00
parent 33cfaef454
commit 7b5269a1fe
3 changed files with 62 additions and 0 deletions

View File

@ -71,6 +71,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
LibrusApiLuckyNumber(data) { onSuccess() }
}
ENDPOINT_LIBRUS_API_CLASSES -> {
data.startProgress(R.string.edziennik_progress_endpoint_classes)
LibrusApiClasses(data) { onSuccess() }
}
else -> onSuccess()
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-10-14
*/
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_CLASSES
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
import pl.szczodrzynski.edziennik.data.db.modules.teams.Team
import pl.szczodrzynski.edziennik.utils.models.Date
class LibrusApiClasses(override val data: DataLibrus,
val onSuccess: () -> Unit) : LibrusApi(data) {
companion object {
const val TAG = "LibrusApiClasses"
}
init {
apiGet(TAG, "Classes") { json ->
json.getJsonObject("Class")?.also { studentClass ->
val id = studentClass.getLong("Id") ?: return@also
val name = studentClass.getString("Number") +
studentClass.getString("Symbol")
val code = data.schoolName + ":" + name
val teacherId = studentClass.getJsonObject("ClassTutor")?.getLong("Id") ?: -1
val teamObject = Team(
profileId,
id,
name,
1,
code,
teacherId
)
data.teamList.put(id, teamObject)
val unitId = studentClass.getJsonObject("Unit").getLong("Id")
profile?.apply {
dateSemester1Start = Date.fromY_m_d(studentClass.getString("BeginSchoolYear")
?: return@apply)
dateSemester2Start = Date.fromY_m_d(studentClass.getString("EndFirstSemester")
?: return@apply)
dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear")
?: return@apply)
if (unitId != null) putStudentData("unitId", unitId)
}
}
data.setSyncNext(ENDPOINT_LIBRUS_API_CLASSES, 4 * DAY)
onSuccess()
}
}
}

View File

@ -944,4 +944,5 @@
<string name="edziennik_progress_endpoint_attendance_types">Pobieranie kategorii obecności...</string>
<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>
</resources>