Skip to content

Commit

Permalink
actions: refactor RealmMyCourse model to kotlin (fixes open-learnin…
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 and dogi authored Dec 6, 2023
1 parent f0ce7ac commit fb5c2eb
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 300 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1191
versionName "0.11.91"
versionCode 1192
versionName "0.11.92"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public void addToMyList() {
RealmRemovedLog.onAdd(mRealm, "resources", profileDbHandler.getUserModel().getId(), myObject.resourceId);
Utilities.toast(getActivity(), getString(R.string.added_to_my_library));
} else {
RealmMyCourse myObject = RealmMyCourse.getMyCourse(mRealm, ((RealmMyCourse) object).getCourseId());
RealmMyCourse myObject = RealmMyCourse.getMyCourse(mRealm, ((RealmMyCourse) object).courseId);
RealmMyCourse.createMyCourse(myObject, mRealm, model.getId());
RealmRemovedLog.onAdd(mRealm, "courses", profileDbHandler.getUserModel().getId(), myObject.getCourseId());
RealmRemovedLog.onAdd(mRealm, "courses", profileDbHandler.getUserModel().getId(), myObject.courseId);
Utilities.toast(getActivity(), getString(R.string.added_to_my_courses));
}
}
Expand All @@ -140,8 +140,8 @@ public void deleteSelected(boolean deleteProgress) {

private void deleteCourseProgress(boolean deleteProgress, RealmObject object) {
if (deleteProgress && object instanceof RealmMyCourse) {
mRealm.where(RealmCourseProgress.class).equalTo("courseId", ((RealmMyCourse) object).getCourseId()).findAll().deleteAllFromRealm();
List<RealmStepExam> examList = mRealm.where(RealmStepExam.class).equalTo("courseId", ((RealmMyCourse) object).getCourseId()).findAll();
mRealm.where(RealmCourseProgress.class).equalTo("courseId", ((RealmMyCourse) object).courseId).findAll().deleteAllFromRealm();
List<RealmStepExam> examList = mRealm.where(RealmStepExam.class).equalTo("courseId", ((RealmMyCourse) object).courseId).findAll();
for (RealmStepExam exam : examList) {
mRealm.where(RealmSubmission.class).equalTo("parentId", exam.getId()).notEqualTo("type", "survey").equalTo("uploaded", false).findAll().deleteAllFromRealm();
}
Expand All @@ -156,7 +156,7 @@ public void onDestroy() {

private void checkAndAddToList(RealmMyCourse course, List<RealmMyCourse> courses, List<RealmTag> tags) {
for (RealmTag tg : tags) {
long count = mRealm.where(RealmTag.class).equalTo("db", "courses").equalTo("tagId", tg.getId()).equalTo("linkId", course.getCourseId()).count();
long count = mRealm.where(RealmTag.class).equalTo("db", "courses").equalTo("tagId", tg.getId()).equalTo("linkId", course.courseId).count();
if (count > 0 && !courses.contains(course)) courses.add(course);
}
}
Expand All @@ -176,7 +176,7 @@ private List<LI> getData(String s, Class c) {
}

private void searchAndAddToList(LI l, Class c, String[] query, List<LI> li) {
String title = c == RealmMyLibrary.class ? ((RealmMyLibrary) l).title : ((RealmMyCourse) l).getCourseTitle();
String title = c == RealmMyLibrary.class ? ((RealmMyLibrary) l).title : ((RealmMyCourse) l).courseTitle;
boolean isExists = false;
for (String q : query) {
isExists = title.toLowerCase().contains(q.toLowerCase());
Expand Down Expand Up @@ -239,7 +239,7 @@ public List<RealmMyCourse> applyCourseFilter(List<RealmMyCourse> courses) {
for (RealmMyCourse l : courses) {
Utilities.log("grade " + gradeLevel);
Utilities.log("subject " + subjectLevel);
if (TextUtils.equals(l.getGradeLevel(), gradeLevel) || TextUtils.equals(l.getSubjectLevel(), subjectLevel)) {
if (TextUtils.equals(l.gradeLevel, gradeLevel) || TextUtils.equals(l.subjectLevel, subjectLevel)) {
newList.add(l);
}
}
Expand All @@ -253,4 +253,4 @@ private boolean isValidFilter(RealmMyLibrary l) {
boolean med = mediums.isEmpty() || mediums.contains(l.mediaType);
return (sub && lev && lan && med);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ public void removeFromShelf(RealmObject object) {
RealmRemovedLog.onRemove(mRealm, "resources", model.getId(), ((RealmMyLibrary) object).resourceId);
Utilities.toast(getActivity(), getString(R.string.removed_from_mylibrary));
} else {
RealmMyCourse myObject = RealmMyCourse.getMyCourse(mRealm, ((RealmMyCourse) object).getCourseId());
RealmMyCourse myObject = RealmMyCourse.getMyCourse(mRealm, ((RealmMyCourse) object).courseId);
myObject.removeUserId(model.getId());
RealmRemovedLog.onRemove(mRealm, "courses", model.getId(), ((RealmMyCourse) object).getCourseId());
RealmRemovedLog.onRemove(mRealm, "courses", model.getId(), ((RealmMyCourse) object).courseId);
Utilities.toast(getActivity(), getString(R.string.removed_from_mycourse));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public static HashMap<String, JsonObject> getCourseProgress(Realm mRealm, String
HashMap<String, JsonObject> map = new HashMap<>();
for (RealmMyCourse course : r) {
JsonObject object = new JsonObject();
List<RealmCourseStep> steps = RealmCourseStep.getSteps(mRealm, course.getCourseId());
List<RealmCourseStep> steps = RealmCourseStep.getSteps(mRealm, course.courseId);
object.addProperty("max", steps.size());

object.addProperty("current", getCurrentProgress(steps, mRealm, userId, course.getCourseId()));
if (RealmMyCourse.isMyCourse(userId, course.getCourseId(), mRealm))
map.put(course.getCourseId(), object);
object.addProperty("current", getCurrentProgress(steps, mRealm, userId, course.courseId));
if (RealmMyCourse.isMyCourse(userId, course.courseId, mRealm))
map.put(course.courseId, object);
}
return map;
}
Expand Down
248 changes: 0 additions & 248 deletions app/src/main/java/org/ole/planet/myplanet/model/RealmMyCourse.java

This file was deleted.

Loading

0 comments on commit fb5c2eb

Please sign in to comment.