Merge pull request #1690 from Bnyro/master

Fix crash when invalid extracted stream info
This commit is contained in:
Bnyro 2022-10-29 16:44:49 +02:00 committed by GitHub
commit c8cf823b1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 20 deletions

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
@ -43,16 +44,24 @@ class ChannelAdapter(
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ChannelViewHolder, position: Int) {
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 {
videoTitle.text = video.title
videoInfo.text =
video.views.formatShort() + " " +
root.context.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(video.uploaded!!)
"" + video.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
thumbnailDuration.text =
DateUtils.formatElapsedTime(video.duration!!)
video.duration?.let { DateUtils.formatElapsedTime(it) }
ImageHelper.loadImage(video.thumbnail, thumbnail)
@ -65,15 +74,19 @@ class ChannelAdapter(
NavigationHelper.navigateVideo(root.context, video.url)
}
val videoId = video.url!!.toID()
val videoName = video.title!!
val videoId = video.url?.toID()
val videoName = video.title
root.setOnLongClickListener {
if (videoId == null || videoName == null) return@setOnLongClickListener true
VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
true
}
watchProgress.setWatchProgressLength(videoId, video.duration!!)
if (videoId != null) {
watchProgress.setWatchProgressLength(videoId, video.duration ?: 0L)
}
}
}
}

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>,
@ -50,31 +50,44 @@ class TrendingAdapter(
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: SubscriptionViewHolder, position: Int) {
val trending = streamItems[position]
val video = streamItems[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 {
textViewTitle.text = trending.title
textViewTitle.text = video.title
textViewChannel.text =
trending.uploaderName + "" +
trending.views.formatShort() + " " +
getApplicationContext().resources.getString(R.string.views_placeholder) +
"" + DateUtils.getRelativeTimeSpanString(trending.uploaded!!)
thumbnailDuration.setFormattedDuration(trending.duration!!)
video.uploaderName + "" +
video.views.formatShort() + " " +
root.context.getString(R.string.views_placeholder) +
"" + video.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
video.duration?.let { thumbnailDuration.setFormattedDuration(it) }
channelImage.setOnClickListener {
NavigationHelper.navigateChannel(root.context, trending.uploaderUrl)
NavigationHelper.navigateChannel(root.context, video.uploaderUrl)
}
ImageHelper.loadImage(trending.thumbnail, thumbnail)
ImageHelper.loadImage(trending.uploaderAvatar, channelImage)
ImageHelper.loadImage(video.thumbnail, thumbnail)
ImageHelper.loadImage(video.uploaderAvatar, channelImage)
root.setOnClickListener {
NavigationHelper.navigateVideo(root.context, trending.url)
NavigationHelper.navigateVideo(root.context, video.url)
}
val videoId = trending.url!!.toID()
val videoName = trending.title!!
val videoId = video.url?.toID()
val videoName = video.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, video.duration ?: 0L)
}
}
}
}