From df52029a29b5d3cf394b2ad692faf80f4ed3e22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Tue, 24 Sep 2019 21:45:49 +0200 Subject: [PATCH] =?UTF-8?q?[API/Librus]=20Add=20Librus=20descriptive=20gra?= =?UTF-8?q?des=20("Bie=C5=BC=C4=85ce=20oceny=20opisowe")=20support.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../szczodrzynski/edziennik/api/Librus.java | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java b/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java index 592131ad..908c845b 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java @@ -288,6 +288,7 @@ public class Librus implements EdziennikInterface { targetEndpoints.add("Grades"); targetEndpoints.add("PointGrades"); targetEndpoints.add("DescriptiveGrades"); + targetEndpoints.add("TextGrades"); targetEndpoints.add("BehaviourGrades"); targetEndpoints.add("Events"); @@ -359,6 +360,7 @@ public class Librus implements EdziennikInterface { targetEndpoints.add("Grades"); targetEndpoints.add("PointGrades"); targetEndpoints.add("DescriptiveGrades"); + targetEndpoints.add("TextGrades"); targetEndpoints.add("BehaviourGrades"); break; case FEATURE_HOMEWORKS: @@ -498,6 +500,9 @@ public class Librus implements EdziennikInterface { case "DescriptiveGrades": getDescriptiveGrades(); break; + case "TextGrades": + getTextGrades(); + break; case "BehaviourGrades": getBehaviourGrades(); break; @@ -644,7 +649,7 @@ public class Librus implements EdziennikInterface { }; librusLoginCallback = redirectUrl -> { - fakeAuthorize = "authorize2"; + fakeAuthorize = "authorize"; authorize(AUTHORIZE_URL, authorizeCallback); }; @@ -2389,6 +2394,62 @@ public class Librus implements EdziennikInterface { }); } + private void getTextGrades() { + callback.onActionStarted(R.string.sync_action_syncing_descriptive_grades); + apiRequest("DescriptiveGrades", data -> { + if (data == null) { + r("finish", "TextGrades"); + return; + } + JsonArray grades = data.get("Grades").getAsJsonArray(); + //d("Got Grades: "+grades.toString()); + for (JsonElement gradeEl : grades) { + JsonObject grade = gradeEl.getAsJsonObject(); + long id = grade.get("Id").getAsLong(); + long teacherId = grade.get("AddedBy").getAsJsonObject().get("Id").getAsLong(); + int semester = grade.get("Semester").getAsInt(); + long subjectId = grade.get("Subject").getAsJsonObject().get("Id").getAsLong(); + String description = grade.get("Map").getAsString(); + + long categoryId = -1; + JsonElement skillEl = grade.get("Skill"); + if (skillEl != null) { + categoryId = skillEl.getAsJsonObject().get("Id").getAsLong(); + } + + String str_date = grade.get("AddDate").getAsString(); + long addedDate = Date.fromIso(str_date); + + String category = ""; + int color = -1; + GradeCategory gradeCategory = GradeCategory.search(gradeCategoryList, categoryId); + if (gradeCategory != null) { + category = gradeCategory.text; + color = gradeCategory.color; + } + + Grade gradeObject = new Grade( + profileId, + id, + category, + color, + "", + description, + 0.0f, + 0, + semester, + teacherId, + subjectId + ); + gradeObject.type = Grade.TYPE_DESCRIPTIVE; + + gradeList.add(gradeObject); + metadataList.add(new Metadata(profileId, Metadata.TYPE_GRADE, gradeObject.id, profile.getEmpty(), profile.getEmpty(), addedDate)); + } + r("finish", "TextGrades"); + }); + } + private void getBehaviourGrades() { d(TAG, "Grades settings: "+enableStandardGrades+", "+enablePointGrades+", "+enableDescriptiveGrades); if (!enableBehaviourGrades) {