[Android] Browsers: code cleaning

Geoffrey Métais git at videolan.org
Tue Sep 25 14:58:12 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Sep 25 14:49:30 2018 +0200| [5f6f6de62d5490c8e8711eb776af4b8488e960a6] | committer: Geoffrey Métais

Browsers: code cleaning

> https://code.videolan.org/videolan/vlc-android/commit/5f6f6de62d5490c8e8711eb776af4b8488e960a6
---

 .../src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt      | 6 +++---
 vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt  | 7 +++----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
index 877fb5bed..c799505b4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserAdapter.kt
@@ -54,7 +54,7 @@ internal class StorageBrowserAdapter(fragment: BaseBrowserFragment) : BaseBrowse
     }
 
     override fun onBindViewHolder(holder: BaseBrowserAdapter.ViewHolder<*>, position: Int) {
-        launch(UI.immediate) {
+        launch {
             val vh = holder as BaseBrowserAdapter.MediaViewHolder
             var storage = getItem(position)
 
@@ -81,14 +81,14 @@ internal class StorageBrowserAdapter(fragment: BaseBrowserFragment) : BaseBrowse
     }
 
     fun updateMediaDirs(context: Context) {
-        if (mediaDirsLocation != null) mediaDirsLocation.clear()
+        mediaDirsLocation.clear()
         val folders = VLCApplication.getMLInstance().foldersList
 
         folders.forEach {
             mediaDirsLocation.add(Uri.decode(if (it.startsWith("file://")) it.substring(7) else it))
         }
 
-        job = launch(UI.immediate) {
+        job = launch {
             customDirsLocation = DirectoryRepository.getInstance(context).getCustomDirectories().map { it.path }
         }
     }
diff --git a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
index a4e13493f..c4b065159 100644
--- a/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/FileBrowserProvider.kt
@@ -26,7 +26,6 @@ import android.hardware.usb.UsbDevice
 import android.net.Uri
 import android.text.TextUtils
 import kotlinx.coroutines.experimental.*
-import kotlinx.coroutines.experimental.android.UI
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
@@ -67,7 +66,7 @@ open class FileBrowserProvider(
                 }
             }
         }
-        launch(UI.immediate) {
+        launch {
             if (favs.isNotEmpty()) {
                 job?.cancelAndJoin()
                 val position = data.size
@@ -127,8 +126,8 @@ open class FileBrowserProvider(
 
     override fun browse(url: String?) {
         when {
-            url == "otg://" || url?.startsWith("content:") == true -> launch(UI.immediate) {
-                dataset.value = withContext(IO) { getDocumentFiles(context, Uri.parse(url).path.substringAfterLast(':')) as? MutableList<MediaLibraryItem> ?: mutableListOf() }
+            url == "otg://" || url?.startsWith("content:") == true -> launch {
+                dataset.value = withContext(Dispatchers.IO) { getDocumentFiles(context, Uri.parse(url).path?.substringAfterLast(':') ?: "") as? MutableList<MediaLibraryItem> ?: mutableListOf() }
             }
             else -> super.browse(url)
         }



More information about the Android mailing list