From 3f85825c4a49ad579a58503d66cc5aaa72a0fc6d Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Thu, 17 Oct 2019 15:07:06 +0200 Subject: [PATCH] [API/Librus] Add showing classroom in substitutions --- .../edziennik/data/api/Librus.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java index 860219a7..5c7356e2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java @@ -277,8 +277,8 @@ public class Librus implements EdziennikInterface { targetEndpoints.add("Users"); targetEndpoints.add("Subjects"); targetEndpoints.add("Classrooms"); - targetEndpoints.add("Timetables"); targetEndpoints.add("Substitutions"); + targetEndpoints.add("Timetables"); targetEndpoints.add("Colors"); targetEndpoints.add("SavedGradeCategories"); @@ -346,8 +346,8 @@ public class Librus implements EdziennikInterface { switch (feature) { case FEATURE_TIMETABLE: targetEndpoints.add("Classrooms"); - targetEndpoints.add("Timetables"); targetEndpoints.add("Substitutions"); + targetEndpoints.add("Timetables"); break; case FEATURE_AGENDA: targetEndpoints.add("Events"); @@ -1663,6 +1663,7 @@ public class Librus implements EdziennikInterface { try { for (Map.Entry dayEl: timetables.entrySet()) { JsonArray day = dayEl.getValue().getAsJsonArray(); + Date lessonDate = Date.fromY_m_d(dayEl.getKey()); for (JsonElement lessonGroupEl: day) { if ((lessonGroupEl instanceof JsonArray && ((JsonArray) lessonGroupEl).size() == 0) || lessonGroupEl instanceof JsonNull || lessonGroupEl == null) { continue; @@ -1737,8 +1738,27 @@ public class Librus implements EdziennikInterface { } JsonElement classroom; - if ((classroom = lesson.get(substitution && !cancelled ? "OrgClassroom" : "Classroom")) != null) { - lessonObject.classroomName = classrooms.get(classroom.getAsJsonObject().get("Id").getAsInt()); + JsonElement substitutionClassroom; + if (substitution && !cancelled) { + classroom = lesson.get("OrgClassroom"); + substitutionClassroom = lesson.get("Classroom"); + + if (classroom != null) + lessonObject.classroomName = classrooms.get(classroom.getAsJsonObject().get("Id").getAsInt()); + + if (substitutionClassroom != null) { + for (LessonChange lessonChange : lessonChangeList) { + if(lessonChange.lessonDate.compareTo(lessonDate) == 0) { + lessonChange.classroomName + = classrooms.get(substitutionClassroom.getAsJsonObject().get("Id").getAsInt()); + break; + } + } + } + } else { + classroom = lesson.get("Classroom"); + if (classroom != null) + lessonObject.classroomName = classrooms.get(classroom.getAsJsonObject().get("Id").getAsInt()); } lessonList.add(lessonObject);