[Android] Monitor Medialibrary activity from its callbacks

Geoffrey Métais git at videolan.org
Wed Dec 5 11:29:57 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Dec  5 10:18:46 2018 +0100| [54e151573edcd1344a220de7e65ebfd123186ea7] | committer: Geoffrey Métais

Monitor Medialibrary activity from its callbacks

> https://code.videolan.org/videolan/vlc-android/commit/54e151573edcd1344a220de7e65ebfd123186ea7
---

 medialibrary/src/org/videolan/medialibrary/Medialibrary.java        | 6 ++++++
 vlc-android/src/org/videolan/vlc/ExternalMonitor.kt                 | 1 -
 vlc-android/src/org/videolan/vlc/MediaParsingService.kt             | 3 ---
 .../src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java      | 5 ++---
 vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java | 2 +-
 5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
index 02fa11152..174157fef 100644
--- a/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
+++ b/medialibrary/src/org/videolan/medialibrary/Medialibrary.java
@@ -76,6 +76,7 @@ public class Medialibrary {
 
     private volatile boolean mIsInitiated = false;
     private volatile boolean mIsWorking = false;
+    private static MutableLiveData<Boolean> sRunning = new MutableLiveData<>();
 
     private final List<ArtistsCb> mArtistsCbs = new ArrayList<>();
     private final List<AlbumsCb> mAlbumsCbs = new ArrayList<>();
@@ -95,6 +96,10 @@ public class Medialibrary {
         return sContext;
     }
 
+    public static LiveData<Boolean> getState() {
+        return sRunning;
+    }
+
     public int init(Context context) {
         if (context == null) return ML_INIT_FAILED;
         sContext = context;
@@ -627,6 +632,7 @@ public class Medialibrary {
     @SuppressWarnings("unused")
     public void onBackgroundTasksIdleChanged(boolean isIdle) {
         mIsWorking = !isIdle;
+        sRunning.postValue(mIsWorking);
         LocalBroadcastManager.getInstance(sContext).sendBroadcast(new Intent(ACTION_IDLE).putExtra(STATE_IDLE, isIdle));
         if (isIdle) {
             synchronized (onMedialibraryReadyListeners) {
diff --git a/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt b/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
index efb42254d..4445f3835 100644
--- a/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
+++ b/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
@@ -94,7 +94,6 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
             is MediaUnmounted -> {
                 delay(100L)
                 VLCApplication.getMLInstance().removeDevice(action.uuid, action.path)
-                MediaParsingService.started.setValue(false)
 
             }
         }
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 543fecd48..a56bb655c 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -133,7 +133,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
                 return Service.START_NOT_STICKY
             }
         }
-        started.value = true
         return Service.START_NOT_STICKY
     }
 
@@ -337,7 +336,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
     }
 
     override fun onDestroy() {
-        started.value = false
         notificationActor.offer(Hide)
         medialibrary.removeDeviceDiscoveryCb(this)
         unregisterReceiver(receiver)
@@ -410,7 +408,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
 
     companion object {
         val progress = MutableLiveData<ScanProgress>()
-        val started = MutableLiveData<Boolean>()
         val newStorages = MutableLiveData<MutableList<String>>()
         var wizardShowing = false
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 8dde606f0..1bd139d40 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -386,11 +386,10 @@ public class AudioPlayerContainerActivity extends BaseActivity {
                 if (mScanProgressBar != null) mScanProgressBar.setProgress(scanProgress.getParsing());
             }
         });
-        MediaParsingService.Companion.getStarted().observe(this, new Observer<Boolean>() {
+        Medialibrary.getState().observe(this, new Observer<Boolean>() {
             @Override
             public void onChanged(@Nullable Boolean started) {
-                if (started == null) return;
-                updateProgressVisibility(started);
+                if (started != null) updateProgressVisibility(started);
             }
         });
         MediaParsingService.Companion.getNewStorages().observe(this, new Observer<List<String>>() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
index 6612bf2d3..cdfad753e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
@@ -117,7 +117,7 @@ public abstract class BaseTvActivity extends FragmentActivity {
                 if (scanProgress != null) onParsingServiceProgress();
             }
         });
-        MediaParsingService.Companion.getStarted().observe(this, new Observer<Boolean>() {
+        Medialibrary.getState().observe(this, new Observer<Boolean>() {
             @Override
             public void onChanged(@Nullable Boolean started) {
                 if (started == null) return;



More information about the Android mailing list