[Android] Always send device events to Medialibrary
Geoffrey Métais
git at videolan.org
Mon May 13 16:27:46 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon May 13 16:26:10 2019 +0200| [f4e2590f022cacb52c95dadeb31d2ac2bddcdd35] | committer: Geoffrey Métais
Always send device events to Medialibrary
> https://code.videolan.org/videolan/vlc-android/commit/f4e2590f022cacb52c95dadeb31d2ac2bddcdd35
---
.../src/org/videolan/vlc/ExternalMonitor.kt | 35 ++++++++--------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt b/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
index 237f44ec9..d0b6e2d8f 100644
--- a/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
+++ b/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
@@ -68,14 +68,14 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
for (action in channel) when (action){
is MediaMounted -> {
if (TextUtils.isEmpty(action.uuid)) return at actor
- val ml = VLCApplication.mlInstance
- val knownDevices = ctx.getFromMl { devices }
- if (ml.addDevice(action.uuid, action.path, true)) notifyNewStorage(action.path)
+ if (ctx.getFromMl { addDevice(action.uuid, action.path, true) }) {
+ notifyNewStorage(action.uri, action.path)
+ }
}
is MediaUnmounted -> {
delay(100L)
VLCApplication.mlInstance.removeDevice(action.uuid, action.path)
-
+ if (storageUnplugged.hasActiveObservers()) storageUnplugged.postValue(action.uri)
}
}
}
@@ -88,8 +88,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
override fun onReceive(context: Context, intent: Intent) {
if (!this::ctx.isInitialized) ctx = context.applicationContext
- val action = intent.action
- when (action) {
+ when (intent.action) {
ConnectivityManager.CONNECTIVITY_ACTION -> {
if (!this::cm.isInitialized)
cm = context.applicationContext.getSystemService(
@@ -102,21 +101,10 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
connected.value = isConnected
}
}
- Intent.ACTION_MEDIA_MOUNTED -> {
- if (storageObserver != null && storageObserver!!.get() != null) {
- intent.data?.let {
- actor.offer(MediaMounted(it))
- storagePlugged.postValue(it)
- }
- }
- }
+ Intent.ACTION_MEDIA_MOUNTED -> intent.data?.let { actor.offer(MediaMounted(it)) }
Intent.ACTION_MEDIA_UNMOUNTED,
- Intent.ACTION_MEDIA_EJECT -> {
- if (storageObserver != null && storageObserver!!.get() != null)
- intent.data?.let {
- actor.offer(MediaUnmounted(it))
- storageUnplugged.postValue(it)
- }
+ Intent.ACTION_MEDIA_EJECT -> intent.data?.let {
+ actor.offer(MediaUnmounted(it))
}
UsbManager.ACTION_USB_DEVICE_ATTACHED -> {
if (intent.hasExtra(UsbManager.EXTRA_DEVICE)) {
@@ -208,9 +196,10 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
}
@Synchronized
- private fun notifyNewStorage(path: String?) {
- val activity = if (storageObserver != null) storageObserver!!.get() else null
- activity?.let { UiTools.newStorageDetected(it, path) }
+ private fun notifyNewStorage(uri: Uri, path: String) {
+ val activity = storageObserver?.get() ?: return
+ UiTools.newStorageDetected(activity, path)
+ if (storagePlugged.hasActiveObservers()) storagePlugged.postValue(uri)
}
val isConnected: Boolean
More information about the Android
mailing list