[Android] medialibrary: Avoid folder -> id -> folder conversions

Hugo Beauzée-Luyssen git at videolan.org
Thu Jan 6 14:38:03 UTC 2022


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Mon Nov 29 10:32:22 2021 +0100| [22511387c9c0ca689716e49c7e4ce70f5ec0c949] | committer: Nicolas Pomepuy

medialibrary: Avoid folder -> id -> folder conversions

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

 medialibrary/jni/AndroidMediaLibrary.cpp |  3 +--
 medialibrary/jni/AndroidMediaLibrary.h   |  2 +-
 medialibrary/jni/medialibrary.cpp        | 13 ++++++++-----
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 9141cedc0..d9de420fa 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -544,9 +544,8 @@ AndroidMediaLibrary::folders(const medialibrary::QueryParameters* params, medial
 }
 
 medialibrary::Query<medialibrary::IMedia>
-AndroidMediaLibrary::mediaFromFolder(int64_t folderId, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params )
+AndroidMediaLibrary::mediaFromFolder(const medialibrary::IFolder* folder, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params )
 {
-    medialibrary::FolderPtr folder = p_ml->folder(folderId);
     return folder != nullptr ? folder->media(type, params) : nullptr;
 }
 
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 79a10f3c9..7be9b3b79 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -107,7 +107,7 @@ public:
     medialibrary::Query<medialibrary::IArtist> artistsFromGenre( int64_t genreId, const medialibrary::QueryParameters* params = nullptr );
     medialibrary::Query<medialibrary::IMedia> mediaFromPlaylist( int64_t playlistId, const medialibrary::QueryParameters* params = nullptr );
     // Folders
-    medialibrary::Query<medialibrary::IMedia> mediaFromFolder(int64_t folderId, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params = nullptr );
+    medialibrary::Query<medialibrary::IMedia> mediaFromFolder(const medialibrary::IFolder* folder, medialibrary::IMedia::Type type, const medialibrary::QueryParameters* params = nullptr );
     medialibrary::Query<medialibrary::IFolder> folders(const medialibrary::QueryParameters* params = nullptr, medialibrary::IMedia::Type type = medialibrary::IMedia::Type::Unknown );
     medialibrary::Query<medialibrary::IFolder> subFolders(int64_t folderId, const medialibrary::QueryParameters* params = nullptr );
     medialibrary::FolderPtr folder(int64_t folderId);
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index c5a12edde..2dc97af8f 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -1657,7 +1657,8 @@ jobjectArray
 mediaFromFolder(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint type, jint sortingCriteria, jboolean desc, jboolean includeMissing,  jint nbItems,  jint offset ) {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
     medialibrary::QueryParameters params = generateParams(sortingCriteria, desc, includeMissing);
-    const auto query = aml->mediaFromFolder(id, (medialibrary::IMedia::Type)type, &params);
+    auto folder = aml->folder(id);
+    const auto query = aml->mediaFromFolder(folder.get(), (medialibrary::IMedia::Type)type, &params);
     if (query == nullptr) return (jobjectArray) env->NewObjectArray(0, ml_fields.MediaWrapper.clazz, NULL);
     std::vector<medialibrary::MediaPtr> mediaList = nbItems != 0 ? query->items(nbItems, offset) : query->all();
     jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mediaList.size(), ml_fields.MediaWrapper.clazz, NULL);
@@ -1671,7 +1672,9 @@ mediaFromFolder(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint
 
 jint
 mediaFromFolderCount(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint type) {
-    const auto query = MediaLibrary_getInstance(env, medialibrary)->mediaFromFolder(id, (medialibrary::IMedia::Type)type);
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
+    auto folder = aml->folder(id);
+    const auto query = aml->mediaFromFolder(folder.get(), (medialibrary::IMedia::Type)type);
     return (jint) (query != nullptr ? query->count() : 0);
 }
 
@@ -1716,7 +1719,7 @@ subFolders(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id, jint sorti
     jobjectArray foldersRefs = (jobjectArray) env->NewObjectArray(foldersList.size(), ml_fields.Folder.clazz, NULL);
     int index = -1;
     for(medialibrary::FolderPtr const& folder : foldersList) {
-        const auto query = aml->mediaFromFolder(folder->id(), medialibrary::IMedia::Type::Video);
+        const auto query = aml->mediaFromFolder(folder.get(), medialibrary::IMedia::Type::Video);
         int count = (query != nullptr ? query->count() : 0);
 
         auto item = convertFolderObject(env, &ml_fields, folder, count);
@@ -1743,7 +1746,7 @@ folders(JNIEnv* env, jobject thiz, jint type, jint sortingCriteria, jboolean des
     for(medialibrary::FolderPtr const& folder : foldersList) {
         try
         {
-            const auto query = aml->mediaFromFolder(folder->id(), (medialibrary::IMedia::Type)type);
+            const auto query = aml->mediaFromFolder(folder.get(), (medialibrary::IMedia::Type)type);
             int count = (query != nullptr ? query->count() : 0);
 
             auto item = convertFolderObject(env, &ml_fields, folder, count);
@@ -1821,7 +1824,7 @@ searchFolders(JNIEnv* env, jobject thiz, jstring queryString, jint sortingCriter
     int index = -1;
     for(medialibrary::FolderPtr const& folder : folders)
     {
-        const auto query = aml->mediaFromFolder(folder->id(), medialibrary::IMedia::Type::Video);
+        const auto query = aml->mediaFromFolder(folder.get(), medialibrary::IMedia::Type::Video);
         int count = (query != nullptr ? query->count() : 0);
         auto item = convertFolderObject(env, &ml_fields, folder, count);
         env->SetObjectArrayElement(folderRefs, ++index, item.get());



More information about the Android mailing list