[Android] Implement the missing ML folder/group query by id

Nicolas Pomepuy git at videolan.org
Thu Feb 22 13:29:24 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Jan 26 14:15:38 2024 +0100| [b671efce241bde507b24e56515fc7db407f0876b] | committer: Nicolas Pomepuy

Implement the missing ML folder/group query by id

> https://code.videolan.org/videolan/vlc-android/commit/b671efce241bde507b24e56515fc7db407f0876b
---

 medialibrary/jni/medialibrary.cpp                   | 21 +++++++++++++++++++++
 .../org/videolan/medialibrary/MedialibraryImpl.java | 12 ++++++++++++
 .../medialibrary/interfaces/Medialibrary.java       |  3 +++
 .../medialibrary/stubs/StubMedialibrary.java        | 10 ++++++++++
 4 files changed, 46 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 2e817092f9..98e7fefde4 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1848,6 +1848,17 @@ folders(JNIEnv* env, jobject thiz, jint type, jint sortingCriteria, jboolean des
     return foldersRefs;
 }
 
+jobject
+getFolder(JNIEnv* env, jobject thiz, jint type, jlong id) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    medialibrary::FolderPtr folder = aml->folder(id);
+    if (folder == nullptr) return nullptr;
+    const auto query = aml->mediaFromFolder(folder.get(), (medialibrary::IMedia::Type)type);
+    int count = (query != nullptr ? query->count() : 0);
+    return convertFolderObject(env, &ml_fields, folder, count).release();;
+}
+
+
 jint
 foldersCount(JNIEnv* env, jobject thiz, jint type) {
     const auto query = MediaLibrary_getInstance(env, thiz)->folders(nullptr, (medialibrary::IMedia::Type)type);
@@ -2065,6 +2076,14 @@ createMediaGroup(JNIEnv* env, jobject thiz, jlongArray mediaIds)
     return convertVideoGroupObject(env, &ml_fields, group).release();
 }
 
+jobject
+getMediaGroup(JNIEnv* env, jobject thiz, jlong id) {
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
+    medialibrary::MediaGroupPtr media = aml->videoGroup(id);
+    if (media == nullptr) return nullptr;
+    return convertVideoGroupObject(env, &ml_fields, media).release();;
+}
+
 jboolean regroupAll(JNIEnv* env, jobject thiz)
 {
     return MediaLibrary_getInstance(env, thiz)->regroupAll();
@@ -2515,6 +2534,7 @@ static JNINativeMethod methods[] = {
     {"nativeGetPlaylist", "(JZZ)Lorg/videolan/medialibrary/interfaces/media/Playlist;", (void*)getPlaylist },
     {"nativeGetFolders", "(IIZZZII)[Lorg/videolan/medialibrary/interfaces/media/Folder;", (void*)folders },
     {"nativeGetFoldersCount", "(I)I", (void*)foldersCount },
+    {"nativeGetFolder", "(IJ)Lorg/videolan/medialibrary/interfaces/media/Folder;", (void*)getFolder },
     {"nativeSearchPagedFolders", "(Ljava/lang/String;IZZZII)[Lorg/videolan/medialibrary/interfaces/media/Folder;", (void*)searchFolders },
     {"nativeGetSearchFoldersCount", "(Ljava/lang/String;)I", (void*)getSearchFoldersCount },
     {"nativePauseBackgroundOperations", "()V", (void*)pauseBackgroundOperations },
@@ -2533,6 +2553,7 @@ static JNINativeMethod methods[] = {
     {"nativeCreateGroupByName", "(Ljava/lang/String;)Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)createMediaGroupByName },
     {"nativeSearchPagedGroups", "(Ljava/lang/String;IZZZII)[Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)searchMediaGroups },
     {"nativeCreateGroup", "([J)Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)createMediaGroup },
+    {"nativeGetGroup", "(J)Lorg/videolan/medialibrary/interfaces/media/VideoGroup;", (void*)getMediaGroup },
     {"nativeRegroupAll", "()Z", (void*)regroupAll },
     {"nativeRegroup", "(J)Z", (void*)regroup },
     {"nativeGetService", "(I)Lorg/videolan/medialibrary/interfaces/media/MlService;", (void*)getService},
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index bbf90df6ef..ca558b7393 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -267,6 +267,11 @@ public class MedialibraryImpl extends Medialibrary {
         return mIsInitiated && (ids.length != 0) ? nativeCreateGroup(ids) : null;
     }
 
+    @Override
+    public VideoGroup getVideoGroup(long id) {
+        return mIsInitiated ? nativeGetGroup(id) : null;
+    }
+
     @Override
     public boolean regroupAll() {
         return mIsInitiated && nativeRegroupAll();
@@ -481,6 +486,11 @@ public class MedialibraryImpl extends Medialibrary {
         return mIsInitiated ? nativeGetFolders(type, sort, desc, includeMissing, onlyFavorites, nbItems, offset) : new Folder[0];
     }
 
+    @Override
+    public Folder getFolder(int type, long id) {
+        return mIsInitiated ? nativeGetFolder(type, id) : null;
+    }
+
     @WorkerThread
     public int getFoldersCount(int type) {
         return mIsInitiated ? nativeGetFoldersCount(type) : 0;
@@ -691,6 +701,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native VideoGroup nativeCreateGroupByName(String name);
 
     private native VideoGroup nativeCreateGroup(long[] ids);
+    private native VideoGroup nativeGetGroup(long id);
 
     private native boolean nativeRegroupAll();
 
@@ -713,6 +724,7 @@ public class MedialibraryImpl extends Medialibrary {
     private native Playlist nativeGetPlaylist(long playlistId, boolean includeMissing, boolean onlyFavorites);
     private native Playlist nativePlaylistCreate(String name, boolean includeMissing, boolean onlyFavorites);
     private native Folder[] nativeGetFolders(int type, int sort, boolean desc, boolean includeMissing, boolean onlyFavorites, int nbItems, int offset);
+    private native Folder nativeGetFolder(int type, long id);
     private native int nativeGetFoldersCount(int type);
     private native void nativePauseBackgroundOperations();
     private native void nativeResumeBackgroundOperations();
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
index 724bd08a0e..aef75e3ad9 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/Medialibrary.java
@@ -770,6 +770,8 @@ abstract public class Medialibrary {
 
     abstract public VideoGroup createVideoGroup(long[] ids);
 
+    abstract public VideoGroup getVideoGroup(long id);
+
     abstract public boolean regroupAll();
 
     abstract public boolean regroup(long mediaId);
@@ -816,6 +818,7 @@ abstract public class Medialibrary {
     abstract public boolean flushUserProvidedThumbnails();
     abstract public MediaWrapper addStream(String mrl, String title);
     abstract public Folder[] getFolders(int type, int sort, boolean desc, boolean includeMissing, boolean onlyFavorites, int nbItems, int offset);
+    abstract public Folder getFolder(int type, long id);
     abstract public int getFoldersCount(int type);
     abstract public int setLastTime(long mediaId, long time);
     abstract public boolean setLastPosition(long mediaId, float position);
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
index 5d68fef218..58b1ee898d 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMedialibrary.java
@@ -186,6 +186,11 @@ public class StubMedialibrary extends Medialibrary {
         return null;
     }
 
+    @Override
+    public VideoGroup getVideoGroup(long id) {
+        return null;
+    }
+
     @Override
     public boolean regroupAll() {
         return false;
@@ -490,6 +495,11 @@ public class StubMedialibrary extends Medialibrary {
         return folders.toArray(new Folder[0]);
     }
 
+    @Override
+    public Folder getFolder(int type, long id) {
+        return null;
+    }
+
     public int getFoldersCount(int type) {
         return getFolders(type, 0, false, true, false, 0, 0).length;
     }



More information about the Android mailing list