[Android] medialib: Add onEntryPointAdded implementation

Hugo Beauzée-Luyssen git at videolan.org
Tue Jun 11 16:26:01 CEST 2019


vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Jun  7 11:09:01 2019 +0200| [dffb074bb4f1a7639046c457ba57f8a6244dae7c] | committer: Hugo Beauzée-Luyssen

medialib: Add onEntryPointAdded implementation

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

 medialibrary/jni/AndroidMediaLibrary.cpp                     | 12 ++++++++++++
 medialibrary/jni/AndroidMediaLibrary.h                       |  1 +
 medialibrary/jni/medialibrary.cpp                            |  4 ++++
 medialibrary/jni/utils.h                                     |  1 +
 medialibrary/src/org/videolan/medialibrary/Medialibrary.java |  9 +++++++++
 .../medialibrary/interfaces/EntryPointsEventsCb.java         |  1 +
 .../org/videolan/vlc/gui/browser/StorageBrowserFragment.kt   |  2 ++
 7 files changed, 30 insertions(+)

diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index 54a8d4ae2..68b7e3b1e 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -846,6 +846,18 @@ void AndroidMediaLibrary::onEntryPointUnbanned( const std::string& entryPoint, b
     env->DeleteLocalRef(ep);
 }
 
+void AndroidMediaLibrary::onEntryPointAdded( const std::string& entryPoint, bool success )
+{
+    JNIEnv *env = getEnv();
+    if (env == NULL) return;
+    jstring ep = env->NewStringUTF(entryPoint.c_str());
+    if (weak_thiz)
+    {
+        env->CallVoidMethod(weak_thiz, p_fields->MediaLibrary.onEntryPointAddedId, ep, success);
+    }
+    env->DeleteLocalRef(ep);
+}
+
 void AndroidMediaLibrary::onEntryPointRemoved( const std::string& entryPoint, bool success )
 {
     JNIEnv *env = getEnv();
diff --git a/medialibrary/jni/AndroidMediaLibrary.h b/medialibrary/jni/AndroidMediaLibrary.h
index 4b9a6762b..22e272047 100644
--- a/medialibrary/jni/AndroidMediaLibrary.h
+++ b/medialibrary/jni/AndroidMediaLibrary.h
@@ -133,6 +133,7 @@ public:
     void onReloadCompleted( const std::string& entryPoint, bool success );
     void onEntryPointBanned( const std::string& entryPoint, bool success );
     void onEntryPointUnbanned( const std::string& entryPoint, bool success );
+    void onEntryPointAdded( const std::string& entryPoint, bool success );
     void onEntryPointRemoved( const std::string& entryPoint, bool success );
     void onParsingStatsUpdated( uint32_t percent);
     void onBackgroundTasksIdleChanged( bool isIdle );
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index f07af36bd..80ff9f9b0 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -2111,6 +2111,10 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
            ml_fields.MediaLibrary.onEntryPointUnbannedId,
            ml_fields.MediaLibrary.clazz,
            "onEntryPointUnbanned", "(Ljava/lang/String;Z)V");
+    GET_ID(GetMethodID,
+           ml_fields.MediaLibrary.onEntryPointAddedId,
+           ml_fields.MediaLibrary.clazz,
+           "onEntryPointAdded", "(Ljava/lang/String;Z)V");
     GET_ID(GetMethodID,
            ml_fields.MediaLibrary.onEntryPointRemovedId,
            ml_fields.MediaLibrary.clazz,
diff --git a/medialibrary/jni/utils.h b/medialibrary/jni/utils.h
index 18f0fb5ec..fcaaddf6c 100644
--- a/medialibrary/jni/utils.h
+++ b/medialibrary/jni/utils.h
@@ -63,6 +63,7 @@ struct fields {
         jmethodID onReloadCompletedId;
         jmethodID onEntryPointBannedId;
         jmethodID onEntryPointUnbannedId;
+        jmethodID onEntryPointAddedId;
         jmethodID onEntryPointRemovedId;
         jmethodID onMediaThumbnailReadyId;
     } MediaLibrary;
diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 279065a56..91a44525c 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -713,6 +713,15 @@ public class Medialibrary {
         }
     }
 
+    @SuppressWarnings("unused")
+    void onEntryPointAdded(String entryPoint, boolean success) {
+        synchronized (entryPointsEventsCbList) {
+            if (!entryPointsEventsCbList.isEmpty())
+                for (EntryPointsEventsCb cb : entryPointsEventsCbList)
+                    cb.onEntryPointAdded(entryPoint, success);
+        }
+    }
+
     @SuppressWarnings("unused")
     void onEntryPointRemoved(String entryPoint, boolean success) {
         synchronized (entryPointsEventsCbList) {
diff --git a/medialibrary/src/org/videolan/medialibrary/interfaces/EntryPointsEventsCb.java b/medialibrary/src/org/videolan/medialibrary/interfaces/EntryPointsEventsCb.java
index 7291dccab..34467aada 100644
--- a/medialibrary/src/org/videolan/medialibrary/interfaces/EntryPointsEventsCb.java
+++ b/medialibrary/src/org/videolan/medialibrary/interfaces/EntryPointsEventsCb.java
@@ -4,6 +4,7 @@ package org.videolan.medialibrary.interfaces;
 public interface EntryPointsEventsCb {
     void onEntryPointBanned(String entryPoint, boolean success);
     void onEntryPointUnbanned(String entryPoint, boolean success);
+    void onEntryPointAdded(String entryPoint, boolean success);
     void onEntryPointRemoved(String entryPoint, boolean success);
     void onDiscoveryStarted(String entryPoint);
     void onDiscoveryProgress(String entryPoint);
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index cad1ef541..8e3b67e10 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -205,6 +205,8 @@ class StorageBrowserFragment : FileBrowserFragment(), EntryPointsEventsCb {
 
     override fun onEntryPointUnbanned(entryPoint: String, success: Boolean) {}
 
+    override fun onEntryPointAdded(entryPoint: String, success: Boolean) {}
+
     override fun onEntryPointRemoved(entryPoint: String, success: Boolean) {
         var entryPoint = entryPoint
         if (entryPoint.endsWith("/"))



More information about the Android mailing list