Skip to content

Commit

Permalink
actions: refactor RealmMyLibrary model to kotlin (fixes open-learni…
Browse files Browse the repository at this point in the history
  • Loading branch information
Okuro3499 and dogi authored Dec 6, 2023
1 parent c221b6b commit f0ce7ac
Show file tree
Hide file tree
Showing 23 changed files with 570 additions and 845 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 1190
versionName "0.11.90"
versionCode 1191
versionName "0.11.91"
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 @@ -99,7 +99,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {

fun openIntent(items: RealmMyLibrary, typeClass: Class<*>?) {
val fileOpenIntent = Intent(activity, typeClass)
if (items.resourceLocalAddress.contains("ole/audio") || items.resourceLocalAddress.contains(
if (items.resourceLocalAddress!!.contains("ole/audio") || items.resourceLocalAddress!!.contains(
"ole/video"
)
) {
Expand All @@ -118,7 +118,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun openResource(items: RealmMyLibrary) {
if (items.resourceOffline != null && items.isResourceOffline) {
if (items.resourceOffline != null && items.isResourceOffline()) {
openFileType(items, "offline")
} else if (FileUtils.getFileExtension(items.resourceLocalAddress) == "mp4") {
openFileType(items, "online")
Expand All @@ -131,7 +131,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
}

fun checkFileExtension(items: RealmMyLibrary) {
val filenameArray = items.resourceLocalAddress.split("\\.".toRegex()).toTypedArray()
val filenameArray = items.resourceLocalAddress!!.split("\\.".toRegex()).toTypedArray()
val extension = filenameArray[filenameArray.size - 1]
val mimetype = Utilities.getMimeType(items.resourceLocalAddress)
if (mimetype.contains("image")) {
Expand Down Expand Up @@ -256,7 +256,7 @@ abstract class BaseContainerFragment : BaseResourceFragment() {
tv.setCompoundDrawablesWithIntrinsicBounds(
0,
0,
if (library!!.isResourceOffline) R.drawable.ic_eye else R.drawable.ic_download,
if (library!!.isResourceOffline()) R.drawable.ic_eye else R.drawable.ic_download,
0
)
tv.text = library.title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public void addToMyList() {
for (int i = 0; i < selectedItems.size(); i++) {
RealmObject object = (RealmObject) selectedItems.get(i);
if (object instanceof RealmMyLibrary) {
RealmMyLibrary myObject = mRealm.where(RealmMyLibrary.class).equalTo("resourceId", ((RealmMyLibrary) object).getResource_id()).findFirst();
RealmMyLibrary myObject = mRealm.where(RealmMyLibrary.class).equalTo("resourceId", ((RealmMyLibrary) object).resourceId).findFirst();
RealmMyLibrary.createFromResource(myObject, mRealm, model.getId());
RealmRemovedLog.onAdd(mRealm, "resources", profileDbHandler.getUserModel().getId(), myObject.getResourceId());
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());
Expand Down Expand Up @@ -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).getTitle() : ((RealmMyCourse) l).getCourseTitle();
String title = c == RealmMyLibrary.class ? ((RealmMyLibrary) l).title : ((RealmMyCourse) l).getCourseTitle();
boolean isExists = false;
for (String q : query) {
isExists = title.toLowerCase().contains(q.toLowerCase());
Expand Down Expand Up @@ -219,7 +219,7 @@ public List<RealmMyCourse> filterCourseByTag(String s, List<RealmTag> tags) {

private void filter(List<RealmTag> tags, RealmMyLibrary library, RealmList<RealmMyLibrary> libraries) {
for (RealmTag tg : tags) {
long count = mRealm.where(RealmTag.class).equalTo("db", "resources").equalTo("tagId", tg.getId()).equalTo("linkId", library.getId()).count();
long count = mRealm.where(RealmTag.class).equalTo("db", "resources").equalTo("tagId", tg.getId()).equalTo("linkId", library.id).count();
if (count > 0 && !libraries.contains(library)) libraries.add(library);
}
}
Expand Down Expand Up @@ -247,10 +247,10 @@ public List<RealmMyCourse> applyCourseFilter(List<RealmMyCourse> courses) {
}

private boolean isValidFilter(RealmMyLibrary l) {
boolean sub = subjects.isEmpty() || l.getSubject().containsAll(subjects);
boolean lev = levels.isEmpty() || l.getLevel().containsAll(levels);
boolean lan = languages.isEmpty() || languages.contains(l.getLanguage());
boolean med = mediums.isEmpty() || mediums.contains(l.getMediaType());
boolean sub = subjects.isEmpty() || l.subject.containsAll(subjects);
boolean lev = levels.isEmpty() || l.level.containsAll(levels);
boolean lan = languages.isEmpty() || languages.contains(l.language);
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 @@ -190,7 +190,7 @@ public void createListView(List<RealmMyLibrary> db_myLibrary, AlertDialog alertD
lv = convertView.findViewById(R.id.alertDialog_listView);
ArrayList<String> names = new ArrayList<>();
for (int i = 0; i < db_myLibrary.size(); i++) {
names.add(db_myLibrary.get(i).getTitle());
names.add(db_myLibrary.get(i).title);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), R.layout.rowlayout, R.id.checkBoxRowLayout, names);
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Expand Down Expand Up @@ -259,9 +259,9 @@ public void onPause() {

public void removeFromShelf(RealmObject object) {
if (object instanceof RealmMyLibrary) {
RealmMyLibrary myObject = mRealm.where(RealmMyLibrary.class).equalTo("resourceId", ((RealmMyLibrary) object).getResource_id()).findFirst();
RealmMyLibrary myObject = mRealm.where(RealmMyLibrary.class).equalTo("resourceId", ((RealmMyLibrary) object).resourceId).findFirst();
myObject.removeUserId(model.getId());
RealmRemovedLog.onRemove(mRealm, "resources", model.getId(), ((RealmMyLibrary) object).getResource_id());
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void uploadAttachment(String id, String rev, RealmMyPersonal personal, Su
}

public void uploadAttachment(String id, String rev, RealmMyLibrary personal, SuccessListener listener) {
File f = new File(personal.getResourceLocalAddress());
String name = FileUtils.getFileNameFromUrl(personal.getResourceLocalAddress());
File f = new File(personal.resourceLocalAddress);
String name = FileUtils.getFileNameFromUrl(personal.resourceLocalAddress);

upload_doc(id, rev, "%s/resources/%s/%s", f, name, listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ private void changeOfflineStatus() {
mRealm.executeTransaction(realm -> {
RealmMyLibrary obj = realm.where(RealmMyLibrary.class).equalTo("resourceLocalAddress", currentFileName).findFirst();
if (obj != null) {
obj.setResourceOffline(true);
obj.setDownloadedRev(obj.get_rev());
obj.resourceOffline = true;
obj.downloadedRev = obj.get_rev();
} else {
Utilities.log("object Is null");
}
Expand Down
Loading

0 comments on commit f0ce7ac

Please sign in to comment.