mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[APIv2/Librus] Add getting classes
This commit is contained in:
parent
33cfaef454
commit
7b5269a1fe
@ -71,6 +71,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||||
LibrusApiLuckyNumber(data) { onSuccess() }
|
LibrusApiLuckyNumber(data) { onSuccess() }
|
||||||
}
|
}
|
||||||
|
ENDPOINT_LIBRUS_API_CLASSES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_classes)
|
||||||
|
LibrusApiClasses(data) { onSuccess() }
|
||||||
|
}
|
||||||
else -> onSuccess()
|
else -> onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -944,4 +944,5 @@
|
|||||||
<string name="edziennik_progress_endpoint_attendance_types">Pobieranie kategorii obecności...</string>
|
<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_progress_endpoint_announcements">Pobieranie ogłoszeń szkolnych...</string>
|
||||||
<string name="edziennik_notification_api_first_login_title">Pierwsze logowanie</string>
|
<string name="edziennik_notification_api_first_login_title">Pierwsze logowanie</string>
|
||||||
|
<string name="edziennik_progress_endpoint_classes">Pobieranie informacji o klasie...</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user