[Android] get folders lists on demand & check existency

Geoffrey Métais git at videolan.org
Mon Jan 2 16:00:47 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  2 15:33:09 2017 +0100| [045f846bd8a73dafe459e33230976fa1c7f9ef3f] | committer: Geoffrey Métais

get folders lists on demand & check existency

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

 .../org/videolan/medialibrary/Medialibrary.java    | 51 ++++++++++++++--------
 .../src/org/videolan/vlc/VLCApplication.java       | 12 +++--
 2 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 8da645e..27c506d 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -1,7 +1,6 @@
 package org.videolan.medialibrary;
 
 import android.Manifest;
-import android.app.Application;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.net.Uri;
@@ -22,6 +21,7 @@ import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.medialibrary.media.Playlist;
 import org.videolan.medialibrary.media.SearchAggregate;
 
+import java.io.File;
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.List;
@@ -38,23 +38,6 @@ public class Medialibrary {
     public static final int FLAG_MEDIA_ADDED_VIDEO          = 1 << 5;
 
     private static final String extDirPath = Environment.getExternalStorageDirectory().getAbsolutePath();
-    public static final String[] banList = {
-            "/Android/data/",
-            "/Android/media/",
-            "/Alarms/",
-            "/Ringtones/",
-            "/Notifications/",
-            "/alarms/",
-            "/ringtones/",
-            "/notifications/",
-            "/audio/Alarms/",
-            "/audio/Ringtones/",
-            "/audio/Notifications/",
-            "/audio/alarms/",
-            "/audio/ringtones/",
-            "/audio/notifications/",
-            "/WhatsApp/",
-    };
 
     private static final MediaWrapper[] EMPTY_COLLECTION = {};
 
@@ -86,7 +69,7 @@ public class Medialibrary {
     }
 
     public void banFolder(String path) {
-        if (mIsInitiated)
+        if (mIsInitiated && new File(path).exists())
             nativeBanFolder(path);
     }
 
@@ -396,6 +379,36 @@ public class Medialibrary {
         setMediaAddedCb(null, 0);
     }
 
+    public static String[] getBlackList() {
+        return new String[] {
+                "/Android/data/",
+                "/Android/media/",
+                "/Alarms/",
+                "/Ringtones/",
+                "/Notifications/",
+                "/alarms/",
+                "/ringtones/",
+                "/notifications/",
+                "/audio/Alarms/",
+                "/audio/Ringtones/",
+                "/audio/Notifications/",
+                "/audio/alarms/",
+                "/audio/ringtones/",
+                "/audio/notifications/",
+                "/WhatsApp/",
+        };
+    }
+
+    public static File[] getDefaultFolders() {
+        return new File[]{
+                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
+                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
+                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC),
+                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS),
+                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
+        };
+    }
+
     /* used only before API 13: substitute for NewWeakGlobalRef */
     @SuppressWarnings("unused") /* Used from JNI */
     private Object getWeakReference() {
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index d6c4c73..4b2cdc2 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -25,7 +25,6 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.content.res.Resources;
-import android.os.Environment;
 import android.os.Process;
 import android.preference.PreferenceManager;
 import android.support.v4.app.DialogFragment;
@@ -44,6 +43,7 @@ import org.videolan.vlc.util.AndroidDevices;
 import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.VLCInstance;
 
+import java.io.File;
 import java.util.Calendar;
 import java.util.Locale;
 import java.util.concurrent.LinkedBlockingQueue;
@@ -254,13 +254,11 @@ public class VLCApplication extends Application {
                     LocalBroadcastManager.getInstance(instance).sendBroadcast(new Intent(ACTION_MEDIALIBRARY_READY));
                     if (medialibrary.getFoldersList().length == 0) {
                         for (String storage : storages)
-                            for (String folder : Medialibrary.banList)
+                            for (String folder : Medialibrary.getBlackList())
                                 medialibrary.banFolder(storage+folder);
-                        medialibrary.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath());
-                        medialibrary.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getPath());
-                        medialibrary.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getPath());
-                        medialibrary.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS).getPath());
-                        medialibrary.discover(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath());
+                        for (File folder : Medialibrary.getDefaultFolders())
+                            if (folder.exists())
+                                medialibrary.discover(folder.getPath());
                         for (String externalStorage : AndroidDevices.getExternalStorageDirectories())
                             medialibrary.discover(externalStorage);
                     }



More information about the Android mailing list