Skip to content

Commit

Permalink
[API/Librus] Add Librus descriptive grades ("Bieżące oceny opisowe") …
Browse files Browse the repository at this point in the history
…support.
  • Loading branch information
kuba2k2 committed Sep 24, 2019
1 parent 1a2b51f commit df52029
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion app/src/main/java/pl/szczodrzynski/edziennik/api/Librus.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public void sync(@NonNull Context activityContext, @NonNull SyncCallback callbac
targetEndpoints.add("Grades");
targetEndpoints.add("PointGrades");
targetEndpoints.add("DescriptiveGrades");
targetEndpoints.add("TextGrades");
targetEndpoints.add("BehaviourGrades");

targetEndpoints.add("Events");
Expand Down Expand Up @@ -359,6 +360,7 @@ public void syncFeature(@NonNull Context activityContext, @NonNull SyncCallback
targetEndpoints.add("Grades");
targetEndpoints.add("PointGrades");
targetEndpoints.add("DescriptiveGrades");
targetEndpoints.add("TextGrades");
targetEndpoints.add("BehaviourGrades");
break;
case FEATURE_HOMEWORKS:
Expand Down Expand Up @@ -498,6 +500,9 @@ private void r(String type, String endpoint) {
case "DescriptiveGrades":
getDescriptiveGrades();
break;
case "TextGrades":
getTextGrades();
break;
case "BehaviourGrades":
getBehaviourGrades();
break;
Expand Down Expand Up @@ -644,7 +649,7 @@ public void onAuthorizationCode(String code) {
};

librusLoginCallback = redirectUrl -> {
fakeAuthorize = "authorize2";
fakeAuthorize = "authorize";
authorize(AUTHORIZE_URL, authorizeCallback);
};

Expand Down Expand Up @@ -2389,6 +2394,62 @@ private void getDescriptiveGrades() {
});
}

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) {
Expand Down

0 comments on commit df52029

Please sign in to comment.