[Android] Add a playlist line to the TV main activity
Nicolas Pomepuy
git at videolan.org
Wed Jun 5 10:31:19 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue May 7 13:52:10 2019 +0200| [e67584ee0a17730a0da851dd96edaa36e536dda3] | committer: Geoffrey Métais
Add a playlist line to the TV main activity
> https://code.videolan.org/videolan/vlc-android/commit/e67584ee0a17730a0da851dd96edaa36e536dda3
---
.../src/org/videolan/vlc/gui/tv/CardPresenter.kt | 19 ++++++++++++++-----
.../src/org/videolan/vlc/gui/tv/MainTvFragment.kt | 14 +++++++++++++-
vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt | 1 +
vlc-android/src/org/videolan/vlc/util/Constants.kt | 1 +
.../src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt | 13 +++++++++++++
5 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.kt b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.kt
index f7609c9a7..f2027c554 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/CardPresenter.kt
@@ -44,6 +44,7 @@ import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.loadImage
+import org.videolan.vlc.gui.helpers.loadPlaylistImageWithWidth
import org.videolan.vlc.util.*
@ObsoleteCoroutinesApi
@@ -54,6 +55,8 @@ class CardPresenter(private val context: Activity) : Presenter() {
private var mIsSeenMediaMarkerVisible = true
private var sDefaultCardImage: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_default_cone)
+ private val imageDefaultWidth: Float by lazy { context.resources.getDimension(R.dimen.tv_grid_card_thumb_width) }
+
init {
mIsSeenMediaMarkerVisible = Settings.getInstance(context).getBoolean("media_seen", true)
@@ -81,11 +84,17 @@ class CardPresenter(private val context: Activity) : Presenter() {
return
}
}
- if (noArt) {
- cardView.mainImageView.scaleType = ImageView.ScaleType.FIT_CENTER
- cardView.mainImage = BitmapDrawable(cardView.resources, getDefaultImage(item))
- } else
- loadImage(cardView, item)
+ when {
+ item.itemType == MediaLibraryItem.TYPE_PLAYLIST -> {
+ cardView.mainImageView.scaleType = ImageView.ScaleType.FIT_CENTER
+ loadPlaylistImageWithWidth(cardView.mainImageView, item, imageDefaultWidth.toInt())
+ }
+ noArt -> {
+ cardView.mainImageView.scaleType = ImageView.ScaleType.FIT_CENTER
+ cardView.mainImage = BitmapDrawable(cardView.resources, getDefaultImage(item))
+ }
+ else -> loadImage(cardView, item)
+ }
}
private fun getDefaultImage(mediaLibraryItem: MediaLibraryItem): Bitmap? {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
index fd1c63547..23278e426 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
@@ -59,12 +59,14 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
private lateinit var videoAdapter: ArrayObjectAdapter
private lateinit var categoriesAdapter: ArrayObjectAdapter
private lateinit var historyAdapter: ArrayObjectAdapter
+ private lateinit var playlistAdapter: ArrayObjectAdapter
private lateinit var browserAdapter: ArrayObjectAdapter
private lateinit var otherAdapter: ArrayObjectAdapter
private lateinit var videoRow: ListRow
private lateinit var audioRow: ListRow
private lateinit var historyRow: ListRow
+ private lateinit var playlistRow: ListRow
private lateinit var browsersRow: ListRow
private lateinit var miscRow: ListRow
@@ -76,7 +78,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Set display parameters for the BrowseFragment
- headersState = BrowseSupportFragment.HEADERS_ENABLED
+ headersState = HEADERS_ENABLED
title = getString(R.string.app_name)
badgeDrawable = ContextCompat.getDrawable(requireContext(), R.drawable.icon)
@@ -107,6 +109,12 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
rowsAdapter.add(audioRow)
//History
+ // Playlists
+ playlistAdapter = ArrayObjectAdapter(CardPresenter(ctx))
+ val playlistHeader = HeaderItem(0, getString(R.string.playlists))
+ playlistRow = ListRow(playlistHeader, playlistAdapter)
+ rowsAdapter.add(playlistRow)
+
//Browser section
browserAdapter = ArrayObjectAdapter(CardPresenter(ctx))
val browserHeader = HeaderItem(HEADER_NETWORK, getString(R.string.browsing))
@@ -159,6 +167,10 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
rowsAdapter.setItems(adapters, TvUtil.listDiffCallback)
}
})
+
+ model.playlist.observe(this, Observer {
+ playlistAdapter.setItems(it, diffCallback)
+ })
}
override fun onStart() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
index 4ab759612..510fcf035 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
@@ -358,6 +358,7 @@ object TvUtil {
HEADER_NETWORK -> R.drawable.ic_menu_network_big
HEADER_SERVER -> R.drawable.ic_menu_network_add_big
HEADER_STREAM -> R.drawable.ic_menu_stream_big
+ HEADER_PLAYLISTS -> R.drawable.ic_menu_playlist_big
ID_SETTINGS -> R.drawable.ic_menu_preferences_big
ID_ABOUT_TV, ID_LICENCE -> R.drawable.ic_default_cone
CATEGORY_ARTISTS -> R.drawable.ic_artist_big
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index fe93c6d92..2cb77c786 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -106,6 +106,7 @@ const val HEADER_DIRECTORIES = 4L
const val HEADER_MISC = 5L
const val HEADER_STREAM = 6L
const val HEADER_SERVER = 7L
+const val HEADER_PLAYLISTS = 8L
const val ID_SETTINGS = 10L
const val ID_ABOUT_TV = 11L
const val ID_LICENCE = 12L
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
index fcf6f8273..c322bf56e 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/tv/MainTvModel.kt
@@ -73,6 +73,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
val audioCategories : LiveData<List<MediaLibraryItem>> = MutableLiveData()
val browsers : LiveData<List<MediaLibraryItem>> = MutableLiveData()
val history : LiveData<List<MediaWrapper>> = MutableLiveData()
+ val playlist: LiveData<List<MediaLibraryItem>> = MutableLiveData()
private val nowPlayingDelegate = NowPlayingDelegate(this)
@@ -108,6 +109,7 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
updateVideos()
historyActor.offer(Unit)
updateActor.offer(Unit)
+ updatePlaylists()
}
private suspend fun setHistory() {
@@ -134,6 +136,17 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
}
}
+ private fun updatePlaylists() = launch {
+ context.getFromMl {
+ getPagedPlaylists(Medialibrary.SORT_INSERTIONDATE, true, NUM_ITEMS_PREVIEW, 0)
+ }.let {
+ (playlist as MutableLiveData).value = mutableListOf<MediaLibraryItem>().apply {
+ add(DummyItem(HEADER_PLAYLISTS, context.getString(R.string.playlists), ""))
+ addAll(it)
+ }
+ }
+ }
+
fun updateAudioCategories() {
val list = mutableListOf<MediaLibraryItem>(
DummyItem(CATEGORY_ARTISTS, context.getString(R.string.artists), ""),
More information about the Android
mailing list