fix for the channel adapter

This commit is contained in:
Bnyro 2022-10-29 16:43:16 +02:00
parent b15bc7369b
commit 2efa4de778
2 changed files with 34 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package com.github.libretube.ui.adapters
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.text.format.DateUtils import android.text.format.DateUtils
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -43,16 +44,24 @@ class ChannelAdapter(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) { override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
val video = videoFeed[position] val video = videoFeed[position]
// hide the item if there was an extractor error
if (video.title == null) {
holder.itemView.visibility = View.GONE
holder.itemView.layoutParams = RecyclerView.LayoutParams(0, 0)
return
}
holder.binding.apply { holder.binding.apply {
videoTitle.text = video.title videoTitle.text = video.title
videoInfo.text = videoInfo.text =
video.views.formatShort() + " " + video.views.formatShort() + " " +
root.context.getString(R.string.views_placeholder) + root.context.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(video.uploaded!!) "" + video.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
thumbnailDuration.text = thumbnailDuration.text =
DateUtils.formatElapsedTime(video.duration!!) video.duration?.let { DateUtils.formatElapsedTime(it) }
ImageHelper.loadImage(video.thumbnail, thumbnail) ImageHelper.loadImage(video.thumbnail, thumbnail)
@ -65,15 +74,19 @@ class ChannelAdapter(
NavigationHelper.navigateVideo(root.context, video.url) NavigationHelper.navigateVideo(root.context, video.url)
} }
val videoId = video.url!!.toID() val videoId = video.url?.toID()
val videoName = video.title!! val videoName = video.title
root.setOnLongClickListener { root.setOnLongClickListener {
if (videoId == null || videoName == null) return@setOnLongClickListener true
VideoOptionsBottomSheet(videoId, videoName) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }
watchProgress.setWatchProgressLength(videoId, video.duration!!) if (videoId != null) {
watchProgress.setWatchProgressLength(videoId, video.duration ?: 0L)
}
} }
} }
} }

View File

@ -50,31 +50,33 @@ class TrendingAdapter(
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) { override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
val trending = streamItems[position] val video = streamItems[position]
if (trending.title == null) { // hide the item if there was an extractor error
if (video.title == null) {
holder.itemView.visibility = View.GONE holder.itemView.visibility = View.GONE
holder.itemView.layoutParams = RecyclerView.LayoutParams(0, 0)
return return
} }
holder.binding.apply { holder.binding.apply {
textViewTitle.text = trending.title textViewTitle.text = video.title
textViewChannel.text = textViewChannel.text =
trending.uploaderName + "" + video.uploaderName + "" +
trending.views.formatShort() + " " + video.views.formatShort() + " " +
root.context.getString(R.string.views_placeholder) + root.context.getString(R.string.views_placeholder) +
"" + trending.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) } "" + video.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
trending.duration?.let { thumbnailDuration.setFormattedDuration(it) } video.duration?.let { thumbnailDuration.setFormattedDuration(it) }
channelImage.setOnClickListener { channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, trending.uploaderUrl) NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
} }
ImageHelper.loadImage(trending.thumbnail, thumbnail) ImageHelper.loadImage(video.thumbnail, thumbnail)
ImageHelper.loadImage(trending.uploaderAvatar, channelImage) ImageHelper.loadImage(video.uploaderAvatar, channelImage)
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, video.url)
} }
val videoId = trending.url?.toID() val videoId = video.url?.toID()
val videoName = trending.title val videoName = video.title
root.setOnLongClickListener { root.setOnLongClickListener {
if (videoId == null || videoName == null) return@setOnLongClickListener true if (videoId == null || videoName == null) return@setOnLongClickListener true
@ -84,7 +86,7 @@ class TrendingAdapter(
true true
} }
if (videoId != null) { if (videoId != null) {
watchProgress.setWatchProgressLength(videoId, trending.duration ?: 0L) watchProgress.setWatchProgressLength(videoId, video.duration ?: 0L)
} }
} }
} }