[Android] Display the dic number in the Android TV album media list

Nicolas Pomepuy git at videolan.org
Wed Feb 9 14:56:38 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jan 17 11:06:46 2022 +0100| [0b181930ab2f2c96ae8fbc4ee5e3598d5f1ff2a9] | committer: Nicolas Pomepuy

Display the dic number in the Android TV album media list

Fixes #2320

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

 .../videolan/television/ui/details/MediaListAdapter.kt   |  2 ++
 .../src/main/res/layout/activity_media_list_tv_item.xml  | 16 ++++++++++------
 .../src/org/videolan/vlc/util/ModelsHelper.kt            |  6 +++---
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/details/MediaListAdapter.kt b/application/television/src/main/java/org/videolan/television/ui/details/MediaListAdapter.kt
index 6ce0f773c..d47578fc6 100644
--- a/application/television/src/main/java/org/videolan/television/ui/details/MediaListAdapter.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/details/MediaListAdapter.kt
@@ -19,6 +19,7 @@ import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.gui.DiffUtilAdapter
 import org.videolan.vlc.gui.helpers.SelectorViewHolder
 import org.videolan.vlc.interfaces.ITVEventsHandler
+import org.videolan.vlc.util.ModelsHelper.getDiscNumberString
 
 @ExperimentalCoroutinesApi
 @ObsoleteCoroutinesApi
@@ -45,6 +46,7 @@ class MediaListAdapter(private val type: Int, private val listener: ITVEventsHan
         val item = getItem(position)
         holder.binding.item = item
         holder.binding.holder = holder
+        holder.binding.subtitle = if (item.getDiscNumberString() != null) "${item.artist} ยท ${item.getDiscNumberString()}" else item.artist
 
         val moveVisibility = if (type == MediaLibraryItem.TYPE_ALBUM) View.GONE else View.VISIBLE
         holder.binding.itemMoveDown.visibility = if (moveVisibility == View.VISIBLE && position == itemCount - 1) View.INVISIBLE else moveVisibility
diff --git a/application/television/src/main/res/layout/activity_media_list_tv_item.xml b/application/television/src/main/res/layout/activity_media_list_tv_item.xml
index 87b347d1e..fe8e2fc4b 100644
--- a/application/television/src/main/res/layout/activity_media_list_tv_item.xml
+++ b/application/television/src/main/res/layout/activity_media_list_tv_item.xml
@@ -19,6 +19,10 @@
                 name="item"
                 type="org.videolan.medialibrary.interfaces.media.MediaWrapper" />
 
+        <variable
+                name="subtitle"
+                type="String" />
+
         <variable
                 name="cover"
                 type="android.graphics.drawable.BitmapDrawable" />
@@ -76,8 +80,8 @@
                 android:text="@{item.title}"
                 android:textColor="@color/white"
                 android:textSize="16sp"
-                app:layout_constraintBottom_toTopOf="@+id/textView16"
-                app:layout_constraintEnd_toStartOf="@+id/textView17"
+                app:layout_constraintBottom_toTopOf="@+id/item_subtitle"
+                app:layout_constraintEnd_toStartOf="@+id/item_length"
                 app:layout_constraintHorizontal_bias="0.5"
                 app:layout_constraintStart_toEndOf="@+id/item_play"
                 app:layout_constraintTop_toTopOf="parent"
@@ -85,23 +89,23 @@
                 tools:text="Symphony No. 1" />
 
         <TextView
-                android:id="@+id/textView16"
+                android:id="@+id/item_subtitle"
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:layout_marginStart="8dp"
                 android:layout_marginEnd="16dp"
                 android:ellipsize="end"
                 android:maxLines="1"
-                android:text="@{item.artist}"
+                android:text="@{subtitle}"
                 app:layout_constraintBottom_toBottomOf="parent"
-                app:layout_constraintEnd_toStartOf="@+id/textView17"
+                app:layout_constraintEnd_toStartOf="@+id/item_length"
                 app:layout_constraintHorizontal_bias="0.5"
                 app:layout_constraintStart_toEndOf="@+id/item_play"
                 app:layout_constraintTop_toBottomOf="@+id/title"
                 tools:text="Ludwig van Beethoven" />
 
         <TextView
-                android:id="@+id/textView17"
+                android:id="@+id/item_length"
                 android:layout_width="0dp"
                 android:layout_height="wrap_content"
                 android:layout_marginEnd="8dp"
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index c49f09999..b3c9e00b7 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -103,7 +103,7 @@ object ModelsHelper {
         return if (title.isEmpty() || !Character.isLetter(title[0]) || isSpecialItem()) "#" else title.substring(0, 1).toUpperCase()
     }
 
-    private fun MediaLibraryItem.getDiscNumber(): String? = if (this is MediaWrapper && this.discNumber != 0) "Disc ${this.discNumber}" else null
+    fun MediaLibraryItem.getDiscNumberString(): String? = if (this is MediaWrapper && this.discNumber != 0) "Disc ${this.discNumber}" else null
 
     fun getHeader(context: Context?, sort: Int, item: MediaLibraryItem?, aboveItem: MediaLibraryItem?) = if (context !== null && item != null) when (sort) {
         SORT_DEFAULT,
@@ -116,10 +116,10 @@ object ModelsHelper {
             }
         }
         TrackId -> {
-            val disc = item.getDiscNumber()
+            val disc = item.getDiscNumberString()
             if (aboveItem == null) disc
             else {
-                val previousDisc = aboveItem.getDiscNumber()
+                val previousDisc = aboveItem.getDiscNumberString()
                 disc.takeIf { it != previousDisc }
             }
         }



More information about the Android mailing list