mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[APIv2/Vulcan] Add getting basic dictionaries (teachers and subjects)
This commit is contained in:
parent
a0fe24ada0
commit
929287a553
@ -6,7 +6,9 @@ package pl.szczodrzynski.edziennik.api.v2.vulcan.data
|
|||||||
|
|
||||||
import pl.szczodrzynski.edziennik.R
|
import pl.szczodrzynski.edziennik.R
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_DICTIONARIES
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_GRADES
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_GRADES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiDictionaries
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
|
|
||||||
@ -38,6 +40,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
private fun useEndpoint(endpointId: Int, onSuccess: () -> Unit) {
|
private fun useEndpoint(endpointId: Int, onSuccess: () -> Unit) {
|
||||||
Utils.d(TAG, "Using endpoint $endpointId")
|
Utils.d(TAG, "Using endpoint $endpointId")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
|
ENDPOINT_VULCAN_API_DICTIONARIES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_dictionaries)
|
||||||
|
VulcanApiDictionaries(data) { onSuccess() }
|
||||||
|
}
|
||||||
ENDPOINT_VULCAN_API_GRADES -> {
|
ENDPOINT_VULCAN_API_GRADES -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||||
VulcanApiGrades(data) { onSuccess() }
|
VulcanApiGrades(data) { onSuccess() }
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-10-20
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_DICTIONARIES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_DICTIONARIES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||||
|
import pl.szczodrzynski.edziennik.getJsonArray
|
||||||
|
import pl.szczodrzynski.edziennik.getJsonObject
|
||||||
|
import pl.szczodrzynski.edziennik.getLong
|
||||||
|
import pl.szczodrzynski.edziennik.getString
|
||||||
|
|
||||||
|
class VulcanApiDictionaries(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VulcanApiDictionaries"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
apiGet(TAG, VULCAN_API_ENDPOINT_DICTIONARIES) { json, _ ->
|
||||||
|
val elements = json.getJsonObject("Data")
|
||||||
|
|
||||||
|
elements?.getJsonArray("Pracownicy")?.forEach { saveTeacher(it.asJsonObject) }
|
||||||
|
elements?.getJsonArray("Przedmioty")?.forEach { saveSubject(it.asJsonObject) }
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_VULCAN_API_DICTIONARIES, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveTeacher(teacher: JsonObject) {
|
||||||
|
val id = teacher.getLong("Id") ?: return
|
||||||
|
val name = teacher.getString("Imie") ?: ""
|
||||||
|
val surname = teacher.getString("Nazwisko") ?: ""
|
||||||
|
val loginId = teacher.getString("LoginId") ?: "-1"
|
||||||
|
|
||||||
|
val teacherObject = Teacher(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
surname,
|
||||||
|
loginId
|
||||||
|
)
|
||||||
|
|
||||||
|
data.teacherList.put(id, teacherObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun saveSubject(subject: JsonObject) {
|
||||||
|
val id = subject.getLong("Id") ?: return
|
||||||
|
val longName = subject.getString("Nazwa") ?: ""
|
||||||
|
val shortName = subject.getString("Kod") ?: ""
|
||||||
|
|
||||||
|
val subjectObject = Subject(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
longName,
|
||||||
|
shortName
|
||||||
|
)
|
||||||
|
|
||||||
|
data.subjectList.put(id, subjectObject)
|
||||||
|
}
|
||||||
|
}
|
@ -4,9 +4,7 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_GRADES
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
import pl.szczodrzynski.edziennik.getJsonArray
|
import pl.szczodrzynski.edziennik.getJsonArray
|
||||||
|
@ -950,4 +950,5 @@
|
|||||||
<string name="edziennik_progress_endpoint_classes">Pobieranie informacji o klasie...</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>
|
<string name="edziennik_progress_endpoint_teacher_free_days">Pobieranie nieobecności nauczycieli...</string>
|
||||||
<string name="edziennik_progress_endpoint_teacher_free_day_types">Pobieranie rodzajów nieobecności nauczycieli...</string>
|
<string name="edziennik_progress_endpoint_teacher_free_day_types">Pobieranie rodzajów nieobecności nauczycieli...</string>
|
||||||
|
<string name="edziennik_progress_endpoint_dictionaries">Pobieranie słowników...</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user