[Android] Show the audio playlists in the audio screen

Nicolas Pomepuy git at videolan.org
Tue Oct 25 06:38:26 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Oct 10 11:45:07 2022 +0200| [4f82ea731b60ad4b175a8de2672e549f7215ebd4] | committer: Nicolas Pomepuy

Show the audio playlists in the audio screen

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

 application/vlc-android/res/layout/audio_browser.xml       |  2 ++
 .../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt |  8 +++++---
 .../vlc/providers/medialibrary/PlaylistsProvider.kt        |  2 +-
 .../vlc/viewmodels/mobile/AudioBrowserViewModel.kt         | 14 +++++++-------
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/res/layout/audio_browser.xml b/application/vlc-android/res/layout/audio_browser.xml
index ed58ba127..6926343ee 100644
--- a/application/vlc-android/res/layout/audio_browser.xml
+++ b/application/vlc-android/res/layout/audio_browser.xml
@@ -37,6 +37,8 @@
             <include layout="@layout/audio_recyclerview" />
 
             <include layout="@layout/audio_recyclerview" />
+
+            <include layout="@layout/audio_recyclerview" />
         </androidx.viewpager.widget.ViewPager>
     </org.videolan.vlc.gui.view.SwipeRefreshLayout>
 
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index eab4b2dc7..5a3bf4ff4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -70,6 +70,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
     private lateinit var artistsAdapter: AudioBrowserAdapter
     private lateinit var albumsAdapter: AudioBrowserAdapter
     private lateinit var genresAdapter: AudioBrowserAdapter
+    private lateinit var playlistAdapter: AudioBrowserAdapter
     private lateinit var emptyView: EmptyLoadingStateView
     private lateinit var fastScroller: FastScroller
 
@@ -118,7 +119,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
                 lists.add(it.findViewById(R.id.audio_list))
             }
         }
-        val titles = arrayOf(getString(R.string.artists), getString(R.string.albums), getString(R.string.tracks), getString(R.string.genres))
+        val titles = arrayOf(getString(R.string.artists), getString(R.string.albums), getString(R.string.tracks), getString(R.string.genres), getString(R.string.playlists))
         viewPager.offscreenPageLimit = MODE_TOTAL - 1
         val audioPagerAdapter = AudioPagerAdapter(views.toTypedArray(), titles)
         @Suppress("UNCHECKED_CAST")
@@ -186,7 +187,8 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
         albumsAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_ALBUM, this).apply { stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY }
         songsAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_MEDIA, this).apply { stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY }
         genresAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_GENRE, this).apply { stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY }
-        adapters = arrayOf(artistsAdapter, albumsAdapter, songsAdapter, genresAdapter)
+        playlistAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this).apply { stateRestorationPolicy = RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY }
+        adapters = arrayOf(artistsAdapter, albumsAdapter, songsAdapter, genresAdapter, playlistAdapter)
         setupProvider()
     }
 
@@ -402,7 +404,7 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
         const val TAG = "VLC/AudioBrowserFragment"
 
         private const val KEY_LISTS_POSITIONS = "key_lists_position"
-        private const val MODE_TOTAL = 4 // Number of audio lists
+        private const val MODE_TOTAL = 5 // Number of audio lists
 
         const val TAG_ITEM = "ML_ITEM"
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
index 862b53614..a07675c7c 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/PlaylistsProvider.kt
@@ -33,7 +33,7 @@ class PlaylistsProvider(context: Context, model: SortableModel, val type: Playli
 
     override fun getPage(loadSize: Int, startposition: Int)  : Array<Playlist> {
         val list = if (model.filterQuery == null) medialibrary.getPagedPlaylists(type, sort, desc, Settings.includeMissing, loadSize, startposition)
-        else medialibrary.searchPlaylist(model.filterQuery, Playlist.Type.All, sort, desc, Settings.includeMissing, loadSize, startposition)
+        else medialibrary.searchPlaylist(model.filterQuery, type, sort, desc, Settings.includeMissing, loadSize, startposition)
         model.viewModelScope.launch { completeHeaders(list, startposition) }
         return list
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
index a5abd6ff6..3b3e4df9d 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/mobile/AudioBrowserViewModel.kt
@@ -25,14 +25,12 @@ import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.viewModelScope
 import kotlinx.coroutines.launch
+import org.videolan.medialibrary.interfaces.media.Playlist
 import org.videolan.resources.KEY_AUDIO_CURRENT_TAB
 import org.videolan.tools.KEY_ARTISTS_SHOW_ALL
 import org.videolan.tools.Settings
 import org.videolan.vlc.gui.audio.AudioBrowserFragment
-import org.videolan.vlc.providers.medialibrary.AlbumsProvider
-import org.videolan.vlc.providers.medialibrary.ArtistsProvider
-import org.videolan.vlc.providers.medialibrary.GenresProvider
-import org.videolan.vlc.providers.medialibrary.TracksProvider
+import org.videolan.vlc.providers.medialibrary.*
 import org.videolan.vlc.viewmodels.MedialibraryViewModel
 
 class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
@@ -43,11 +41,12 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
     val albumsProvider = AlbumsProvider(null, context, this)
     val tracksProvider = TracksProvider(null, context, this)
     val genresProvider = GenresProvider(context, this)
-    override val providers = arrayOf(artistsProvider, albumsProvider, tracksProvider, genresProvider)
-    val providersInCard = arrayOf(true, true, false, false)
+    private val playlistsProvider = PlaylistsProvider(context, this, Playlist.Type.AudioOnly)
+    override val providers = arrayOf(artistsProvider, albumsProvider, tracksProvider, genresProvider, playlistsProvider)
+    val providersInCard = arrayOf(true, true, false, false, true)
 
     var showResumeCard = settings.getBoolean("audio_resume_card", true)
-    val displayModeKeys = arrayOf("display_mode_audio_browser_artists", "display_mode_audio_browser_albums", "display_mode_audio_browser_track", "display_mode_audio_browser_genres")
+    val displayModeKeys = arrayOf("display_mode_audio_browser_artists", "display_mode_audio_browser_albums", "display_mode_audio_browser_track", "display_mode_audio_browser_genres", "display_mode_playlists")
 
 
     init {
@@ -55,6 +54,7 @@ class AudioBrowserViewModel(context: Context) : MedialibraryViewModel(context) {
         watchArtists()
         watchGenres()
         watchMedia()
+        watchPlaylists()
         //Initial state coming from preferences and falling back to [providersInCard] hardcoded values
         for (i in displayModeKeys.indices) {
             providersInCard[i] = settings.getBoolean(displayModeKeys[i], providersInCard[i])



More information about the Android mailing list