Skip to content
Snippets Groups Projects
Commit 21db50ef authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix search item description and cover for playlists

parent f200c755
No related branches found
No related tags found
1 merge request!1162Improve the SearchActivity UI
Pipeline #162370 passed with stage
in 4 minutes and 55 seconds
......@@ -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"
......
......@@ -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>) {
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment