cleanup adapters

This commit is contained in:
Bnyro 2022-11-19 11:19:07 +01:00
parent 3105a46e2b
commit 01dee22802
15 changed files with 29 additions and 41 deletions

View File

@ -5,6 +5,7 @@ import android.text.format.DateUtils
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.api.obj.ChapterSegment
import com.github.libretube.databinding.ChapterColumnBinding import com.github.libretube.databinding.ChapterColumnBinding
import com.github.libretube.ui.viewholders.ChaptersViewHolder import com.github.libretube.ui.viewholders.ChaptersViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
@ -12,7 +13,7 @@ import com.github.libretube.util.ThemeHelper
import com.google.android.exoplayer2.ExoPlayer import com.google.android.exoplayer2.ExoPlayer
class ChaptersAdapter( class ChaptersAdapter(
private val chapters: List<com.github.libretube.api.obj.ChapterSegment>, private val chapters: List<ChapterSegment>,
private val exoPlayer: ExoPlayer private val exoPlayer: ExoPlayer
) : RecyclerView.Adapter<ChaptersViewHolder>() { ) : RecyclerView.Adapter<ChaptersViewHolder>() {
private var selectedPosition = 0 private var selectedPosition = 0

View File

@ -6,7 +6,6 @@ import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
import com.github.libretube.api.obj.PlaylistId import com.github.libretube.api.obj.PlaylistId
@ -14,6 +13,7 @@ import com.github.libretube.api.obj.StreamItem
import com.github.libretube.databinding.PlaylistRowBinding import com.github.libretube.databinding.PlaylistRowBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setFormattedDuration
import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.extensions.setWatchProgressLength
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
@ -30,8 +30,7 @@ import java.io.IOException
class PlaylistAdapter( class PlaylistAdapter(
private val videoFeed: MutableList<StreamItem>, private val videoFeed: MutableList<StreamItem>,
private val playlistId: String, private val playlistId: String,
private val isOwner: Boolean, private val isOwner: Boolean
private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<PlaylistViewHolder>() { ) : RecyclerView.Adapter<PlaylistViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -64,7 +63,10 @@ class PlaylistAdapter(
val videoName = streamItem.title!! val videoName = streamItem.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId, videoName) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show(
(root.context as BaseActivity).supportFragmentManager,
VideoOptionsBottomSheet::class.java.name
)
true true
} }

View File

@ -4,7 +4,6 @@ import android.app.Activity
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.RetrofitInstance
@ -12,6 +11,7 @@ import com.github.libretube.api.obj.PlaylistId
import com.github.libretube.api.obj.Playlists import com.github.libretube.api.obj.Playlists
import com.github.libretube.databinding.PlaylistsRowBinding import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.extensions.TAG import com.github.libretube.extensions.TAG
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
import com.github.libretube.ui.viewholders.PlaylistsViewHolder import com.github.libretube.ui.viewholders.PlaylistsViewHolder
import com.github.libretube.util.ImageHelper import com.github.libretube.util.ImageHelper
@ -25,8 +25,7 @@ import retrofit2.HttpException
import java.io.IOException import java.io.IOException
class PlaylistsAdapter( class PlaylistsAdapter(
private val playlists: MutableList<Playlists>, private val playlists: MutableList<Playlists>
private val childFragmentManager: FragmentManager
) : RecyclerView.Adapter<PlaylistsViewHolder>() { ) : RecyclerView.Adapter<PlaylistsViewHolder>() {
override fun getItemCount(): Int { override fun getItemCount(): Int {
@ -81,7 +80,7 @@ class PlaylistsAdapter(
isOwner = true isOwner = true
) )
playlistOptionsDialog.show( playlistOptionsDialog.show(
childFragmentManager, (root.context as BaseActivity).supportFragmentManager,
PlaylistOptionsBottomSheet::class.java.name PlaylistOptionsBottomSheet::class.java.name
) )
true true

View File

@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.obj.ContentItem import com.github.libretube.api.obj.ContentItem
@ -13,6 +12,7 @@ import com.github.libretube.databinding.PlaylistsRowBinding
import com.github.libretube.databinding.VideoRowBinding import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setFormattedDuration
import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.extensions.setWatchProgressLength
import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.extensions.setupSubscriptionButton
@ -24,8 +24,7 @@ import com.github.libretube.util.NavigationHelper
import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils
class SearchAdapter( class SearchAdapter(
private val searchItems: MutableList<ContentItem>, private val searchItems: MutableList<ContentItem>
private val childFragmentManager: FragmentManager
) : ) :
RecyclerView.Adapter<SearchViewHolder>() { RecyclerView.Adapter<SearchViewHolder>() {
@ -101,7 +100,7 @@ class SearchAdapter(
val videoName = item.title!! val videoName = item.title!!
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(videoId, videoName) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }
channelContainer.setOnClickListener { channelContainer.setOnClickListener {
@ -148,7 +147,7 @@ class SearchAdapter(
val playlistId = item.url!!.toID() val playlistId = item.url!!.toID()
val playlistName = item.name!! val playlistName = item.name!!
PlaylistOptionsBottomSheet(playlistId, playlistName, false) PlaylistOptionsBottomSheet(playlistId, playlistName, false)
.show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name) .show((root.context as BaseActivity).supportFragmentManager, PlaylistOptionsBottomSheet::class.java.name)
true true
} }
} }

View File

@ -6,7 +6,6 @@ import android.text.format.DateUtils
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -19,6 +18,7 @@ import com.github.libretube.databinding.VideoRowBinding
import com.github.libretube.extensions.formatShort import com.github.libretube.extensions.formatShort
import com.github.libretube.extensions.toDp import com.github.libretube.extensions.toDp
import com.github.libretube.extensions.toID import com.github.libretube.extensions.toID
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setFormattedDuration
import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.extensions.setWatchProgressLength
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
@ -30,7 +30,6 @@ import com.github.libretube.util.TextUtils
class VideosAdapter( class VideosAdapter(
private val streamItems: MutableList<StreamItem>, private val streamItems: MutableList<StreamItem>,
private val childFragmentManager: FragmentManager,
private val showAllAtOnce: Boolean = true, private val showAllAtOnce: Boolean = true,
private val forceMode: ForceMode = ForceMode.NONE private val forceMode: ForceMode = ForceMode.NONE
) : RecyclerView.Adapter<VideosViewHolder>() { ) : RecyclerView.Adapter<VideosViewHolder>() {
@ -113,7 +112,7 @@ class VideosAdapter(
if (videoId == null || videoName == null) return@setOnLongClickListener true if (videoId == null || videoName == null) return@setOnLongClickListener true
VideoOptionsBottomSheet(videoId, videoName) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }
@ -154,7 +153,7 @@ class VideosAdapter(
root.setOnLongClickListener { root.setOnLongClickListener {
if (videoId == null || videoName == null) return@setOnLongClickListener true if (videoId == null || videoName == null) return@setOnLongClickListener true
VideoOptionsBottomSheet(videoId, videoName) VideoOptionsBottomSheet(videoId, videoName)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -2,11 +2,11 @@ package com.github.libretube.ui.adapters
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.github.libretube.databinding.WatchHistoryRowBinding import com.github.libretube.databinding.WatchHistoryRowBinding
import com.github.libretube.db.DatabaseHolder import com.github.libretube.db.DatabaseHolder
import com.github.libretube.db.obj.WatchHistoryItem import com.github.libretube.db.obj.WatchHistoryItem
import com.github.libretube.ui.base.BaseActivity
import com.github.libretube.ui.extensions.setFormattedDuration import com.github.libretube.ui.extensions.setFormattedDuration
import com.github.libretube.ui.extensions.setWatchProgressLength import com.github.libretube.ui.extensions.setWatchProgressLength
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
@ -15,8 +15,7 @@ import com.github.libretube.util.ImageHelper
import com.github.libretube.util.NavigationHelper import com.github.libretube.util.NavigationHelper
class WatchHistoryAdapter( class WatchHistoryAdapter(
private val watchHistory: MutableList<WatchHistoryItem>, private val watchHistory: MutableList<WatchHistoryItem>
private val childFragmentManager: FragmentManager
) : ) :
RecyclerView.Adapter<WatchHistoryViewHolder>() { RecyclerView.Adapter<WatchHistoryViewHolder>() {
@ -56,7 +55,7 @@ class WatchHistoryAdapter(
} }
root.setOnLongClickListener { root.setOnLongClickListener {
VideoOptionsBottomSheet(video.videoId, video.title!!) VideoOptionsBottomSheet(video.videoId, video.title!!)
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name) .show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
true true
} }

View File

@ -183,7 +183,6 @@ class ChannelFragment : BaseFragment() {
// recyclerview of the videos by the channel // recyclerview of the videos by the channel
channelAdapter = VideosAdapter( channelAdapter = VideosAdapter(
response.relatedStreams.orEmpty().toMutableList(), response.relatedStreams.orEmpty().toMutableList(),
childFragmentManager,
forceMode = VideosAdapter.Companion.ForceMode.CHANNEL forceMode = VideosAdapter.Companion.ForceMode.CHANNEL
) )
binding.channelRecView.adapter = channelAdapter binding.channelRecView.adapter = channelAdapter
@ -229,8 +228,7 @@ class ChannelFragment : BaseFragment() {
} }
val adapter = SearchAdapter( val adapter = SearchAdapter(
response.content.toMutableList(), response.content.toMutableList()
childFragmentManager
) )
runOnUiThread { runOnUiThread {

View File

@ -80,7 +80,6 @@ class HomeFragment : BaseFragment() {
binding.featuredRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) binding.featuredRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.featuredRV.adapter = VideosAdapter( binding.featuredRV.adapter = VideosAdapter(
feed.toMutableList(), feed.toMutableList(),
childFragmentManager,
forceMode = VideosAdapter.Companion.ForceMode.HOME forceMode = VideosAdapter.Companion.ForceMode.HOME
) )
} }
@ -96,7 +95,6 @@ class HomeFragment : BaseFragment() {
binding.trendingRV.layoutManager = GridLayoutManager(context, 2) binding.trendingRV.layoutManager = GridLayoutManager(context, 2)
binding.trendingRV.adapter = VideosAdapter( binding.trendingRV.adapter = VideosAdapter(
trending.toMutableList(), trending.toMutableList(),
childFragmentManager,
forceMode = VideosAdapter.Companion.ForceMode.TRENDING forceMode = VideosAdapter.Companion.ForceMode.TRENDING
) )
} }
@ -109,7 +107,7 @@ class HomeFragment : BaseFragment() {
runOnUiThread { runOnUiThread {
makeVisible(binding.playlistsRV, binding.playlistsTV) makeVisible(binding.playlistsRV, binding.playlistsTV)
binding.playlistsRV.layoutManager = LinearLayoutManager(context) binding.playlistsRV.layoutManager = LinearLayoutManager(context)
binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList(), childFragmentManager) binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList())
binding.playlistsRV.adapter?.registerAdapterDataObserver(object : binding.playlistsRV.adapter?.registerAdapterDataObserver(object :
RecyclerView.AdapterDataObserver() { RecyclerView.AdapterDataObserver() {
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {

View File

@ -135,8 +135,7 @@ class LibraryFragment : BaseFragment() {
} }
val playlistsAdapter = PlaylistsAdapter( val playlistsAdapter = PlaylistsAdapter(
playlists.toMutableList(), playlists.toMutableList()
childFragmentManager
) )
// listen for playlists to become deleted // listen for playlists to become deleted

View File

@ -977,13 +977,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
if (PlayerHelper.alternativeVideoLayout) { if (PlayerHelper.alternativeVideoLayout) {
binding.alternativeTrendingRec.adapter = VideosAdapter( binding.alternativeTrendingRec.adapter = VideosAdapter(
relatedStreams.orEmpty().toMutableList(), relatedStreams.orEmpty().toMutableList(),
childFragmentManager,
forceMode = VideosAdapter.Companion.ForceMode.RELATED forceMode = VideosAdapter.Companion.ForceMode.RELATED
) )
} else { } else {
binding.relatedRecView.adapter = VideosAdapter( binding.relatedRecView.adapter = VideosAdapter(
relatedStreams.orEmpty().toMutableList(), relatedStreams.orEmpty().toMutableList()
childFragmentManager
) )
} }
} }

View File

@ -157,8 +157,7 @@ class PlaylistFragment : BaseFragment() {
playlistAdapter = PlaylistAdapter( playlistAdapter = PlaylistAdapter(
response.relatedStreams.orEmpty().toMutableList(), response.relatedStreams.orEmpty().toMutableList(),
playlistId!!, playlistId!!,
isOwner, isOwner
childFragmentManager
) )
// listen for playlist items to become deleted // listen for playlist items to become deleted

View File

@ -96,7 +96,7 @@ class SearchResultFragment : BaseFragment() {
runOnUiThread { runOnUiThread {
if (response.items?.isNotEmpty() == true) { if (response.items?.isNotEmpty() == true) {
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext()) binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
searchAdapter = SearchAdapter(response.items, childFragmentManager) searchAdapter = SearchAdapter(response.items)
binding.searchRecycler.adapter = searchAdapter binding.searchRecycler.adapter = searchAdapter
} else { } else {
binding.searchContainer.visibility = View.GONE binding.searchContainer.visibility = View.GONE

View File

@ -155,7 +155,6 @@ class SubscriptionsFragment : BaseFragment() {
binding.subProgress.visibility = View.GONE binding.subProgress.visibility = View.GONE
subscriptionAdapter = VideosAdapter( subscriptionAdapter = VideosAdapter(
sortedFeed.toMutableList(), sortedFeed.toMutableList(),
childFragmentManager,
showAllAtOnce = false showAllAtOnce = false
) )
binding.subFeed.adapter = subscriptionAdapter binding.subFeed.adapter = subscriptionAdapter

View File

@ -85,8 +85,7 @@ class TrendsFragment : BaseFragment() {
} }
binding.recview.adapter = VideosAdapter( binding.recview.adapter = VideosAdapter(
response.toMutableList(), response.toMutableList()
childFragmentManager
) )
binding.recview.layoutManager = VideosAdapter.getLayout(requireContext()) binding.recview.layoutManager = VideosAdapter.getLayout(requireContext())

View File

@ -41,8 +41,7 @@ class WatchHistoryFragment : BaseFragment() {
} }
val watchHistoryAdapter = WatchHistoryAdapter( val watchHistoryAdapter = WatchHistoryAdapter(
watchHistory.toMutableList(), watchHistory.toMutableList()
childFragmentManager
) )
val itemTouchCallback = object : ItemTouchHelper.SimpleCallback( val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(