diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt
index ef811453..1d07ffd1 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt
@@ -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 -> {
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeCategories.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeCategories.kt
new file mode 100644
index 00000000..b91eae8a
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeCategories.kt
@@ -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()
+ }
+ }
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7b31bc00..a08886af 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -930,6 +930,7 @@
Pokazuj nieobecności nauczycieli w Terminarzu
Pobieram informacje o szkole...
Pobieranie ocen ucznia...
+ Pobieranie kategorii ocen...
Logowanie do Template WEB...
Logowanie do Template API...
Logowanie do MobiDziennika...