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.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
@ -16,7 +17,6 @@ import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
import com.github.libretube.ui.viewholders.SubscriptionViewHolder import com.github.libretube.ui.viewholders.SubscriptionViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
import org.chromium.base.ContextUtils.getApplicationContext
class TrendingAdapter( class TrendingAdapter(
private val streamItems: List<com.github.libretube.api.obj.StreamItem>, private val streamItems: List<com.github.libretube.api.obj.StreamItem>,
@ -51,14 +51,20 @@ 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 trending = streamItems[position]
if (trending.title == null) {
holder.itemView.visibility = View.GONE
return
}
holder.binding.apply { holder.binding.apply {
textViewTitle.text = trending.title textViewTitle.text = trending.title
textViewChannel.text = textViewChannel.text =
trending.uploaderName + "" + trending.uploaderName + "" +
trending.views.formatShort() + " " + trending.views.formatShort() + " " +
getApplicationContext().resources.getString(R.string.views_placeholder) + root.context.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(trending.uploaded!!) "" + trending.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
thumbnailDuration.setFormattedDuration(trending.duration!!) trending.duration?.let { thumbnailDuration.setFormattedDuration(it) }
channelImage.setOnClickListener { channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, trending.uploaderUrl) NavigationHelper.navigateChannel(root.context, trending.uploaderUrl)
} }
@ -67,14 +73,19 @@ class TrendingAdapter(
root.setOnClickListener { root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url) NavigationHelper.navigateVideo(root.context, trending.url)
} }
val videoId = trending.url!!.toID() val videoId = trending.url?.toID()
val videoName = trending.title!! val videoName = trending.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, trending.duration!!) if (videoId != null) {
watchProgress.setWatchProgressLength(videoId, trending.duration ?: 0L)
}
} }
} }
} }