diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt
index 79c7d2df..02bd46d7 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt
@@ -24,6 +24,7 @@ const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GC = 1023
const val ENDPOINT_LIBRUS_API_TEXT_GC = 1024
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC = 1025
const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GC = 1026
+const val ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS = 1030
const val ENDPOINT_LIBRUS_API_NORMAL_GRADES = 1031
const val ENDPOINT_LIBRUS_API_POINT_GRADES = 1032
const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES = 1033
@@ -97,6 +98,7 @@ val LibrusFeatures = listOf(
ENDPOINT_LIBRUS_API_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GC to LOGIN_METHOD_LIBRUS_API,
ENDPOINT_LIBRUS_API_BEHAVIOUR_GC to LOGIN_METHOD_LIBRUS_API,
+ ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS to LOGIN_METHOD_LIBRUS_API,
ENDPOINT_LIBRUS_API_NORMAL_GRADES to LOGIN_METHOD_LIBRUS_API,
ENDPOINT_LIBRUS_API_POINT_GRADES to LOGIN_METHOD_LIBRUS_API,
ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES to LOGIN_METHOD_LIBRUS_API,
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 940d48fe..c919cd52 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
@@ -85,6 +85,10 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
data.startProgress(R.string.edziennik_progress_endpoint_grades)
LibrusApiGrades(data, onSuccess)
}
+ ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS -> {
+ data.startProgress(R.string.edziennik_progress_endpoint_grade_comments)
+ LibrusApiGradeComments(data, onSuccess)
+ }
ENDPOINT_LIBRUS_API_NORMAL_GC -> {
data.startProgress(R.string.edziennik_progress_endpoint_grade_categories)
LibrusApiGradeCategories(data, onSuccess)
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeComments.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeComments.kt
new file mode 100644
index 00000000..26a1b76b
--- /dev/null
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGradeComments.kt
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) Kacper Ziubryniewicz 2019-11-20
+ */
+
+package pl.szczodrzynski.edziennik.api.v2.librus.data.api
+
+import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
+import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS
+import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
+import pl.szczodrzynski.edziennik.asJsonObjectList
+import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
+import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
+import pl.szczodrzynski.edziennik.getJsonArray
+import pl.szczodrzynski.edziennik.getLong
+import pl.szczodrzynski.edziennik.getString
+
+class LibrusApiGradeComments(override val data: DataLibrus,
+ val onSuccess: () -> Unit) : LibrusApi(data) {
+ companion object {
+ const val TAG = "LibrusApiGradeComments"
+ }
+
+ init {
+ apiGet(TAG, "Grades/Comments") { json ->
+
+ json.getJsonArray("Comments")?.asJsonObjectList()?.forEach { comment ->
+ val id = comment.getLong("Id") ?: return@forEach
+ val text = comment.getString("Text")
+
+ val gradeCategoryObject = GradeCategory(
+ profileId,
+ id,
+ -1f,
+ -1,
+ text
+ ).apply {
+ type = GradeCategory.TYPE_COMMENT
+ }
+
+ data.gradeCategories.put(id, gradeCategoryObject)
+ }
+
+ data.setSyncNext(ENDPOINT_LIBRUS_API_NORMAL_GRADE_COMMENTS, SYNC_ALWAYS)
+ onSuccess()
+ }
+ }
+}
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt
index 930938d0..07c76f00 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt
@@ -6,6 +6,7 @@ import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADE
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.Grade
+import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
import pl.szczodrzynski.edziennik.utils.Utils
import pl.szczodrzynski.edziennik.utils.models.Date
@@ -42,12 +43,21 @@ class LibrusApiGrades(override val data: DataLibrus,
weight = 0f
}
+ val description = grade.getJsonArray("Comments")?.asJsonObjectList()?.let { comments ->
+ if (comments.isNotEmpty()) {
+ data.gradeCategories.singleOrNull {
+ it.type == GradeCategory.TYPE_COMMENT
+ && it.categoryId == comments[0].asJsonObject.getLong("Id")
+ }?.text
+ } else null
+ } ?: ""
+
val gradeObject = Grade(
profileId,
id,
categoryName,
color,
- "",
+ description,
name,
value,
weight,
diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/grades/GradeCategory.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/grades/GradeCategory.java
index 24e89359..442a384a 100644
--- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/grades/GradeCategory.java
+++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/grades/GradeCategory.java
@@ -1,10 +1,10 @@
package pl.szczodrzynski.edziennik.data.db.modules.grades;
+import androidx.room.Entity;
+
import java.util.ArrayList;
import java.util.List;
-import androidx.room.Entity;
-
@Entity(tableName = "gradeCategories",
primaryKeys = {"profileId", "categoryId"})
public class GradeCategory {
@@ -25,6 +25,9 @@ public class GradeCategory {
*/
public int type = 0;
+ public static final int TYPE_NORMAL = 0;
+ public static final int TYPE_COMMENT = 1;
+
public GradeCategory(int profileId, long categoryId, float weight, int color, String text) {
this.profileId = profileId;
this.categoryId = categoryId;
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d85c9df2..210529bb 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1027,4 +1027,5 @@
Synchronizacja ręczna
(brak nazwy)
Więcej opcji
+ Pobieranie komentarzy ocen...