[Android] Fix files filtering/grouping in browsers

Geoffrey Métais git at videolan.org
Mon Jan 7 17:22:00 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  7 16:55:22 2019 +0100| [77e3a42dfcd33748d3c69f3edca2f4c32a65416a] | committer: Geoffrey Métais

Fix files filtering/grouping in browsers

> https://code.videolan.org/videolan/vlc-android/commit/77e3a42dfcd33748d3c69f3edca2f4c32a65416a
---

 vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt  | 10 +++++-----
 vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt          | 10 +++++-----
 .../src/org/videolan/vlc/viewmodels/browser/NetworkModel.kt    |  6 +-----
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 9fe3d90ea..4cc3e1ca7 100644
--- a/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -40,10 +40,7 @@ import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.medialibrary.media.Storage
 import org.videolan.vlc.R
-import org.videolan.vlc.util.LiveDataset
-import org.videolan.vlc.util.Settings
-import org.videolan.vlc.util.VLCInstance
-import org.videolan.vlc.util.isBrowserMedia
+import org.videolan.vlc.util.*
 import java.util.*
 
 const val TAG = "VLC/BrowserProvider"
@@ -207,7 +204,10 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
     private suspend fun findMedia(media: Media): MediaWrapper? {
         val mw = MediaWrapper(media)
         media.release()
-        if (!showAll && !mw.isBrowserMedia()) return null
+        if (!mw.isMedia()) {
+            if (mw.isBrowserMedia()) return mw
+            else if (!showAll) return null
+        }
         val uri = mw.uri
         if ((mw.type == MediaWrapper.TYPE_AUDIO || mw.type == MediaWrapper.TYPE_VIDEO)
                 && "file" == uri.scheme) return withContext(Dispatchers.IO) { medialibrary.getMedia(uri) ?: mw }
diff --git a/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 29c1a534c..da93326e5 100644
--- a/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -40,7 +40,7 @@ object ModelsHelper {
                     val letter = if (title.isEmpty() || !Character.isLetter(title[0]) || ModelsHelper.isSpecialItem(item)) "#" else title.substring(0, 1).toUpperCase()
                     if (currentLetter === null || !TextUtils.equals(currentLetter, letter)) {
                         currentLetter = letter
-                        array[letter] = mutableListOf()
+                        if (array[letter].isNullOrEmpty()) array[letter] = mutableListOf()
                     }
                     array[letter]?.add(item)
                 }
@@ -53,7 +53,7 @@ object ModelsHelper {
                     val lengthCategory = ModelsHelper.lengthToCategory(length)
                     if (currentLengthCategory == null || !TextUtils.equals(currentLengthCategory, lengthCategory)) {
                         currentLengthCategory = lengthCategory
-                        array[currentLengthCategory] = mutableListOf()
+                        if (array[currentLengthCategory].isNullOrEmpty()) array[currentLengthCategory] = mutableListOf()
                     }
                     array[currentLengthCategory]?.add(item)
                 }
@@ -65,7 +65,7 @@ object ModelsHelper {
                     val year = ModelsHelper.getYear(item)
                     if (currentYear === null || !TextUtils.equals(currentYear, year)) {
                         currentYear = year
-                        array[currentYear] = mutableListOf()
+                        if (array[currentYear].isNullOrEmpty()) array[currentYear] = mutableListOf()
                     }
                     array[currentYear]?.add(item)
                 }
@@ -77,7 +77,7 @@ object ModelsHelper {
                     val artist = (item as MediaWrapper).artist ?: ""
                     if (currentArtist === null || !TextUtils.equals(currentArtist, artist)) {
                         currentArtist = artist
-                        array[currentArtist] = mutableListOf()
+                        if (array[currentArtist].isNullOrEmpty()) array[currentArtist] = mutableListOf()
                     }
                     array[currentArtist]?.add(item)
                 }
@@ -89,7 +89,7 @@ object ModelsHelper {
                     val album = (item as MediaWrapper).album ?: ""
                     if (currentAlbum === null || !TextUtils.equals(currentAlbum, album)) {
                         currentAlbum = album
-                        array[currentAlbum] = mutableListOf()
+                        if (array[currentAlbum].isNullOrEmpty()) array[currentAlbum] = mutableListOf()
                     }
                     array[currentAlbum]?.add(item)
                 }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkModel.kt
index 1a677715e..75a144676 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/NetworkModel.kt
@@ -20,16 +20,12 @@
 
 package org.videolan.vlc.viewmodels.browser
 
+import android.content.Context
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModelProvider
-import android.content.Context
 
 class NetworkModel(context: Context, url: String? = null, showHiddenFiles: Boolean): BrowserModel(context, url, TYPE_NETWORK, showHiddenFiles) {
 
-    override fun refresh() : Boolean {
-        return provider.refresh()
-    }
-
     class Factory(val context: Context, val url: String?, private val showHiddenFiles: Boolean): ViewModelProvider.NewInstanceFactory() {
         override fun <T : ViewModel> create(modelClass: Class<T>): T {
             @Suppress("UNCHECKED_CAST")



More information about the Android mailing list