From 554097fc7d0fee6f5611f1f3e8aeb564d45f047a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Wed, 25 Sep 2019 21:40:03 +0200 Subject: [PATCH] [API/Librus] Fix r() IndexOutOfBounds. Fix Descriptive grades NPE. --- .../pl/szczodrzynski/edziennik/api/Librus.java | 14 +++++++++++++- 1 file changed, 13 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 908c845b..ca231ebf 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java @@ -435,6 +435,10 @@ public class Librus implements EdziennikInterface { callback.onProgress(PROGRESS_STEP); index++; } + if (index > targetEndpoints.size()) { + finish(); + return; + } d(TAG, "Called r("+type+", "+endpoint+"). Getting "+targetEndpoints.get(index)); switch (targetEndpoints.get(index)) { case "Me": @@ -2409,7 +2413,15 @@ public class Librus implements EdziennikInterface { 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(); + JsonElement map = grade.get("Map"); + JsonElement realGrade = grade.get("RealGradeValue"); + String description = ""; + if (map != null) { + description = map.getAsString(); + } + else if (realGrade != null) { + description = realGrade.getAsString(); + } long categoryId = -1; JsonElement skillEl = grade.get("Skill");