[Android] Browser: Fix non existing favorites

Geoffrey Métais git at videolan.org
Fri Apr 24 17:44:29 CEST 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr 24 10:15:13 2020 +0200| [5806940027f339e238a9dbe3cbdc78bc3cef6b99] | committer: Nicolas Pomepuy

Browser: Fix non existing favorites

Also fix favorites convertion with wrong dispatchers

> https://code.videolan.org/videolan/vlc-android/commit/5806940027f339e238a9dbe3cbdc78bc3cef6b99
---

 application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt  | 5 ++++-
 .../org/videolan/vlc/viewmodels/browser/BrowserFavoritesModel.kt   | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index c82d54f78..39f17aebd 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -25,13 +25,16 @@ import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.vlc.mediadb.models.BrowserFav
+import java.io.File
 
 fun isSchemeSupported(scheme: String?) = when(scheme) {
     "file", "smb", "ssh", "nfs", "content" -> true
     else -> false
 }
 
-fun convertFavorites(browserFavs: List<BrowserFav>?) = browserFavs?.map { (uri, _, title, iconUrl) ->
+fun convertFavorites(browserFavs: List<BrowserFav>?) = browserFavs?.filter {
+    it.uri.scheme != "file" || File(it.uri.path).exists()
+}?.map { (uri, _, title, iconUrl) ->
     MLServiceLocator.getAbstractMediaWrapper(uri).apply {
         setDisplayTitle(Uri.decode(title))
         type = MediaWrapper.TYPE_DIR
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserFavoritesModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserFavoritesModel.kt
index e766f965f..f4a2bed6b 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserFavoritesModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserFavoritesModel.kt
@@ -57,13 +57,14 @@ class FavoritesProvider(
 
     init {
         browserFavRepository.browserFavorites
-                .flowOn(Dispatchers.IO)
                 .onEach { list ->
                     convertFavorites(list.sortedWith(compareBy(BrowserFav::title, BrowserFav::type))).let {
-                        dataset.value = it as MutableList<MediaLibraryItem>
+                        dataset.postValue(it as MutableList<MediaLibraryItem>)
                         parseSubDirectories()
                     }
-                }.launchIn(scope)
+                }
+                .flowOn(Dispatchers.IO)
+                .launchIn(scope)
     }
 
     override suspend fun requestBrowsing(url: String?, eventListener: MediaBrowser.EventListener, interact : Boolean) = withContext(coroutineContextProvider.IO) {



More information about the Android mailing list