mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 08:20:32 +05:30
fix: add pagination to subscriptions list
This commit is contained in:
parent
caef216c96
commit
b22e026ec0
@ -16,8 +16,9 @@ import com.github.libretube.ui.viewholders.SubscriptionChannelViewHolder
|
||||
class SubscriptionChannelAdapter(
|
||||
private val subscriptions: MutableList<Subscription>
|
||||
) : RecyclerView.Adapter<SubscriptionChannelViewHolder>() {
|
||||
private var visibleCount = 20
|
||||
|
||||
override fun getItemCount() = subscriptions.size
|
||||
override fun getItemCount() = minOf(visibleCount, subscriptions.size)
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
parent: ViewGroup,
|
||||
@ -28,6 +29,13 @@ class SubscriptionChannelAdapter(
|
||||
return SubscriptionChannelViewHolder(binding)
|
||||
}
|
||||
|
||||
fun updateItems() {
|
||||
val oldSize = visibleCount
|
||||
visibleCount += minOf(10, subscriptions.size - oldSize)
|
||||
if (visibleCount == oldSize) return
|
||||
notifyItemRangeInserted(oldSize, visibleCount)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: SubscriptionChannelViewHolder, position: Int) {
|
||||
val subscription = subscriptions[position]
|
||||
|
||||
|
@ -49,7 +49,8 @@ class SubscriptionsFragment : Fragment() {
|
||||
private var selectedFilterGroup = 0
|
||||
private var isCurrentTabSubChannels = false
|
||||
|
||||
var subscriptionsAdapter: VideosAdapter? = null
|
||||
var feedAdapter: VideosAdapter? = null
|
||||
private var channelsAdapter: SubscriptionChannelAdapter? = null
|
||||
private var selectedSortOrder = PreferenceHelper.getInt(PreferenceKeys.FEED_SORT_ORDER, 0)
|
||||
set(value) {
|
||||
PreferenceHelper.putInt(PreferenceKeys.FEED_SORT_ORDER, value)
|
||||
@ -155,7 +156,11 @@ class SubscriptionsFragment : Fragment() {
|
||||
viewModel.videoFeed.value != null // scroll view is at bottom
|
||||
) {
|
||||
binding.subRefresh.isRefreshing = true
|
||||
subscriptionsAdapter?.updateItems()
|
||||
if (isCurrentTabSubChannels) {
|
||||
channelsAdapter?.updateItems()
|
||||
} else {
|
||||
feedAdapter?.updateItems()
|
||||
}
|
||||
binding.subRefresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
@ -315,11 +320,11 @@ class SubscriptionsFragment : Fragment() {
|
||||
binding.subFeedContainer.isGone = notLoaded
|
||||
binding.emptyFeed.isVisible = notLoaded
|
||||
|
||||
subscriptionsAdapter = VideosAdapter(
|
||||
feedAdapter = VideosAdapter(
|
||||
sortedFeed.toMutableList(),
|
||||
showAllAtOnce = false
|
||||
)
|
||||
binding.subFeed.adapter = subscriptionsAdapter
|
||||
binding.subFeed.adapter = feedAdapter
|
||||
binding.toggleSubsText.text = getString(R.string.subscriptions)
|
||||
|
||||
PreferenceHelper.updateLastFeedWatchedTime()
|
||||
@ -345,7 +350,8 @@ class SubscriptionsFragment : Fragment() {
|
||||
binding.subChannels.adapter = LegacySubscriptionAdapter(subscriptions)
|
||||
} else {
|
||||
binding.subChannels.layoutManager = LinearLayoutManager(context)
|
||||
binding.subChannels.adapter = SubscriptionChannelAdapter(subscriptions.toMutableList())
|
||||
channelsAdapter = SubscriptionChannelAdapter(subscriptions.toMutableList())
|
||||
binding.subChannels.adapter = channelsAdapter
|
||||
}
|
||||
|
||||
binding.subRefresh.isRefreshing = false
|
||||
|
@ -132,7 +132,7 @@ class VideoOptionsBottomSheet(
|
||||
// get the current fragment
|
||||
val fragment = navHostFragment?.childFragmentManager?.fragments
|
||||
?.firstOrNull() as? SubscriptionsFragment
|
||||
fragment?.subscriptionsAdapter?.removeItemById(videoId)
|
||||
fragment?.feedAdapter?.removeItemById(videoId)
|
||||
}
|
||||
onVideoChanged()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user