[Android] Storage: override refresh function to filter items

Geoffrey Métais git at videolan.org
Fri Jun 14 12:14:53 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 14 12:12:26 2019 +0200| [082fb7eee10da5f728d0b83ca17ca1440c6bf404] | committer: Geoffrey Métais

Storage: override refresh function to filter items

Fix #897

> https://code.videolan.org/videolan/vlc-android/commit/082fb7eee10da5f728d0b83ca17ca1440c6bf404
---

 .../src/org/videolan/vlc/providers/BrowserProvider.kt   |  4 ++--
 .../src/org/videolan/vlc/providers/StorageProvider.kt   | 17 ++++++++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index f4e2812eb..19c87b64e 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -55,7 +55,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
     protected var mediabrowser: MediaBrowser? = null
 
     private val foldersContentMap = SimpleArrayMap<MediaLibraryItem, MutableList<MediaLibraryItem>>()
-    private lateinit var browserChannel : Channel<Media>
+    protected lateinit var browserChannel : Channel<Media>
     private val showAll = Settings.getInstance(context).getBoolean("browser_show_all_files", true)
 
     val descriptionUpdate = MutableLiveData<Pair<Int, String>>()
@@ -249,7 +249,7 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         return flags
     }
 
-    private suspend fun requestBrowsing(url: String?) = withContext(Dispatchers.IO) {
+    protected suspend fun requestBrowsing(url: String?) = withContext(Dispatchers.IO) {
         initBrowser()
         mediabrowser?.let {
             if (url != null) it.browse(Uri.parse(url), getFlags())
diff --git a/vlc-android/src/org/videolan/vlc/providers/StorageProvider.kt b/vlc-android/src/org/videolan/vlc/providers/StorageProvider.kt
index 04dda25b6..61aa4931d 100644
--- a/vlc-android/src/org/videolan/vlc/providers/StorageProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/StorageProvider.kt
@@ -23,6 +23,10 @@ package org.videolan.vlc.providers
 import android.content.Context
 import android.net.Uri
 import android.text.TextUtils
+import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.channels.filter
+import kotlinx.coroutines.channels.mapTo
+import org.videolan.libvlc.Media
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.medialibrary.media.Storage
@@ -66,4 +70,15 @@ class StorageProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>,
         } else if (media.itemType != MediaLibraryItem.TYPE_STORAGE) return
         super.addMedia(media)
     }
-}
\ No newline at end of file
+
+    override suspend fun refreshImpl() {
+        browserChannel = Channel(Channel.UNLIMITED)
+        requestBrowsing(url)
+        val value: MutableList<MediaLibraryItem> = browserChannel.filter { it.isStorage() }.mapTo(mutableListOf()) { Storage(it.uri)}
+        dataset.value = value
+        parseSubDirectories()
+        loading.value = false
+    }
+}
+
+private fun Media.isStorage() = type == Media.Type.Directory



More information about the Android mailing list