[Android] Fix filename comparators for Storage objects

Nicolas Pomepuy git at videolan.org
Tue Jul 5 09:23:24 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul  4 14:33:41 2022 +0200| [6b86c54777dadd8cc4bb9ec45d380454dc1c229c] | committer: Duncan McNamara

Fix filename comparators for Storage objects

> https://code.videolan.org/videolan/vlc-android/commit/6b86c54777dadd8cc4bb9ec45d380454dc1c229c
---

 .../vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt        | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

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 53311f464..01c2c3d3c 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -10,6 +10,7 @@ import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 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.vlc.PlaybackService
 import java.util.*
@@ -288,8 +289,8 @@ val filenameAscComp by lazy {
         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 filename1 = (item1 as? MediaWrapper)?.fileName
-        val filename2 = (item2 as? MediaWrapper)?.fileName
+        val filename1 = (item1 as? MediaWrapper)?.fileName ?: (item1 as? Storage)?.title
+        val filename2 = (item2 as? MediaWrapper)?.fileName ?: (item2 as? Storage)?.title
         filename1?.lowercase(Locale.getDefault())?.compareTo(filename2?.lowercase(Locale.getDefault()) ?: "") ?: -1
     }
 }
@@ -300,8 +301,8 @@ val filenameDescComp by lazy {
         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 filename1 = (item1 as? MediaWrapper)?.fileName
-        val filename2 = (item2 as? MediaWrapper)?.fileName
+        val filename1 = (item1 as? MediaWrapper)?.fileName ?: (item1 as? Storage)?.title
+        val filename2 = (item2 as? MediaWrapper)?.fileName ?: (item2 as? Storage)?.title
         filename2?.lowercase(Locale.getDefault())?.compareTo(filename1?.lowercase(Locale.getDefault()) ?: "") ?: -1
     }
 }
\ No newline at end of file



More information about the Android mailing list