Skip to content
Snippets Groups Projects
Commit 54e15157 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Monitor Medialibrary activity from its callbacks

parent 05adcfd6
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -94,7 +94,6 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
is MediaUnmounted -> {
delay(100L)
VLCApplication.getMLInstance().removeDevice(action.uuid, action.path)
MediaParsingService.started.setValue(false)
}
}
......
......@@ -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
}
......
......@@ -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>>() {
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment