refactor: match the size of continue watching and related streams

This commit is contained in:
Bnyro 2023-12-06 14:21:04 +01:00
parent e465c313ac
commit c807d1d54d
4 changed files with 20 additions and 24 deletions

View File

@ -35,7 +35,7 @@ import com.github.libretube.util.TextUtils
class VideosAdapter( class VideosAdapter(
private val streamItems: MutableList<StreamItem>, private val streamItems: MutableList<StreamItem>,
private val showAllAtOnce: Boolean = true, private val showAllAtOnce: Boolean = true,
private val forceMode: ForceMode = ForceMode.NONE private val forceMode: LayoutMode = LayoutMode.RESPECT_PREF
) : RecyclerView.Adapter<VideosViewHolder>() { ) : RecyclerView.Adapter<VideosViewHolder>() {
private var visibleCount = minOf(10, streamItems.size) private var visibleCount = minOf(10, streamItems.size)
@ -82,14 +82,13 @@ class VideosAdapter(
) )
forceMode in listOf( forceMode in listOf(
ForceMode.TRENDING, LayoutMode.TRENDING_ROW,
ForceMode.RELATED, LayoutMode.RELATED_COLUMN
ForceMode.HOME
) -> VideosViewHolder( ) -> VideosViewHolder(
TrendingRowBinding.inflate(layoutInflater, parent, false) TrendingRowBinding.inflate(layoutInflater, parent, false)
) )
forceMode == ForceMode.CHANNEL -> VideosViewHolder( forceMode == LayoutMode.CHANNEL_ROW -> VideosViewHolder(
VideoRowBinding.inflate(layoutInflater, parent, false) VideoRowBinding.inflate(layoutInflater, parent, false)
) )
@ -126,11 +125,9 @@ class VideosAdapter(
// Trending layout // Trending layout
holder.trendingRowBinding?.apply { holder.trendingRowBinding?.apply {
// set a fixed width for better visuals // set a fixed width for better visuals
root.updateLayoutParams { if (forceMode == LayoutMode.RELATED_COLUMN) {
when (forceMode) { root.updateLayoutParams {
ForceMode.RELATED -> width = 210f.dpToPx() width = 250f.dpToPx()
ForceMode.HOME -> width = 250f.dpToPx()
else -> {}
} }
} }
@ -183,7 +180,7 @@ class VideosAdapter(
ImageHelper.loadImage(video.thumbnail, thumbnail) ImageHelper.loadImage(video.thumbnail, thumbnail)
if (forceMode != ForceMode.CHANNEL) { if (forceMode != LayoutMode.CHANNEL_ROW) {
ImageHelper.loadImage(video.uploaderAvatar, channelImage) ImageHelper.loadImage(video.uploaderAvatar, channelImage)
channelName.text = video.uploaderName channelName.text = video.uploaderName
@ -214,13 +211,12 @@ class VideosAdapter(
} }
companion object { companion object {
enum class ForceMode { enum class LayoutMode {
NONE, RESPECT_PREF,
TRENDING, TRENDING_ROW,
ROW, VIDEO_ROW,
CHANNEL, CHANNEL_ROW,
RELATED, RELATED_COLUMN
HOME
} }
fun getLayout(context: Context): LayoutManager { fun getLayout(context: Context): LayoutManager {

View File

@ -224,7 +224,7 @@ class ChannelFragment : Fragment() {
// recyclerview of the videos by the channel // recyclerview of the videos by the channel
channelAdapter = VideosAdapter( channelAdapter = VideosAdapter(
response.relatedStreams.toMutableList(), response.relatedStreams.toMutableList(),
forceMode = VideosAdapter.Companion.ForceMode.CHANNEL forceMode = VideosAdapter.Companion.LayoutMode.CHANNEL_ROW
) )
binding.channelRecView.adapter = channelAdapter binding.channelRecView.adapter = channelAdapter

View File

@ -127,7 +127,7 @@ class HomeFragment : Fragment() {
binding.trendingRV.layoutManager = GridLayoutManager(context, 2) binding.trendingRV.layoutManager = GridLayoutManager(context, 2)
binding.trendingRV.adapter = VideosAdapter( binding.trendingRV.adapter = VideosAdapter(
trending.toMutableList(), trending.toMutableList(),
forceMode = VideosAdapter.Companion.ForceMode.TRENDING forceMode = VideosAdapter.Companion.LayoutMode.TRENDING_ROW
) )
} }
@ -165,7 +165,7 @@ class HomeFragment : Fragment() {
) )
binding.featuredRV.adapter = VideosAdapter( binding.featuredRV.adapter = VideosAdapter(
filteredFeed.take(20).toMutableList(), filteredFeed.take(20).toMutableList(),
forceMode = VideosAdapter.Companion.ForceMode.HOME forceMode = VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
) )
} }
@ -233,7 +233,7 @@ class HomeFragment : Fragment() {
) )
binding.watchingRV.adapter = VideosAdapter( binding.watchingRV.adapter = VideosAdapter(
unwatchedVideos.toMutableList(), unwatchedVideos.toMutableList(),
forceMode = VideosAdapter.Companion.ForceMode.HOME forceMode = VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
) )
} }

View File

@ -1034,9 +1034,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.relatedRecView.adapter = VideosAdapter( binding.relatedRecView.adapter = VideosAdapter(
streams.relatedStreams.filter { !it.title.isNullOrBlank() }.toMutableList(), streams.relatedStreams.filter { !it.title.isNullOrBlank() }.toMutableList(),
forceMode = if (relatedLayoutManager.orientation == LinearLayoutManager.HORIZONTAL) { forceMode = if (relatedLayoutManager.orientation == LinearLayoutManager.HORIZONTAL) {
VideosAdapter.Companion.ForceMode.RELATED VideosAdapter.Companion.LayoutMode.RELATED_COLUMN
} else { } else {
VideosAdapter.Companion.ForceMode.TRENDING VideosAdapter.Companion.LayoutMode.TRENDING_ROW
} }
) )
} }