[Android] Use the natural sort for the TV file browser

Nicolas Pomepuy git at videolan.org
Mon May 13 13:13:55 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Apr 30 13:12:00 2024 +0200| [2d8b3341d7cd09b0b0b860843622752da32b9a04] | committer: Nicolas Pomepuy

Use the natural sort for the TV file browser

Fixes #3063

> https://code.videolan.org/videolan/vlc-android/commit/2d8b3341d7cd09b0b0b860843622752da32b9a04
---

 .../src/org/videolan/vlc/providers/BrowserProvider.kt       |  4 ++--
 .../vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt   | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index ad3405f24d..6d580d6672 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -109,8 +109,8 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         else -> true
     }
     fun getComparator(nbOfDigits: Int): Comparator<MediaLibraryItem>? = when {
-            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT, Medialibrary.SORT_FILENAME) && desc -> getTvDescComp(Settings.tvFoldersFirst)
-            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT, Medialibrary.SORT_FILENAME) && !desc -> getTvAscComp(Settings.tvFoldersFirst)
+            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT) && desc -> getTvDescComp(Settings.tvFoldersFirst)
+            Settings.showTvUi && sort in arrayOf(Medialibrary.SORT_ALPHA, Medialibrary.SORT_DEFAULT) && !desc -> getTvAscComp(Settings.tvFoldersFirst)
             url != null && Uri.parse(url)?.scheme == "upnp" -> null
             sort == Medialibrary.SORT_ALPHA && desc -> descComp
             sort == Medialibrary.SORT_ALPHA && !desc -> ascComp
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index d4e2926779..a787e47b7a 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -12,6 +12,7 @@ import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.Storage
 import org.videolan.resources.util.*
+import org.videolan.tools.Settings
 import org.videolan.vlc.PlaybackService
 import java.util.*
 import kotlin.math.floor
@@ -298,6 +299,12 @@ fun getTvDescComp(foldersFirst: Boolean): Comparator<MediaLibraryItem> = Compara
 }
 
 fun getFilenameAscComp(nbOfDigits: Int): Comparator<MediaLibraryItem> = Comparator<MediaLibraryItem> { item1, item2 ->
+    if (Settings.showTvUi && Settings.tvFoldersFirst) {
+        val type1 = (item1 as? MediaWrapper)?.type
+        val type2 = (item2 as? MediaWrapper)?.type
+        if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
+        else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
+    }
     val type1 = (item1 as? MediaWrapper)?.type
     val type2 = (item2 as? MediaWrapper)?.type
     if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
@@ -309,6 +316,12 @@ fun getFilenameAscComp(nbOfDigits: Int): Comparator<MediaLibraryItem> = Comparat
 }
 
 fun getFilenameDescComp(nbOfDigits: Int): Comparator<MediaLibraryItem> = Comparator<MediaLibraryItem> { item1, item2 ->
+    if (Settings.showTvUi && Settings.tvFoldersFirst) {
+        val type1 = (item1 as? MediaWrapper)?.type
+        val type2 = (item2 as? MediaWrapper)?.type
+        if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
+        else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
+    }
     val type1 = (item1 as? MediaWrapper)?.type
     val type2 = (item2 as? MediaWrapper)?.type
     if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1



More information about the Android mailing list