mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 19:04:38 -06:00
[APIv2/Librus] Add getting normal grade categories
This commit is contained in:
parent
23d55ec571
commit
a049effa61
@ -82,6 +82,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
LibrusApiGrades(data) { onSuccess() }
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GC -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
|
||||
LibrusApiGradeCategories(data) { onSuccess() }
|
||||
}
|
||||
// TODO grades
|
||||
|
||||
ENDPOINT_LIBRUS_API_EVENT_TYPES -> {
|
||||
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2019-11-5
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import android.graphics.Color
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GC
|
||||
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.grades.GradeCategory
|
||||
|
||||
class LibrusApiGradeCategories(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiGradeCategories"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "Grades/Categories") { json ->
|
||||
json.getJsonArray("Categories")?.asJsonObjectList()?.forEach { category ->
|
||||
val id = category.getLong("Id") ?: return@forEach
|
||||
val name = category.getString("Name") ?: ""
|
||||
val weight = when (category.getBoolean("CountToTheAverage")) {
|
||||
true -> category.getFloat("Weight") ?: 0f
|
||||
else -> 0f
|
||||
}
|
||||
val color = category.getJsonObject("Color")?.getInt("Id")
|
||||
?.let { data.getColor(it) } ?: Color.BLUE
|
||||
|
||||
val gradeCategoryObject = GradeCategory(
|
||||
profileId,
|
||||
id,
|
||||
weight,
|
||||
color,
|
||||
name
|
||||
)
|
||||
|
||||
data.gradeCategories.put(id, gradeCategoryObject)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GC, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -930,6 +930,7 @@
|
||||
<string name="settings_register_show_teacher_absences_text">Pokazuj nieobecności nauczycieli w Terminarzu</string>
|
||||
<string name="edziennik_progress_endpoint_school_info">Pobieram informacje o szkole...</string>
|
||||
<string name="edziennik_progress_endpoint_grades">Pobieranie ocen ucznia...</string>
|
||||
<string name="edziennik_progress_endpoint_grade_categories">Pobieranie kategorii ocen...</string>
|
||||
<string name="edziennik_progress_login_template_web">Logowanie do Template WEB...</string>
|
||||
<string name="edziennik_progress_login_template_api">Logowanie do Template API...</string>
|
||||
<string name="edziennik_progress_login_mobidziennik_web">Logowanie do MobiDziennika...</string>
|
||||
|
Loading…
Reference in New Issue
Block a user