Commit 93e09f3d authored by Geoffrey Métais's avatar Geoffrey Métais

Fix otg root setting event

parent 6d49723f
......@@ -16,7 +16,13 @@ class LiveEvent<T> : MutableLiveData<T>() {
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
if (hasActiveObservers()) Log.w(TAG, "Multiple observers registered but only one will be notified of changes.")
// Observe the internal MutableLiveData
super.observe(owner, Observer<T> { t -> if (pending.compareAndSet(true, false)) observer.onChanged(t) })
super.observe(owner, Observer<T> { t ->
if (pending.compareAndSet(true, false)) observer.onChanged(t)
})
}
override fun observeForever(observer: Observer<T>) {
super.observeForever { if (pending.compareAndSet(true, false)) observer.onChanged(it) }
}
@MainThread
......@@ -26,7 +32,5 @@ class LiveEvent<T> : MutableLiveData<T>() {
}
@MainThread
fun call() {
super.setValue(null)
}
fun clear() = super.setValue(null)
}
\ No newline at end of file
......@@ -153,7 +153,7 @@ public class ExternalMonitor extends BroadcastReceiver implements LifecycleObser
break;
case UsbManager.ACTION_USB_DEVICE_DETACHED:
if (intent.hasExtra(UsbManager.EXTRA_DEVICE)) {
((LiveEvent<Uri>)OtgAccess.Companion.getOtgRoot()).call();
((LiveEvent<Uri>)OtgAccess.Companion.getOtgRoot()).clear();
final UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
devices.remove(device);
}
......
......@@ -102,10 +102,8 @@ public class FileBrowserFragment extends BaseBrowserFragment {
otgRoot.observeForever(new Observer<Uri>() {
@Override
public void onChanged(@Nullable Uri uri) {
if (uri != null) {
OtgAccess.Companion.getOtgRoot().removeObserver(this);
browseOtgDevice(uri, title);
}
OtgAccess.Companion.getOtgRoot().removeObserver(this);
if (uri != null) browseOtgDevice(uri, title);
}
});
OtgAccess.Companion.requestOtgRoot(requireActivity());
......
......@@ -129,15 +129,13 @@ open class FileBrowserProvider(dataset: LiveDataset<MediaLibraryItem>, url: Stri
dataset.remove(otgPosition)
otgPosition = -1
}
} else {
if (otgPosition == -1) {
val otg = MediaWrapper(Uri.parse("otg://")).apply {
title = VLCApplication.getAppResources().getString(R.string.otg_device_title)
type = MediaWrapper.TYPE_DIR
}
otgPosition = storagePosition+1
dataset.add(otgPosition, otg)
} else if (otgPosition == -1) {
val otg = MediaWrapper(Uri.parse("otg://")).apply {
title = VLCApplication.getAppResources().getString(R.string.otg_device_title)
type = MediaWrapper.TYPE_DIR
}
otgPosition = storagePosition+1
dataset.add(otgPosition, otg)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment