[Android] Medialibrary folders: add count methods for paging

Geoffrey Métais git at videolan.org
Wed Oct 31 18:19:33 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Oct 31 18:19:11 2018 +0100| [c2bee28184f66d0046d3951179a7d4977d9601bc] | committer: Geoffrey Métais

Medialibrary folders: add count methods for paging

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

 medialibrary/jni/AndroidMediaLibrary.cpp            |  2 +-
 medialibrary/jni/AndroidMediaLibrary.h              | 18 +++++++++---------
 medialibrary/jni/medialibrary.cpp                   | 21 +++++++++++++++++++++
 .../src/org/videolan/medialibrary/Medialibrary.java |  6 ++++++
 .../src/org/videolan/medialibrary/media/Folder.java | 18 ++++++++++++++++--
 5 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index f34a92908..67fcc5ccb 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -467,7 +467,7 @@ AndroidMediaLibrary::PlaylistDelete( int64_t playlistId )
 medialibrary::Query<medialibrary::IFolder>
 AndroidMediaLibrary::folders(const medialibrary::QueryParameters* params )
 {
-    return p_ml->folders();
+    return p_ml->folders(params);
 }
 
 medialibrary::Query<medialibrary::IMedia>
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index d09b4aac7..2ff193ec0 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -84,17 +84,17 @@ public:
     medialibrary::Query<medialibrary::IPlaylist> playlists(const medialibrary::QueryParameters* params);
     medialibrary::PlaylistPtr playlist( int64_t playlistId );
     medialibrary::PlaylistPtr PlaylistCreate( const std::string &name );
-    medialibrary::Query<medialibrary::IMedia> tracksFromAlbum( int64_t albumId, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IMedia> mediaFromArtist( int64_t artistId, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IAlbum> albumsFromArtist( int64_t artistId, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IMedia> mediaFromGenre( int64_t genreId, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IAlbum> albumsFromGenre( int64_t genreId, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IArtist> artistsFromGenre( int64_t genreId, const medialibrary::QueryParameters* params );
+    medialibrary::Query<medialibrary::IMedia> tracksFromAlbum( int64_t albumId, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IMedia> mediaFromArtist( int64_t artistId, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IAlbum> albumsFromArtist( int64_t artistId, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IMedia> mediaFromGenre( int64_t genreId, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IAlbum> albumsFromGenre( int64_t genreId, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IArtist> artistsFromGenre( int64_t genreId, const medialibrary::QueryParameters* params = nullptr );
     medialibrary::Query<medialibrary::IMedia> mediaFromPlaylist( int64_t playlistId );
     // Folders
-    medialibrary::Query<medialibrary::IMedia> mediaFromFolder(int64_t folderId, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IFolder> folders(const medialibrary::QueryParameters* params );
-    medialibrary::Query<medialibrary::IFolder> subFolders(int64_t folderId, const medialibrary::QueryParameters* params );
+    medialibrary::Query<medialibrary::IMedia> mediaFromFolder(int64_t folderId, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IFolder> folders(const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IFolder> subFolders(int64_t folderId, const medialibrary::QueryParameters* params = nullptr );
     //PLaylists
     bool playlistAppend(int64_t playlistId, int64_t mediaId);
     bool playlistAdd(int64_t playlistId, int64_t mediaId, unsigned int position);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 63686b009..9e1acbc44 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1607,6 +1607,12 @@ mediaFromFolder(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, media
     return mediaRefs;
 }
 
+jint
+mediaFromFolderCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, medialibrary::IMedia::Type type) {
+    const auto query = MediaLibrary_getInstance(env, medialibrary)->mediaFromFolder(id, type);
+    return (jint) (query != nullptr ? query->count() : 0);
+}
+
 jobjectArray
 subFolders(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint sortingCriteria, jboolean desc, jint nbItems,  jint offset ) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
@@ -1627,6 +1633,12 @@ subFolders(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint sorti
     return foldersRefs;
 }
 
+jint
+subFoldersCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id) {
+    const auto query = MediaLibrary_getInstance(env, medialibrary)->subFolders(id);
+    return (jint) (query != nullptr ? query->count() : 0);
+}
+
 jobjectArray
 folders(JNIEnv* env, jobject thiz, jint sortingCriteria, jboolean desc, jint nbItems,  jint offset ) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
@@ -1647,6 +1659,12 @@ folders(JNIEnv* env, jobject thiz, jint sortingCriteria, jboolean desc, jint nbI
     return foldersRefs;
 }
 
+jint
+foldersCount(JNIEnv* env, jobject thiz) {
+    const auto query = MediaLibrary_getInstance(env, thiz)->folders();
+    return (jint) (query != nullptr ? query->count() : 0);
+}
+
  /*
   * JNI stuff
   */
@@ -1716,6 +1734,7 @@ static JNINativeMethod methods[] = {
     {"nativeGetPlaylistsCount", "()I", (void*)getPlaylistsCount },
     {"nativeGetPlaylist", "(J)Lorg/videolan/medialibrary/media/Playlist;", (void*)getPlaylist },
     {"nativeGetFolders", "(IZII)[Lorg/videolan/medialibrary/media/Folder;", (void*)folders },
+    {"nativeGetFoldersCount", "()I", (void*)foldersCount },
     {"nativePauseBackgroundOperations", "()V", (void*)pauseBackgroundOperations },
     {"nativeResumeBackgroundOperations", "()V", (void*)resumeBackgroundOperations },
     {"nativeReload", "()V", (void*)reload },
@@ -1778,6 +1797,8 @@ static JNINativeMethod genre_methods[] = {
 static JNINativeMethod folder_methods[] = {
     {"nativeMedia", "(Lorg/videolan/medialibrary/Medialibrary;JIIZII)[Lorg/videolan/medialibrary/media/MediaWrapper;", (void*)mediaFromFolder },
     {"nativeSubfolders", "(Lorg/videolan/medialibrary/Medialibrary;JIZII)[Lorg/videolan/medialibrary/media/Folder;", (void*)subFolders },
+    {"nativeMediaCount", "(Lorg/videolan/medialibrary/Medialibrary;JI)I", (void*)mediaFromFolderCount },
+    {"nativeSubfoldersCount", "(Lorg/videolan/medialibrary/Medialibrary;J)I", (void*)subFoldersCount },
 };
 
 static JNINativeMethod playlist_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index d230aca64..5e3e10d81 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -420,6 +420,11 @@ public class Medialibrary {
         return mIsInitiated ? nativeGetFolders(sort, desc, nbItems, offset) : new Folder[0];
     }
 
+    @Nullable
+    public int getFoldersCount() {
+        return mIsInitiated ? nativeGetFoldersCount() : 0;
+    }
+
     public void requestThumbnail(long id) {
         if (mIsInitiated) nativeRequestThumbnail(id);
     }
@@ -935,6 +940,7 @@ public class Medialibrary {
     private native Playlist nativeGetPlaylist(long playlistId);
     private native Playlist nativePlaylistCreate(String name);
     private native Folder[] nativeGetFolders(int sort, boolean desc, int nbItems, int offset);
+    private native int nativeGetFoldersCount();
     private native void nativePauseBackgroundOperations();
     private native void nativeResumeBackgroundOperations();
     private native void nativeReload();
diff --git a/medialibrary/src/org/videolan/medialibrary/media/Folder.java b/medialibrary/src/org/videolan/medialibrary/media/Folder.java
index a88759293..1261b5e07 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/Folder.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/Folder.java
@@ -30,17 +30,31 @@ public class Folder extends MediaLibraryItem {
     }
 
     public MediaWrapper[] media(int type, int sort, boolean desc, int nbItems, int offset) {
-        return null;
+        final Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeMedia(ml, mId, type, sort, desc, nbItems, offset) : Medialibrary.EMPTY_COLLECTION;
+    }
+
+    public int mediaCount(int type) {
+        final Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeMediaCount(ml, mId, type) : 0;
     }
 
     public Folder[] subfolders(int sort, boolean desc, int nbItems, int offset) {
-        return null;
+        final Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeSubfolders(ml, mId, sort, desc, nbItems, offset) : new Folder[0];
+    }
+
+    public int subfoldersCount() {
+        final Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() ? nativeSubfoldersCount(ml, mId) : 0;
     }
 
 //    private native MediaWrapper[] nativeGetTracks();
 //    private native int nativeGetTracksCount();
     private native MediaWrapper[] nativeMedia(Medialibrary ml, long mId, int type, int sort, boolean desc, int nbItems, int offset);
+    private native int nativeMediaCount(Medialibrary ml, long mId, int type);
     private native Folder[] nativeSubfolders(Medialibrary ml, long mId, int sort, boolean desc, int nbItems, int offset);
+    private native int nativeSubfoldersCount(Medialibrary ml, long mId);
 
     @Override
     public void writeToParcel(Parcel parcel, int i) {



More information about the Android mailing list