[Android] Allow displaying the playlists in list mode
Nicolas Pomepuy
git at videolan.org
Thu Dec 12 15:06:50 CET 2019
vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Dec 12 13:56:36 2019 +0000| [f986995b10309e82708e05d6265e7dd22d9feffd] | committer: Geoffrey Métais
Allow displaying the playlists in list mode
Fixes #1122
(cherry picked from commit 4703fa12441b7b38530c71de6222db393ac2ea92)
> https://code.videolan.org/videolan/vlc-android/commit/f986995b10309e82708e05d6265e7dd22d9feffd
---
vlc-android/res/layout/audio_browser_item.xml | 8 +++-
.../src/org/videolan/vlc/gui/PlaylistFragment.kt | 49 +++++++++++++++++++---
.../videolan/vlc/gui/audio/AudioBrowserAdapter.kt | 3 ++
.../vlc/viewmodels/mobile/PlaylistsViewModel.kt | 5 +++
4 files changed, 58 insertions(+), 7 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index c8b3426d8..b3eefa7db 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -24,6 +24,9 @@
name="bgColor"
type="int" />
+ <variable
+ name="imageWidth"
+ type="int" />
<variable
name="holder"
@@ -65,12 +68,13 @@
android:layout_marginBottom="8dp"
android:background="@{cover}"
android:onClick="@{holder::onImageClick}"
- android:visibility="@{(item.getItemType() & (MediaLibraryItem.TYPE_ALBUM|MediaLibraryItem.TYPE_ARTIST|MediaLibraryItem.TYPE_MEDIA)) != 0 ? View.VISIBLE : View.GONE, default=gone}"
+ android:visibility="@{(item.getItemType() & (MediaLibraryItem.TYPE_ALBUM|MediaLibraryItem.TYPE_ARTIST|MediaLibraryItem.TYPE_MEDIA|MediaLibraryItem.TYPE_PLAYLIST)) != 0 ? View.VISIBLE : View.GONE, default=gone}"
vlc:layout_constraintBottom_toBottomOf="parent"
vlc:layout_constraintDimensionRatio="1"
vlc:layout_constraintTop_toTopOf="parent"
vlc:layout_constraintStart_toEndOf="@id/item_move"
android:layout_gravity="center"
+ vlc:imageWidth="@{imageWidth}"
vlc:media="@{item}"/>
@@ -101,7 +105,7 @@
style="@style/VLC.TextViewDescription"
android:layout_width="0dp"
android:layout_height="wrap_content"
- vlc:asyncText="@{item.description}"
+ vlc:asyncText="@{item}"
vlc:layout_constraintBottom_toBottomOf="parent"
vlc:layout_constraintEnd_toEndOf="@+id/title"
vlc:layout_constraintStart_toStartOf="@+id/title"
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index 28dccac59..e122f89e4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -23,14 +23,12 @@ package org.videolan.vlc.gui
import android.content.Intent
import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.Menu
-import android.view.View
-import android.view.ViewGroup
+import android.view.*
import androidx.appcompat.view.ActionMode
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.lifecycle.Observer
import androidx.paging.PagedList
+import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.appbar.AppBarLayout
@@ -46,11 +44,13 @@ import org.videolan.vlc.gui.audio.AudioBrowserAdapter
import org.videolan.vlc.gui.audio.AudioBrowserFragment
import org.videolan.vlc.gui.audio.BaseAudioBrowser
import org.videolan.vlc.gui.view.FastScroller
+import org.videolan.vlc.gui.view.RecyclerSectionItemDecoration
import org.videolan.vlc.gui.view.RecyclerSectionItemGridDecoration
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.reloadLibrary
import org.videolan.vlc.util.CTX_PLAY_ALL
+import org.videolan.vlc.util.Settings
import org.videolan.vlc.util.getScreenWidth
import org.videolan.vlc.viewmodels.mobile.PlaylistsViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
@@ -92,7 +92,7 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
playlistAdapter = AudioBrowserAdapter(MediaLibraryItem.TYPE_PLAYLIST, this, cardSize = itemSize)
adapter = playlistAdapter
- displayListInGrid(playlists, adapter!!, viewModel.provider as MedialibraryProvider<MediaLibraryItem>, spacing)
+ setupLayoutManager()
playlists.adapter = playlistAdapter
fastScroller = view.rootView.findViewById(R.id.songs_fast_scroller) as FastScroller
@@ -122,6 +122,45 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
return true
}
+ override fun onPrepareOptionsMenu(menu: Menu) {
+ menu.findItem(R.id.ml_menu_display_grid).isVisible = !viewModel.providerInCard
+ menu.findItem(R.id.ml_menu_display_list).isVisible = viewModel.providerInCard
+ super.onPrepareOptionsMenu(menu)
+ }
+
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
+ return when (item.itemId) {
+ R.id.ml_menu_display_list, R.id.ml_menu_display_grid -> {
+ viewModel.providerInCard = item.itemId == R.id.ml_menu_display_grid
+ setupLayoutManager()
+ playlists.adapter = adapter
+ activity?.invalidateOptionsMenu()
+ Settings.getInstance(requireActivity()).edit().putBoolean(viewModel.displayModeKey, item.itemId == R.id.ml_menu_display_grid).apply()
+ true
+ }
+ else -> super.onOptionsItemSelected(item)
+ }
+ }
+
+ private fun setupLayoutManager() {
+ val spacing = resources.getDimension(R.dimen.kl_half).toInt()
+
+ if (playlists.itemDecorationCount > 0) {
+ playlists.removeItemDecorationAt(0)
+ }
+ when (viewModel.providerInCard) {
+ true -> {
+ adapter?.cardSize = RecyclerSectionItemGridDecoration.getItemSize(requireActivity().getScreenWidth(), nbColumns, spacing)
+ adapter?.let { adapter -> displayListInGrid(playlists, adapter, viewModel.provider as MedialibraryProvider<MediaLibraryItem>, spacing) }
+ }
+ else -> {
+ adapter?.cardSize = -1
+ playlists.addItemDecoration(RecyclerSectionItemDecoration(resources.getDimensionPixelSize(R.dimen.recycler_section_header_height), true, viewModel.provider))
+ playlists.layoutManager = LinearLayoutManager(activity)
+ }
+ }
+ }
+
override fun onClick(v: View, position: Int, item: MediaLibraryItem) {
if (actionMode == null) {
val i = Intent(activity, PlaylistActivity::class.java)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
index 16bd6981d..8d6a482a8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
@@ -79,6 +79,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
AudioBrowserAdapter.AbstractMediaItemViewHolder<ViewDataBinding>>(DIFF_CALLBACK),
FastScroller.SeparatedAdapter, MultiSelectAdapter<MediaLibraryItem>, SwipeDragHelperAdapter
{
+ private var listImageWidth: Int
val multiSelectHelper: MultiSelectHelper<MediaLibraryItem> = MultiSelectHelper(this, UPDATE_SELECTION)
private val defaultCover: BitmapDrawable?
private var focusNext = -1
@@ -95,6 +96,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
is Fragment -> eventsHandler.requireContext()
else -> VLCApplication.appContext
}
+ listImageWidth = ctx.resources.getDimension(R.dimen.audio_browser_item_size).toInt()
defaultCover = getAudioIconDrawable(ctx, type, displayInCard())
}
@@ -244,6 +246,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
return false
}
}
+ binding.imageWidth = listImageWidth
}
override fun setItem(item: MediaLibraryItem?) {
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
index b59c897ad..db2f8e6e6 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/mobile/PlaylistsViewModel.kt
@@ -30,16 +30,21 @@ import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.gui.PlaylistFragment
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.providers.medialibrary.PlaylistsProvider
+import org.videolan.vlc.util.Settings
import org.videolan.vlc.viewmodels.MedialibraryViewModel
@ExperimentalCoroutinesApi
class PlaylistsViewModel(context: Context) : MedialibraryViewModel(context) {
+ val displayModeKey: String = "display_mode_playlists"
val provider = PlaylistsProvider(context, this)
+ var providerInCard = true
override val providers : Array<MedialibraryProvider<out MediaLibraryItem>> = arrayOf(provider)
+ private val settings = Settings.getInstance(context)
init {
watchPlaylists()
+ providerInCard = settings.getBoolean(displayModeKey, providerInCard)
}
class Factory(val context: Context): ViewModelProvider.NewInstanceFactory() {
More information about the Android
mailing list