Fix displayed information in the short tabs of channels

This commit is contained in:
Bnyro 2023-04-10 13:21:11 +02:00
parent e7995b4bd9
commit a42f7ddb50

View File

@ -22,6 +22,7 @@ import com.github.libretube.ui.sheets.ChannelOptionsBottomSheet
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SearchViewHolder import com.github.libretube.ui.viewholders.SearchViewHolder
import com.github.libretube.util.TextUtils
class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback) { class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SearchViewHolder {
@ -49,7 +50,7 @@ class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback)
val playlistRowBinding = holder.playlistRowBinding val playlistRowBinding = holder.playlistRowBinding
if (videoRowBinding != null) { if (videoRowBinding != null) {
bindWatch(searchItem, videoRowBinding) bindVideo(searchItem, videoRowBinding)
} else if (channelRowBinding != null) { } else if (channelRowBinding != null) {
bindChannel(searchItem, channelRowBinding) bindChannel(searchItem, channelRowBinding)
} else if (playlistRowBinding != null) { } else if (playlistRowBinding != null) {
@ -66,21 +67,23 @@ class SearchAdapter : ListAdapter<ContentItem, SearchViewHolder>(SearchCallback)
} }
} }
private fun bindWatch(item: ContentItem, binding: VideoRowBinding) { private fun bindVideo(item: ContentItem, binding: VideoRowBinding) {
binding.apply { binding.apply {
ImageHelper.loadImage(item.thumbnail, thumbnail) ImageHelper.loadImage(item.thumbnail, thumbnail)
thumbnailDuration.setFormattedDuration(item.duration, item.isShort) thumbnailDuration.setFormattedDuration(item.duration, item.isShort)
ImageHelper.loadImage(item.uploaderAvatar, channelImage) ImageHelper.loadImage(item.uploaderAvatar, channelImage)
videoTitle.text = item.title videoTitle.text = item.title
val viewsString = if (item.views != -1L) item.views.formatShort() else "" // only display the additional info if not in a channel tab
val uploadDate = item.uploadedDate.orEmpty() if (item.isShort != true || item.uploaderAvatar != null) {
videoInfo.text = val viewsString = item.views.takeIf { it != -1L }?.formatShort().orEmpty()
if (viewsString.isNotEmpty() && uploadDate.isNotEmpty()) { val uploadDate = item.uploadedDate?.let { " ${TextUtils.SEPARATOR} $it" }.orEmpty()
"$viewsString$uploadDate" videoInfo.text = root.context.getString(
} else { R.string.normal_views,
viewsString + uploadDate viewsString,
} uploadDate
channelName.text = item.uploaderName )
channelName.text = item.uploaderName
}
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, item.url) NavigationHelper.navigateVideo(root.context, item.url)
} }