mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
cleanup adapters
This commit is contained in:
parent
3105a46e2b
commit
01dee22802
@ -5,6 +5,7 @@ import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.obj.ChapterSegment
|
||||
import com.github.libretube.databinding.ChapterColumnBinding
|
||||
import com.github.libretube.ui.viewholders.ChaptersViewHolder
|
||||
import com.github.libretube.util.ImageHelper
|
||||
@ -12,7 +13,7 @@ import com.github.libretube.util.ThemeHelper
|
||||
import com.google.android.exoplayer2.ExoPlayer
|
||||
|
||||
class ChaptersAdapter(
|
||||
private val chapters: List<com.github.libretube.api.obj.ChapterSegment>,
|
||||
private val chapters: List<ChapterSegment>,
|
||||
private val exoPlayer: ExoPlayer
|
||||
) : RecyclerView.Adapter<ChaptersViewHolder>() {
|
||||
private var selectedPosition = 0
|
||||
|
@ -6,7 +6,6 @@ import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
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.extensions.TAG
|
||||
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.setWatchProgressLength
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||
@ -30,8 +30,7 @@ import java.io.IOException
|
||||
class PlaylistAdapter(
|
||||
private val videoFeed: MutableList<StreamItem>,
|
||||
private val playlistId: String,
|
||||
private val isOwner: Boolean,
|
||||
private val childFragmentManager: FragmentManager
|
||||
private val isOwner: Boolean
|
||||
) : RecyclerView.Adapter<PlaylistViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
@ -64,7 +63,10 @@ class PlaylistAdapter(
|
||||
val videoName = streamItem.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
.show(
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
VideoOptionsBottomSheet::class.java.name
|
||||
)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import android.app.Activity
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
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.databinding.PlaylistsRowBinding
|
||||
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.viewholders.PlaylistsViewHolder
|
||||
import com.github.libretube.util.ImageHelper
|
||||
@ -25,8 +25,7 @@ import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
|
||||
class PlaylistsAdapter(
|
||||
private val playlists: MutableList<Playlists>,
|
||||
private val childFragmentManager: FragmentManager
|
||||
private val playlists: MutableList<Playlists>
|
||||
) : RecyclerView.Adapter<PlaylistsViewHolder>() {
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
@ -81,7 +80,7 @@ class PlaylistsAdapter(
|
||||
isOwner = true
|
||||
)
|
||||
playlistOptionsDialog.show(
|
||||
childFragmentManager,
|
||||
(root.context as BaseActivity).supportFragmentManager,
|
||||
PlaylistOptionsBottomSheet::class.java.name
|
||||
)
|
||||
true
|
||||
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.R
|
||||
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.extensions.formatShort
|
||||
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.setWatchProgressLength
|
||||
import com.github.libretube.ui.extensions.setupSubscriptionButton
|
||||
@ -24,8 +24,7 @@ import com.github.libretube.util.NavigationHelper
|
||||
import com.github.libretube.util.TextUtils
|
||||
|
||||
class SearchAdapter(
|
||||
private val searchItems: MutableList<ContentItem>,
|
||||
private val childFragmentManager: FragmentManager
|
||||
private val searchItems: MutableList<ContentItem>
|
||||
) :
|
||||
RecyclerView.Adapter<SearchViewHolder>() {
|
||||
|
||||
@ -101,7 +100,7 @@ class SearchAdapter(
|
||||
val videoName = item.title!!
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
channelContainer.setOnClickListener {
|
||||
@ -148,7 +147,7 @@ class SearchAdapter(
|
||||
val playlistId = item.url!!.toID()
|
||||
val playlistName = item.name!!
|
||||
PlaylistOptionsBottomSheet(playlistId, playlistName, false)
|
||||
.show(childFragmentManager, PlaylistOptionsBottomSheet::class.java.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager, PlaylistOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ 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.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
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.toDp
|
||||
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.setWatchProgressLength
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||
@ -30,7 +30,6 @@ import com.github.libretube.util.TextUtils
|
||||
|
||||
class VideosAdapter(
|
||||
private val streamItems: MutableList<StreamItem>,
|
||||
private val childFragmentManager: FragmentManager,
|
||||
private val showAllAtOnce: Boolean = true,
|
||||
private val forceMode: ForceMode = ForceMode.NONE
|
||||
) : RecyclerView.Adapter<VideosViewHolder>() {
|
||||
@ -113,7 +112,7 @@ class VideosAdapter(
|
||||
if (videoId == null || videoName == null) return@setOnLongClickListener true
|
||||
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
|
||||
true
|
||||
}
|
||||
@ -154,7 +153,7 @@ class VideosAdapter(
|
||||
root.setOnLongClickListener {
|
||||
if (videoId == null || videoName == null) return@setOnLongClickListener true
|
||||
VideoOptionsBottomSheet(videoId, videoName)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -2,11 +2,11 @@ package com.github.libretube.ui.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.github.libretube.databinding.WatchHistoryRowBinding
|
||||
import com.github.libretube.db.DatabaseHolder
|
||||
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.setWatchProgressLength
|
||||
import com.github.libretube.ui.sheets.VideoOptionsBottomSheet
|
||||
@ -15,8 +15,7 @@ import com.github.libretube.util.ImageHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
|
||||
class WatchHistoryAdapter(
|
||||
private val watchHistory: MutableList<WatchHistoryItem>,
|
||||
private val childFragmentManager: FragmentManager
|
||||
private val watchHistory: MutableList<WatchHistoryItem>
|
||||
) :
|
||||
RecyclerView.Adapter<WatchHistoryViewHolder>() {
|
||||
|
||||
@ -56,7 +55,7 @@ class WatchHistoryAdapter(
|
||||
}
|
||||
root.setOnLongClickListener {
|
||||
VideoOptionsBottomSheet(video.videoId, video.title!!)
|
||||
.show(childFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
.show((root.context as BaseActivity).supportFragmentManager, VideoOptionsBottomSheet::class.java.name)
|
||||
true
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,6 @@ class ChannelFragment : BaseFragment() {
|
||||
// recyclerview of the videos by the channel
|
||||
channelAdapter = VideosAdapter(
|
||||
response.relatedStreams.orEmpty().toMutableList(),
|
||||
childFragmentManager,
|
||||
forceMode = VideosAdapter.Companion.ForceMode.CHANNEL
|
||||
)
|
||||
binding.channelRecView.adapter = channelAdapter
|
||||
@ -229,8 +228,7 @@ class ChannelFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
val adapter = SearchAdapter(
|
||||
response.content.toMutableList(),
|
||||
childFragmentManager
|
||||
response.content.toMutableList()
|
||||
)
|
||||
|
||||
runOnUiThread {
|
||||
|
@ -80,7 +80,6 @@ class HomeFragment : BaseFragment() {
|
||||
binding.featuredRV.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
binding.featuredRV.adapter = VideosAdapter(
|
||||
feed.toMutableList(),
|
||||
childFragmentManager,
|
||||
forceMode = VideosAdapter.Companion.ForceMode.HOME
|
||||
)
|
||||
}
|
||||
@ -96,7 +95,6 @@ class HomeFragment : BaseFragment() {
|
||||
binding.trendingRV.layoutManager = GridLayoutManager(context, 2)
|
||||
binding.trendingRV.adapter = VideosAdapter(
|
||||
trending.toMutableList(),
|
||||
childFragmentManager,
|
||||
forceMode = VideosAdapter.Companion.ForceMode.TRENDING
|
||||
)
|
||||
}
|
||||
@ -109,7 +107,7 @@ class HomeFragment : BaseFragment() {
|
||||
runOnUiThread {
|
||||
makeVisible(binding.playlistsRV, binding.playlistsTV)
|
||||
binding.playlistsRV.layoutManager = LinearLayoutManager(context)
|
||||
binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList(), childFragmentManager)
|
||||
binding.playlistsRV.adapter = PlaylistsAdapter(playlists.toMutableList())
|
||||
binding.playlistsRV.adapter?.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
|
@ -135,8 +135,7 @@ class LibraryFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
val playlistsAdapter = PlaylistsAdapter(
|
||||
playlists.toMutableList(),
|
||||
childFragmentManager
|
||||
playlists.toMutableList()
|
||||
)
|
||||
|
||||
// listen for playlists to become deleted
|
||||
|
@ -977,13 +977,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
|
||||
if (PlayerHelper.alternativeVideoLayout) {
|
||||
binding.alternativeTrendingRec.adapter = VideosAdapter(
|
||||
relatedStreams.orEmpty().toMutableList(),
|
||||
childFragmentManager,
|
||||
forceMode = VideosAdapter.Companion.ForceMode.RELATED
|
||||
)
|
||||
} else {
|
||||
binding.relatedRecView.adapter = VideosAdapter(
|
||||
relatedStreams.orEmpty().toMutableList(),
|
||||
childFragmentManager
|
||||
relatedStreams.orEmpty().toMutableList()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -157,8 +157,7 @@ class PlaylistFragment : BaseFragment() {
|
||||
playlistAdapter = PlaylistAdapter(
|
||||
response.relatedStreams.orEmpty().toMutableList(),
|
||||
playlistId!!,
|
||||
isOwner,
|
||||
childFragmentManager
|
||||
isOwner
|
||||
)
|
||||
|
||||
// listen for playlist items to become deleted
|
||||
|
@ -96,7 +96,7 @@ class SearchResultFragment : BaseFragment() {
|
||||
runOnUiThread {
|
||||
if (response.items?.isNotEmpty() == true) {
|
||||
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
|
||||
searchAdapter = SearchAdapter(response.items, childFragmentManager)
|
||||
searchAdapter = SearchAdapter(response.items)
|
||||
binding.searchRecycler.adapter = searchAdapter
|
||||
} else {
|
||||
binding.searchContainer.visibility = View.GONE
|
||||
|
@ -155,7 +155,6 @@ class SubscriptionsFragment : BaseFragment() {
|
||||
binding.subProgress.visibility = View.GONE
|
||||
subscriptionAdapter = VideosAdapter(
|
||||
sortedFeed.toMutableList(),
|
||||
childFragmentManager,
|
||||
showAllAtOnce = false
|
||||
)
|
||||
binding.subFeed.adapter = subscriptionAdapter
|
||||
|
@ -85,8 +85,7 @@ class TrendsFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
binding.recview.adapter = VideosAdapter(
|
||||
response.toMutableList(),
|
||||
childFragmentManager
|
||||
response.toMutableList()
|
||||
)
|
||||
|
||||
binding.recview.layoutManager = VideosAdapter.getLayout(requireContext())
|
||||
|
@ -41,8 +41,7 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
}
|
||||
|
||||
val watchHistoryAdapter = WatchHistoryAdapter(
|
||||
watchHistory.toMutableList(),
|
||||
childFragmentManager
|
||||
watchHistory.toMutableList()
|
||||
)
|
||||
|
||||
val itemTouchCallback = object : ItemTouchHelper.SimpleCallback(
|
||||
|
Loading…
Reference in New Issue
Block a user