[Android] Pass the firstRun info to MediaParsingService

Geoffrey Métais git at videolan.org
Mon Mar 13 14:45:51 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 13 11:34:14 2017 +0100| [9ac01ee3fa8d8e3268d911764130cbb1c6968f00] | committer: Geoffrey Métais

Pass the firstRun info to MediaParsingService

This will improve medialibrary management

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

 .../src/org/videolan/vlc/MediaParsingService.java  | 26 +++++++++++-----------
 .../src/org/videolan/vlc/StartActivity.java        |  1 +
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index 4fdcc47..c4da6cd 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -82,7 +82,8 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
         mMedialibrary.addDeviceDiscoveryCb(MediaParsingService.this);
         switch (intent.getAction()) {
             case ACTION_INIT:
-                setupMedialibrary(intent.getBooleanExtra(StartActivity.EXTRA_UPGRADE, false));
+                setupMedialibrary(intent.getBooleanExtra(StartActivity.EXTRA_FIRST_RUN, false),
+                        intent.getBooleanExtra(StartActivity.EXTRA_UPGRADE, false));
                 break;
             case ACTION_RELOAD:
                 reload();
@@ -105,7 +106,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
         mMedialibrary.reload();
     }
 
-    private void setupMedialibrary(final boolean upgrade) {
+    private void setupMedialibrary(final boolean firstRun, final boolean upgrade) {
         if (mMedialibrary.isInitiated())
             mMedialibrary.resumeBackgroundOperations();
         else
@@ -120,26 +121,25 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                     }
                     if (mMedialibrary.init(MediaParsingService.this)) {
                         LocalBroadcastManager.getInstance(MediaParsingService.this).sendBroadcast(new Intent(VLCApplication.ACTION_MEDIALIBRARY_READY));
-                        String[] foldersList = mMedialibrary.getFoldersList();
-                        if (foldersList.length == 0) {
+                        if (firstRun) {
                             for (String storage : storages)
                                 for (String folder : Medialibrary.getBlackList())
                                     mMedialibrary.banFolder(storage + folder);
                             for (File folder : Medialibrary.getDefaultFolders())
                                 if (folder.exists())
                                     mMedialibrary.discover(folder.getPath());
+                            String[] foldersList = mMedialibrary.getFoldersList();
+                            for (String externalStorage : AndroidDevices.getExternalStorageDirectories()) {
+                                if (!TextUtils.equals(externalStorage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
+                                        && !Util.arrayContains(foldersList, "file://" + externalStorage + "/")) {
+                                    for (String folder : Medialibrary.getBlackList())
+                                        mMedialibrary.banFolder(externalStorage + folder);
+                                    mMedialibrary.discover(externalStorage);
+                                }
+                            }
                         } else if (upgrade) {
                             mMedialibrary.forceParserRetry();
                         }
-                        for (String externalStorage : AndroidDevices.getExternalStorageDirectories()) {
-                            if (foldersList.length == 0
-                                    && !TextUtils.equals(externalStorage, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
-                                    && !Util.arrayContains(foldersList, "file://" + externalStorage + "/")) {
-                                for (String folder : Medialibrary.getBlackList())
-                                    mMedialibrary.banFolder(externalStorage + folder);
-                                mMedialibrary.discover(externalStorage);
-                            }
-                        }
                     }
                 }
             });
diff --git a/vlc-android/src/org/videolan/vlc/StartActivity.java b/vlc-android/src/org/videolan/vlc/StartActivity.java
index c85e72b..e9dca5a 100644
--- a/vlc-android/src/org/videolan/vlc/StartActivity.java
+++ b/vlc-android/src/org/videolan/vlc/StartActivity.java
@@ -87,6 +87,7 @@ public class StartActivity extends Activity {
         } else {
             if (Permissions.canReadStorage()) {
                 Intent serviceInent = new Intent(MediaParsingService.ACTION_INIT, null, this, MediaParsingService.class);
+                serviceInent.putExtra(EXTRA_FIRST_RUN, firstRun);
                 serviceInent.putExtra(EXTRA_UPGRADE, upgrade);
                 startService(serviceInent);
             }



More information about the Android mailing list