[Android] Allow sorting tracks by filename
Nicolas Pomepuy
git at videolan.org
Tue Apr 28 15:52:43 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Apr 28 13:55:48 2020 +0200| [77acece50bcb621a3cf0983270515f848fcf9a69] | committer: Geoffrey Métais
Allow sorting tracks by filename
> https://code.videolan.org/videolan/vlc-android/commit/77acece50bcb621a3cf0983270515f848fcf9a69
---
.../org/videolan/vlc/providers/medialibrary/TracksProvider.kt | 2 +-
.../vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
index e484639bd..efc84fcf0 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt
@@ -38,7 +38,7 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, model: So
override fun canSortByLastModified() = parent !is Playlist
override fun canSortByReleaseDate() = parent !is Playlist
override fun canSortByName() = parent !is Playlist
- override fun canSortByFileNameName() = parent is Album
+ override fun canSortByFileNameName() = parent !is Playlist
override fun canSortByTrackId() = parent is Album
init {
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 824c568c7..12fdba390 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -107,7 +107,6 @@ object ModelsHelper {
fun getHeader(context: Context?, sort: Int, item: MediaLibraryItem?, aboveItem: MediaLibraryItem?) = if (context !== null && item != null) when (sort) {
SORT_DEFAULT,
- SORT_FILENAME,
SORT_ALPHA -> {
val letter = if (item.title.isEmpty() || !Character.isLetter(item.title[0]) || item.isSpecialItem()) "#" else item.title.substring(0, 1).toUpperCase()
if (aboveItem == null) letter
@@ -166,6 +165,16 @@ object ModelsHelper {
album.takeIf { it != previous }
}
}
+ SORT_FILENAME -> {
+ val title = FileUtils.getFileNameFromPath((item as? MediaWrapper)?.uri.toString())
+ val aboveTitle = FileUtils.getFileNameFromPath((aboveItem as? MediaWrapper)?.uri.toString())
+ val letter = if (title.isEmpty() || !Character.isLetter(title[0]) || item.isSpecialItem()) "#" else title.substring(0, 1).toUpperCase()
+ if (aboveItem == null) letter
+ else {
+ val previous = if (aboveTitle.isEmpty() || !Character.isLetter(aboveTitle[0]) || aboveItem.isSpecialItem()) "#" else aboveTitle.substring(0, 1).toUpperCase()
+ letter.takeIf { it != previous }
+ }
+ }
else -> null
} else null
}
More information about the Android
mailing list