mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 07:50:31 +05:30
Merge pull request #1690 from Bnyro/master
Fix crash when invalid extracted stream info
This commit is contained in:
commit
c8cf823b1f
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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>,
|
||||||
@ -50,31 +50,44 @@ 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]
|
||||||
|
|
||||||
|
// 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 {
|
||||||
textViewTitle.text = trending.title
|
textViewTitle.text = video.title
|
||||||
textViewChannel.text =
|
textViewChannel.text =
|
||||||
trending.uploaderName + " • " +
|
video.uploaderName + " • " +
|
||||||
trending.views.formatShort() + " " +
|
video.views.formatShort() + " " +
|
||||||
getApplicationContext().resources.getString(R.string.views_placeholder) +
|
root.context.getString(R.string.views_placeholder) +
|
||||||
" • " + DateUtils.getRelativeTimeSpanString(trending.uploaded!!)
|
" • " + video.uploaded?.let { DateUtils.getRelativeTimeSpanString(it) }
|
||||||
thumbnailDuration.setFormattedDuration(trending.duration!!)
|
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
|
||||||
|
|
||||||
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, video.duration ?: 0L)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user