[Android] Fix search item description and cover for playlists
Nicolas Pomepuy
git at videolan.org
Thu Nov 25 06:17:24 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Fri Nov 19 12:16:34 2021 +0100| [21db50efbdd6bf16e603abe7174dc72810e03ce5] | committer: Nicolas Pomepuy
Fix search item description and cover for playlists
> https://code.videolan.org/videolan/vlc-android/commit/21db50efbdd6bf16e603abe7174dc72810e03ce5
---
application/vlc-android/res/layout/search_item.xml | 7 +++++-
.../org/videolan/vlc/gui/SearchResultAdapter.kt | 28 ++++++++++++++++++----
.../org/videolan/vlc/gui/helpers/ImageLoader.kt | 6 ++---
3 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/application/vlc-android/res/layout/search_item.xml b/application/vlc-android/res/layout/search_item.xml
index 9ed03e730..c785627f3 100644
--- a/application/vlc-android/res/layout/search_item.xml
+++ b/application/vlc-android/res/layout/search_item.xml
@@ -15,6 +15,10 @@
name="item"
type="org.videolan.medialibrary.media.MediaLibraryItem" />
+ <variable
+ name="description"
+ type="String" />
+
<variable
name="holder"
type="org.videolan.vlc.gui.SearchResultAdapter.ViewHolder" />
@@ -54,6 +58,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
+ vlc:imageWidth="@{coverWidth}"
vlc:coverWidth="@{coverWidth}"
vlc:constraintRatio="@{isSquare}"
vlc:media="@{item}"
@@ -84,7 +89,7 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:maxLines="2"
- android:text="@{item.description}"
+ android:text="@{description}"
android:textColor="?attr/font_light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.kt
index 37e41775d..046a24e23 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/SearchResultAdapter.kt
@@ -3,12 +3,19 @@ package org.videolan.vlc.gui
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
+import org.videolan.medialibrary.Tools
+import org.videolan.medialibrary.interfaces.media.Genre
import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.medialibrary.interfaces.media.Playlist
import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.resources.AppContextProvider
import org.videolan.tools.dp
+import org.videolan.vlc.R
import org.videolan.vlc.databinding.SearchItemBinding
import org.videolan.vlc.gui.helpers.SelectorViewHolder
import org.videolan.vlc.gui.helpers.UiTools
+import org.videolan.vlc.util.generateResolutionClass
+import java.lang.StringBuilder
class SearchResultAdapter internal constructor(private val mLayoutInflater: LayoutInflater) : RecyclerView.Adapter<SearchResultAdapter.ViewHolder>() {
@@ -21,12 +28,25 @@ class SearchResultAdapter internal constructor(private val mLayoutInflater: Layo
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
- if (mDataList!![position].artworkMrl.isNullOrEmpty())
- holder.binding.cover = UiTools.getDefaultCover(holder.itemView.context, mDataList!![position])
- holder.binding.item = mDataList!![position]
- val isNotVideo = mDataList!![position] !is MediaWrapper || (mDataList!![position] as MediaWrapper).type != MediaWrapper.TYPE_VIDEO
+ val item = mDataList!![position]
+ if (item.artworkMrl.isNullOrEmpty())
+ holder.binding.cover = UiTools.getDefaultCover(holder.itemView.context, item)
+ holder.binding.item = item
+ val isNotVideo = item !is MediaWrapper || item.type != MediaWrapper.TYPE_VIDEO
holder.binding.isSquare = isNotVideo
holder.binding.coverWidth = if (isNotVideo) 48.dp else 100.dp
+ holder.binding.description = when {
+ (item as? MediaWrapper)?.type == MediaWrapper.TYPE_VIDEO -> {
+ if (item.length > 0) {
+ val resolution = generateResolutionClass(item.width, item.height)
+ if (resolution !== null) {
+ "${Tools.millisToString(item.length)} • $resolution"
+ } else Tools.millisToString(item.length)
+ } else null
+ }
+ item is Playlist || item is Genre -> holder.itemView.context.getString(R.string.track_number, item.tracksCount)
+ else -> item.description
+ }
}
fun add(newList: Array<MediaLibraryItem>) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index 2bbde64a1..42eb0caac 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -343,10 +343,10 @@ private suspend fun findInLibrary(item: MediaLibraryItem, isMedia: Boolean): Med
@MainThread
@BindingAdapter(value = ["constraintRatio", "coverWidth"], requireAll = false)
-fun constraintRatio(v: View, isSquare: Boolean, width: Int = -2) {
- if (width != -2) {
+fun constraintRatio(v: View, isSquare: Boolean, imageWidth: Int = -2) {
+ if (imageWidth != -2) {
val layoutParams: ViewGroup.LayoutParams = v.layoutParams
- layoutParams.width = width
+ layoutParams.width = imageWidth
v.layoutParams = layoutParams
}
val constraintLayout = v.parent as? ConstraintLayout
More information about the Android
mailing list