[Android] Improve media scan icon display management

Geoffrey Métais git at videolan.org
Mon Feb 20 14:40:07 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 20 11:53:32 2017 +0100| [87f817e3d86c50226c1605229947cb1a15f23356] | committer: Geoffrey Métais

Improve media scan icon display management

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

 .../src/org/videolan/vlc/MediaParsingService.java  | 30 ++++++++++++++--------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.java b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
index a9440b7..f75b902 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.java
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.java
@@ -41,7 +41,7 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     private final IBinder mBinder = new LocalBinder();
     private Medialibrary mMedialibrary;
     private int mParsing = 0, mReload = 0;
-    private String mCurrentProgress = null;
+    private String mCurrentDiscovery = null;
     private long mLastNotificationTime;
     private BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
@@ -56,7 +56,9 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                 default:
                     return;
             }
-            mLastNotificationTime = 0L;
+            synchronized (this) {
+                mLastNotificationTime = 0L;
+            }
             showNotification();
         }
     };
@@ -74,7 +76,9 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
         filter.addAction(ACTION_PAUSE_SCAN);
         filter.addAction(ACTION_RESUME_SCAN);
         registerReceiver(mReceiver, filter);
-        mLastNotificationTime = System.currentTimeMillis();
+        synchronized (this) {
+            mLastNotificationTime = System.currentTimeMillis();
+        }
         mMedialibrary.addDeviceDiscoveryCb(MediaParsingService.this);
         switch (intent.getAction()) {
             case ACTION_INIT:
@@ -150,8 +154,8 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
                 sb.setLength(0);
                 if (mParsing > 0)
                     sb.append(getString(R.string.ml_parse_media)).append(' ').append(mParsing).append("%");
-                else if (mCurrentProgress != null)
-                    sb.append(getString(R.string.ml_discovering)).append(' ').append(Uri.decode(Strings.removeFileProtocole(mCurrentProgress)));
+                else if (mCurrentDiscovery != null)
+                    sb.append(getString(R.string.ml_discovering)).append(' ').append(Uri.decode(Strings.removeFileProtocole(mCurrentDiscovery)));
                 else
                     sb.append(getString(R.string.ml_parse_media));
                 if (builder == null) {
@@ -198,13 +202,13 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
 
     @Override
     public void onDiscoveryProgress(String entryPoint) {
-        mCurrentProgress = entryPoint;
+        mCurrentDiscovery = entryPoint;
         showNotification();
     }
 
     @Override
     public void onDiscoveryCompleted(String entryPoint) {
-        if (mCurrentProgress != null && mParsing == 0 && entryPoint.isEmpty())
+        if (mCurrentDiscovery != null && mParsing == 0 && entryPoint.isEmpty())
             stopSelf();
     }
 
@@ -221,21 +225,25 @@ public class MediaParsingService extends Service implements DevicesDiscoveryCb {
     public void onReloadStarted(String entryPoint) {
         if (TextUtils.isEmpty(entryPoint))
             ++mReload;
-        mLastNotificationTime = System.currentTimeMillis();
-        showNotification();
+        synchronized (this) {
+            mLastNotificationTime = System.currentTimeMillis();
+        }
     }
 
     @Override
     public void onReloadCompleted(String entryPoint) {
-        if (TextUtils.isEmpty(entryPoint))
+        if (TextUtils.isEmpty(entryPoint)) {
             --mReload;
+            if (mCurrentDiscovery != null && mParsing == 0)
+                stopSelf();
+        }
     }
 
     @Override
     public void onDestroy() {
+        hideNotification();
         mMedialibrary.removeDeviceDiscoveryCb(this);
         unregisterReceiver(mReceiver);
-        hideNotification();
         super.onDestroy();
     }
 



More information about the Android mailing list