[Android] Browser: fix filename sort
Duncan McNamara
git at videolan.org
Tue Jun 7 08:00:51 UTC 2022
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Mon May 30 15:16:39 2022 +0200| [0e737ea395ee573736a4ae333aba570b0c7ea0a2] | committer: Nicolas Pomepuy
Browser: fix filename sort
> https://code.videolan.org/videolan/vlc-android/commit/0e737ea395ee573736a4ae333aba570b0c7ea0a2
---
.../src/org/videolan/vlc/util/ModelsHelper.kt | 24 ++++++++++++++++++++++
.../vlc/viewmodels/browser/BrowserModel.kt | 6 +++++-
2 files changed, 29 insertions(+), 1 deletion(-)
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 b5f4efef7..53311f464 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -280,4 +280,28 @@ val tvDescComp by lazy {
else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
item2?.title?.lowercase(Locale.getDefault())?.compareTo(item1?.title?.lowercase(Locale.getDefault()) ?: "") ?: -1
}
+}
+
+val filenameAscComp by lazy {
+ Comparator<MediaLibraryItem> { item1, item2 ->
+ 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 filename1 = (item1 as? MediaWrapper)?.fileName
+ val filename2 = (item2 as? MediaWrapper)?.fileName
+ filename1?.lowercase(Locale.getDefault())?.compareTo(filename2?.lowercase(Locale.getDefault()) ?: "") ?: -1
+ }
+}
+
+val filenameDescComp by lazy {
+ Comparator<MediaLibraryItem> { item1, item2 ->
+ 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 filename1 = (item1 as? MediaWrapper)?.fileName
+ val filename2 = (item2 as? MediaWrapper)?.fileName
+ filename2?.lowercase(Locale.getDefault())?.compareTo(filename1?.lowercase(Locale.getDefault()) ?: "") ?: -1
+ }
}
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index 9e35cb7b5..fc63f2c06 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -83,7 +83,11 @@ open class BrowserModel(
val comp = if (tv) {
if (desc) tvDescComp else tvAscComp
} else {
- if (desc) descComp else ascComp
+ when (sort) {
+ Medialibrary.SORT_FILENAME -> if (desc) filenameDescComp else filenameAscComp
+ else -> if (desc) descComp else ascComp
+ }
+
}
dataset.value = withContext(coroutineContextProvider.Default) { dataset.value.apply { sortWith(comp) }.also { provider.computeHeaders(dataset.value) } }
}
More information about the Android
mailing list