[Android] MainActivity: start a rescan of the media library only if needed

Ludovic Fauvet git at videolan.org
Mon Oct 1 16:03:52 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Mon Oct  1 13:30:41 2012 +0200| [3881a50949aad0781f28ee1097717062eec6e583] | committer: Ludovic Fauvet

MainActivity: start a rescan of the media library only if needed

A rescan will only be triggered if a previous scan was ongoing during
the last call to onPause().

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3881a50949aad0781f28ee1097717062eec6e583
---

 vlc-android/src/org/videolan/vlc/MediaLibrary.java     |    8 ++++++++
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java |    6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaLibrary.java b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
index 66c3060..5e9fda8 100644
--- a/vlc-android/src/org/videolan/vlc/MediaLibrary.java
+++ b/vlc-android/src/org/videolan/vlc/MediaLibrary.java
@@ -71,6 +71,14 @@ public class MediaLibrary {
         isStopping = true;
     }
 
+    public boolean isWorking() {
+        if (mLoadingThread != null &&
+            mLoadingThread.getState() != State.TERMINATED &&
+            mLoadingThread.getState() != State.NEW)
+            return true;
+        return false;
+    }
+
     public static MediaLibrary getInstance(Context context) {
         if (mInstance == null)
             mInstance = new MediaLibrary(context);
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index ac95e88..41d74ef 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -103,6 +103,7 @@ public class MainActivity extends SherlockFragmentActivity {
 
     private int mVersionNumber = -1;
     private boolean mFirstRun = false;
+    private boolean mScanNeeded = true;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -305,7 +306,8 @@ public class MainActivity extends SherlockFragmentActivity {
             getIntent().removeExtra(AudioService.START_FROM_NOTIFICATION);
 
         /* Load media items from database and storage */
-        MediaLibrary.getInstance(this).loadMediaItems(this);
+        if (mScanNeeded)
+            MediaLibrary.getInstance(this).loadMediaItems(this);
 
         super.onResume();
     }
@@ -315,6 +317,8 @@ public class MainActivity extends SherlockFragmentActivity {
      */
     @Override
     protected void onPause() {
+        /* Check for an ongoing scan that needs to be resumed during onResume */
+        mScanNeeded = MediaLibrary.getInstance(this).isWorking();
         /* Stop scanning for files */
         MediaLibrary.getInstance(this).stop();
         /* Stop the thumbnailer */



More information about the Android mailing list