[Android] Albums: fix sorting

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 23 16:07:13 2022 +0200| [ab9d0f9b00c8b8b563fd653d5aedf1a7f754a0f2] | committer: Nicolas Pomepuy

Albums: fix sorting

Sorting was applied to the pagedList from the track provider, and not
the track list with the playlist medialibrary item. Using the
trackProvider to play tracks now.

Fixes #2532

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

 .../vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt   | 4 ++--
 application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt      | 4 ++++
 .../src/org/videolan/vlc/providers/medialibrary/TracksProvider.kt     | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index 74f13ac8d..2943129c7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -258,7 +258,7 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
             invalidateActionMode()
         } else {
             if (searchView.visibility == View.VISIBLE) UiTools.setKeyboardVisibility(v, false)
-            MediaUtils.playTracks(this, viewModel.playlist, position)
+            MediaUtils.playTracks(this, viewModel.tracksProvider, position)
         }
     }
 
@@ -461,7 +461,7 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
     }
 
     override fun onClick(v: View) {
-        MediaUtils.playTracks(this, viewModel.playlist, 0)
+        MediaUtils.playTracks(this, viewModel.tracksProvider, 0)
     }
 
     private fun removeFromPlaylist(list: List<MediaWrapper>, indexes: List<Int>) {
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index 3179a6a20..7845e88d6 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -187,6 +187,10 @@ object MediaUtils {
         openList(context, withContext(Dispatchers.IO) { item.tracks }.toList(), position, shuffle)
     }
 
+    fun playTracks(context: Context, provider: MedialibraryProvider<MediaWrapper>, position: Int, shuffle: Boolean = false) = context.scope.launch {
+        withContext(Dispatchers.IO) { provider.pagedList }.value?.let { openList(context, it.toList(), position, shuffle) }
+    }
+
     fun playAlbums(context: Context?, provider: MedialibraryProvider<Album>, position: Int, shuffle: Boolean) {
         if (context == null) return
         SuspendDialogCallback(context) { service ->
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 e0148c99d..013398446 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
@@ -50,7 +50,7 @@ class TracksProvider(val parent : MediaLibraryItem?, context: Context, model: So
         }
     }
 
-    override fun getAll(): Array<MediaWrapper> = parent?.tracks ?: medialibrary.getAudio(sort, desc, Settings.includeMissing)
+    override fun getAll(): Array<MediaWrapper> = this.pagedList.value?.toTypedArray() ?: medialibrary.getAudio(sort, desc, Settings.includeMissing)
 
     override fun getPage(loadSize: Int, startposition: Int) : Array<MediaWrapper> {
         val list = if (model.filterQuery == null) when(parent) {



More information about the Android mailing list