Fix empty trending items

This commit is contained in:
Bnyro 2022-10-29 16:37:59 +02:00
parent c8d8fdbe41
commit b15bc7369b

View File

@ -3,6 +3,7 @@ package com.github.libretube.ui.adapters
import android.annotation.SuppressLint
import android.text.format.DateUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView
@ -16,7 +17,6 @@ import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SubscriptionViewHolder
import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper
import org.chromium.base.ContextUtils.getApplicationContext
class TrendingAdapter(
private val streamItems: List<com.github.libretube.api.obj.StreamItem>,
@ -51,14 +51,20 @@ class TrendingAdapter(
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
val trending = streamItems[position]
if (trending.title == null) {
holder.itemView.visibility = View.GONE
return
}
holder.binding.apply {
textViewTitle.text = trending.title
textViewChannel.text =
trending.uploaderName + "" +
trending.views.formatShort() + " " +
getApplicationContext().resources.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(trending.uploaded!!)
thumbnailDuration.setFormattedDuration(trending.duration!!)
root.context.getString(R.string.views_placeholder) +
"" + trending.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
trending.duration?.let { thumbnailDuration.setFormattedDuration(it) }
channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, trending.uploaderUrl)
}
@ -67,14 +73,19 @@ class TrendingAdapter(
root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url)
}
val videoId = trending.url!!.toID()
val videoName = trending.title!!
val videoId = trending.url?.toID()
val videoName = trending.title
root.setOnLongClickListener {
if (videoId == null || videoName == null) return@setOnLongClickListener true
VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true
}
watchProgress.setWatchProgressLength(videoId, trending.duration!!)
if (videoId != null) {
watchProgress.setWatchProgressLength(videoId, trending.duration ?: 0L)
}
}
}
}