[Android] TV: Fix browsing in artists and genres categories

Geoffrey Métais git at videolan.org
Mon Apr 20 08:03:07 CEST 2020


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Apr 17 12:19:27 2020 +0200| [1de22262c00573098752e97af402569ab0129d51] | committer: Nicolas Pomepuy

TV: Fix browsing in artists and genres categories

All albums of all artists/genres were displayed

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

 .../src/main/java/org/videolan/television/ui/TvUtil.kt       |  2 +-
 .../videolan/television/ui/browser/MediaBrowserTvFragment.kt |  5 +++--
 .../videolan/television/viewmodel/MediaBrowserViewModel.kt   | 12 ++++++------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
index 8940f62b9..96ed9afa6 100644
--- a/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/TvUtil.kt
@@ -310,7 +310,7 @@ object TvUtil {
                 val intent = Intent(context, VerticalGridActivity::class.java)
                 intent.putExtra(ITEM, mediaLibraryItem)
                 intent.putExtra(CATEGORY, CATEGORY_ALBUMS)
-                intent.putExtra(org.videolan.television.ui.MainTvActivity.BROWSER_TYPE, HEADER_CATEGORIES)
+                intent.putExtra(MainTvActivity.BROWSER_TYPE, HEADER_CATEGORIES)
                 context.startActivity(intent)
             }
         }
diff --git a/application/television/src/main/java/org/videolan/television/ui/browser/MediaBrowserTvFragment.kt b/application/television/src/main/java/org/videolan/television/ui/browser/MediaBrowserTvFragment.kt
index 8dec7fa35..a8ab721dd 100644
--- a/application/television/src/main/java/org/videolan/television/ui/browser/MediaBrowserTvFragment.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/browser/MediaBrowserTvFragment.kt
@@ -71,11 +71,12 @@ class MediaBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
 
-        viewModel = getMediaBrowserModel(arguments?.getLong(CATEGORY, CATEGORY_SONGS) ?: CATEGORY_SONGS)
 
-        viewModel.currentItem = if (savedInstanceState != null) savedInstanceState.getParcelable<Parcelable>(ITEM) as? MediaLibraryItem
+        val currentItem = if (savedInstanceState != null) savedInstanceState.getParcelable<Parcelable>(ITEM) as? MediaLibraryItem
         else requireActivity().intent.getParcelableExtra<Parcelable>(ITEM) as? MediaLibraryItem
 
+        viewModel = getMediaBrowserModel(arguments?.getLong(CATEGORY, CATEGORY_SONGS) ?: CATEGORY_SONGS, currentItem)
+
         (viewModel.provider as MedialibraryProvider<*>).pagedList.observe(this, Observer { items ->
             submitList(items)
 
diff --git a/application/television/src/main/java/org/videolan/television/viewmodel/MediaBrowserViewModel.kt b/application/television/src/main/java/org/videolan/television/viewmodel/MediaBrowserViewModel.kt
index 1494578e5..97bce85b8 100644
--- a/application/television/src/main/java/org/videolan/television/viewmodel/MediaBrowserViewModel.kt
+++ b/application/television/src/main/java/org/videolan/television/viewmodel/MediaBrowserViewModel.kt
@@ -17,14 +17,14 @@ import org.videolan.vlc.viewmodels.tv.TvBrowserModel
 
 
 @ExperimentalCoroutinesApi
-class MediaBrowserViewModel(context: Context, val category: Long) : MedialibraryViewModel(context), TvBrowserModel<MediaLibraryItem> {
+class MediaBrowserViewModel(context: Context, val category: Long, val parent : MediaLibraryItem?) : MedialibraryViewModel(context), TvBrowserModel<MediaLibraryItem> {
 
 
     override var nbColumns = 0
-    override var currentItem: MediaLibraryItem? = null
+    override var currentItem: MediaLibraryItem? = parent
 
     override val provider = when (category) {
-        CATEGORY_ALBUMS -> AlbumsProvider(null, context, this)
+        CATEGORY_ALBUMS -> AlbumsProvider(parent, context, this)
         CATEGORY_ARTISTS -> ArtistsProvider(context, this, true)
         CATEGORY_GENRES -> GenresProvider(context, this)
         CATEGORY_VIDEOS -> VideosProvider(null, null, context, this)
@@ -41,13 +41,13 @@ class MediaBrowserViewModel(context: Context, val category: Long) : Medialibrary
         }
     }
 
-    class Factory(private val context: Context, private val category: Long) : ViewModelProvider.NewInstanceFactory() {
+    class Factory(private val context: Context, private val category: Long, private val parent : MediaLibraryItem?) : ViewModelProvider.NewInstanceFactory() {
         override fun <T : ViewModel> create(modelClass: Class<T>): T {
             @Suppress("UNCHECKED_CAST")
-            return MediaBrowserViewModel(context.applicationContext, category) as T
+            return MediaBrowserViewModel(context.applicationContext, category, parent) as T
         }
     }
 }
 
 @ExperimentalCoroutinesApi
-fun Fragment.getMediaBrowserModel(category: Long) = ViewModelProviders.of(requireActivity(), MediaBrowserViewModel.Factory(requireContext(), category)).get(MediaBrowserViewModel::class.java)
+fun Fragment.getMediaBrowserModel(category: Long, parent : MediaLibraryItem? = null) = ViewModelProviders.of(requireActivity(), MediaBrowserViewModel.Factory(requireContext(), category, parent)).get(MediaBrowserViewModel::class.java)



More information about the Android mailing list