[Android] MlService: add new refresh API

Duncan McNamara git at videolan.org
Fri Nov 18 12:29:46 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Nov 16 18:39:19 2022 +0100| [01cccf02a26e00f39fd8fc2d44a17e8f56abff03] | committer: Nicolas Pomepuy

MlService: add new refresh API

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

 medialibrary/jni/medialibrary.cpp                             | 11 +++++++++++
 .../org/videolan/medialibrary/interfaces/media/MlService.java |  1 +
 .../src/org/videolan/medialibrary/media/MlServiceImpl.java    |  7 +++++++
 .../src/org/videolan/medialibrary/stubs/StubMlService.java    |  5 +++++
 4 files changed, 24 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 576cc0f2c4..716dba2901 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2281,6 +2281,16 @@ jint sortingCriteria, jboolean desc, jboolean includeMissing)
     return mediaRefs;
 }
 
+jboolean
+serviceRefresh(JNIEnv* env, jobject thiz, jobject ml, jint _type)
+{
+    AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, ml);
+    medialibrary::IService::Type type = (medialibrary::IService::Type)_type;
+    medialibrary::ServicePtr servicePtr = aml->service(type);
+    if (servicePtr == nullptr) return false;
+    return servicePtr->refresh();
+}
+
 /*
  * Subscriptions
  */
@@ -2631,6 +2641,7 @@ static JNINativeMethod service_methods[] = {
     {"nativeGetSubscriptions", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;IIZZ)[Lorg/videolan/medialibrary/interfaces/media/Subscription;", (void*)getSubscriptions},
     {"nativeGetNbMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;I)I", (void*)getNbMedia},
     {"nativeGetServiceMedia", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;IIZZ)[Lorg/videolan/medialibrary/interfaces/media/MediaWrapper;", (void*)getServiceMedia},
+    {"nativeServiceRefresh", "(Lorg/videolan/medialibrary/interfaces/Medialibrary;I)Z", (void*)serviceRefresh},
 };
 
 static JNINativeMethod subscription_methods[] = {
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
index b53055e953..91fb0682ea 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/media/MlService.java
@@ -40,4 +40,5 @@ public abstract class MlService {
     public abstract Subscription[] getSubscriptions(int sort, boolean desc, boolean includeMissing);
     public abstract int getNbMedia();
     public abstract MediaWrapper[] getMedia(int sortingCriteria, boolean desc, boolean includeMissing);
+    public abstract boolean refresh();
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
index e80a44373c..36dc7a3902 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MlServiceImpl.java
@@ -80,6 +80,12 @@ public class MlServiceImpl extends MlService {
         return ml.isInitiated() ? nativeGetServiceMedia(ml, this.type.value, sortingCriteria, desc, includeMissing) : Medialibrary.EMPTY_COLLECTION;
     }
 
+    @Override
+    public boolean refresh() {
+        final Medialibrary ml = Medialibrary.getInstance();
+        return ml.isInitiated() && nativeServiceRefresh(ml, this.type.value);
+    }
+
     private native boolean nativeAddSubscription(Medialibrary ml, int type, String mrl);
     private native boolean nativeIsAutoDownloadEnabled(Medialibrary ml, int type);
     private native boolean nativeSetAutoDownloadEnabled(Medialibrary ml, int type, boolean enabled);
@@ -92,4 +98,5 @@ public class MlServiceImpl extends MlService {
     private native Subscription[] nativeGetSubscriptions(Medialibrary ml, int type, int sort, boolean desc, boolean includeMissing);
     private native int nativeGetNbMedia(Medialibrary ml, int type);
     private native MediaWrapper[] nativeGetServiceMedia(Medialibrary ml, int type, int sort, boolean desc, boolean includeMissing);
+    private native boolean nativeServiceRefresh(Medialibrary ml, int type);
 }
diff --git a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
index 38657e420f..28b2106ddc 100644
--- a/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
+++ b/medialibrary/src/org/videolan/medialibrary/stubs/StubMlService.java
@@ -67,4 +67,9 @@ public class StubMlService extends MlService {
     public int getNbMedia() {
         return 0;
     }
+
+    @Override
+    public boolean refresh() {
+        return false;
+    }
 }



More information about the Android mailing list