[Android] Disable medialibrary options during scan

Geoffrey Métais git at videolan.org
Mon Oct 2 17:41:19 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Oct  2 17:27:52 2017 +0200| [5b218c176f8edb425c2e157f8c8a570729e8b379] | committer: Geoffrey Métais

Disable medialibrary options during scan

This will avoid undefined medialibrary states

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

 .../vlc/gui/browser/StorageBrowserAdapter.java     | 12 +++++++++-
 .../vlc/gui/browser/StorageBrowserFragment.java    | 27 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
index 517b19e8c..a0fa160dc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.java
@@ -41,10 +41,20 @@ class StorageBrowserAdapter extends BaseBrowserAdapter {
 
     private static ArrayList<String> mMediaDirsLocation;
     private static ArrayList<String> mCustomDirsLocation;
+    private boolean mParsing = false;
 
     StorageBrowserAdapter(BaseBrowserFragment fragment) {
         super(fragment);
         updateMediaDirs();
+        mParsing = VLCApplication.getMLInstance().isWorking();
+    }
+
+    // Deactivate checkboxes while ML is scanning to avoid ML undefined states
+    void setServiceActive(boolean started) {
+        if (started != mParsing) {
+            mParsing = started;
+            notifyDataSetChanged();
+        }
     }
 
     @Override
@@ -67,7 +77,7 @@ class StorageBrowserAdapter extends BaseBrowserAdapter {
             vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_PARTIAL);
         else
             vh.binding.browserCheckbox.setState(ThreeStatesCheckbox.STATE_UNCHECKED);
-        vh.binding.setCheckEnabled(!((StorageBrowserFragment) fragment).mScannedDirectory);
+        vh.binding.setCheckEnabled(!mParsing && !((StorageBrowserFragment) fragment).mScannedDirectory);
         if (hasContextMenu)
             vh.setContextMenuListener();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
index 19817dbb0..25933d574 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.browser;
 
+import android.content.IntentFilter;
 import android.databinding.DataBindingUtil;
 import android.net.Uri;
 import android.os.Bundle;
@@ -30,6 +31,7 @@ import android.support.annotation.Nullable;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentTransaction;
+import android.support.v4.content.LocalBroadcastManager;
 import android.support.v4.util.SimpleArrayMap;
 import android.text.TextUtils;
 import android.view.Menu;
@@ -42,6 +44,7 @@ import org.videolan.medialibrary.interfaces.EntryPointsEventsCb;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 import org.videolan.medialibrary.media.MediaWrapper;
 import org.videolan.medialibrary.media.Storage;
+import org.videolan.vlc.MediaParsingService;
 import org.videolan.vlc.R;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.databinding.BrowserItemBinding;
@@ -76,9 +79,8 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
         mAdapter = new StorageBrowserAdapter(this);
         if (bundle == null)
             bundle = getArguments();
-        if (bundle != null){
+        if (bundle != null)
             mScannedDirectory = bundle.getBoolean(KEY_IN_MEDIALIB);
-        }
     }
 
     @Override
@@ -102,6 +104,15 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
     }
 
     @Override
+    public void onResume() {
+        super.onResume();
+        final IntentFilter filter = new IntentFilter(MediaParsingService.ACTION_SERVICE_STARTED);
+        filter.addAction(MediaParsingService.ACTION_SERVICE_ENDED);
+        LocalBroadcastManager.getInstance(VLCApplication.getAppContext()).registerReceiver(mParsingServiceReceiver, filter);
+        ((StorageBrowserAdapter)mAdapter).setServiceActive(mMediaLibrary.isWorking());
+    }
+
+    @Override
     public void onStop() {
         super.onStop();
         if (mFabPlay != null) {
@@ -249,4 +260,16 @@ public class StorageBrowserFragment extends FileBrowserFragment implements Entry
             ((StorageBrowserAdapter)mAdapter).updateMediaDirs();
         }
     }
+
+    @Override
+    protected void onParsingServiceFinished() {
+        super.onParsingServiceFinished();
+        ((StorageBrowserAdapter)mAdapter).setServiceActive(false);
+    }
+
+    @Override
+    protected void onParsingServiceStarted() {
+        super.onParsingServiceStarted();
+        ((StorageBrowserAdapter)mAdapter).setServiceActive(true);
+    }
 }



More information about the Android mailing list