mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #5655 from Bnyro/master
fix: bad performance when scrolling in subscriptions feed
This commit is contained in:
commit
9f16a27b74
@ -55,6 +55,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
private val channelGroupsModel: EditChannelGroupsModel by activityViewModels()
|
||||
private var selectedFilterGroup = 0
|
||||
private var isCurrentTabSubChannels = false
|
||||
private var isAppBarFullyExpanded = true
|
||||
|
||||
var feedAdapter: VideosAdapter? = null
|
||||
private var channelsAdapter: SubscriptionChannelAdapter? = null
|
||||
@ -89,6 +90,16 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
|
||||
setupSortAndFilter()
|
||||
|
||||
// Check if the AppBarLayout is fully expanded
|
||||
binding.subscriptionsAppBar.addOnOffsetChangedListener { _, verticalOffset ->
|
||||
isAppBarFullyExpanded = verticalOffset == 0
|
||||
}
|
||||
|
||||
// Determine if the child can scroll up
|
||||
binding.subRefresh.setOnChildScrollUpCallback { _, _ ->
|
||||
!isAppBarFullyExpanded
|
||||
}
|
||||
|
||||
binding.subRefresh.isEnabled = true
|
||||
binding.subProgress.isVisible = true
|
||||
|
||||
@ -119,21 +130,30 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
|
||||
if (isCurrentTabSubChannels) showSubscriptions() else showFeed()
|
||||
|
||||
binding.subChannelsContainer.isVisible = isCurrentTabSubChannels
|
||||
binding.subFeedContainer.isGone = isCurrentTabSubChannels
|
||||
binding.subChannels.isVisible = isCurrentTabSubChannels
|
||||
binding.subFeed.isGone = isCurrentTabSubChannels
|
||||
}
|
||||
|
||||
binding.scrollviewSub.viewTreeObserver.addOnScrollChangedListener {
|
||||
binding.subChannels.viewTreeObserver.addOnScrollChangedListener {
|
||||
val binding = _binding
|
||||
if (binding?.scrollviewSub?.canScrollVertically(1) == false &&
|
||||
viewModel.videoFeed.value != null // scroll view is at bottom
|
||||
if (binding?.subChannels?.canScrollVertically(1) == false &&
|
||||
viewModel.subscriptions.value != null && // scroll view is at bottom
|
||||
isCurrentTabSubChannels
|
||||
) {
|
||||
binding.subRefresh.isRefreshing = true
|
||||
if (isCurrentTabSubChannels) {
|
||||
channelsAdapter?.updateItems()
|
||||
} else {
|
||||
feedAdapter?.updateItems()
|
||||
}
|
||||
channelsAdapter?.updateItems()
|
||||
binding.subRefresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
binding.subFeed.viewTreeObserver.addOnScrollChangedListener {
|
||||
val binding = _binding
|
||||
if (binding?.subFeed?.canScrollVertically(1) == false &&
|
||||
viewModel.videoFeed.value != null && // scroll view is at bottom
|
||||
!isCurrentTabSubChannels
|
||||
) {
|
||||
binding.subRefresh.isRefreshing = true
|
||||
feedAdapter?.updateItems()
|
||||
binding.subRefresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
@ -141,7 +161,7 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
// add some extra margin to the subscribed channels while the mini player is visible
|
||||
// otherwise the last channel would be invisible
|
||||
playerModel.isMiniPlayerVisible.observe(viewLifecycleOwner) {
|
||||
binding.subChannelsContainer.updateLayoutParams<MarginLayoutParams> {
|
||||
binding.subChannels.updateLayoutParams<MarginLayoutParams> {
|
||||
bottomMargin = (if (it) 64f else 0f).dpToPx()
|
||||
}
|
||||
}
|
||||
@ -314,11 +334,11 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
}
|
||||
}
|
||||
|
||||
binding.subChannelsContainer.isGone = true
|
||||
binding.subChannels.isGone = true
|
||||
binding.subProgress.isGone = true
|
||||
|
||||
val notLoaded = viewModel.videoFeed.value.isNullOrEmpty()
|
||||
binding.subFeedContainer.isGone = notLoaded
|
||||
binding.subFeed.isGone = notLoaded
|
||||
binding.emptyFeed.isVisible = notLoaded
|
||||
|
||||
feedAdapter = VideosAdapter(
|
||||
@ -357,10 +377,10 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() {
|
||||
|
||||
binding.subRefresh.isRefreshing = false
|
||||
binding.subProgress.isGone = true
|
||||
binding.subFeedContainer.isGone = true
|
||||
binding.subFeed.isGone = true
|
||||
|
||||
val notLoaded = viewModel.subscriptions.value.isNullOrEmpty()
|
||||
binding.subChannelsContainer.isGone = notLoaded
|
||||
binding.subChannels.isGone = notLoaded
|
||||
binding.emptyFeed.isVisible = notLoaded
|
||||
|
||||
val subCount = subscriptions.size.toLong().formatShort()
|
||||
|
@ -20,7 +20,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="100dp"
|
||||
@ -44,132 +45,126 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/scrollview_sub"
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/sub_coordinator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/subscriptions_app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/filter_sort"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_filter_sort"
|
||||
android:contentDescription="@string/tooltip_filter"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:padding="6dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:alpha="0.7"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/toggle_subs"
|
||||
style="@style/PlayerActionsButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
app:layout_constraintEnd_toStartOf="@id/filter_sort"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:text="@string/subscriptions"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?colorPrimary"
|
||||
app:drawableEndCompat="@drawable/ic_arrow_up_down"
|
||||
app:drawableTint="?colorPrimary" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/sub_channels_container"
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/subscriptions_collapsing_tb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:visibility="gone">
|
||||
app:layout_scrollFlags="scroll"
|
||||
app:titleCollapseMode="scale">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_channels"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:nestedScrollingEnabled="false" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sub_feed_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="3dp"
|
||||
android:scrollbars="none">
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/edit_groups"
|
||||
android:layout_width="wrap_content"
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/toggle_subs"
|
||||
style="@style/PlayerActionsButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_edit"
|
||||
android:tooltipText="@string/tooltip_edit_groups" />
|
||||
android:layout_marginBottom="6dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/subscriptions"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?colorPrimary"
|
||||
app:drawableEndCompat="@drawable/ic_arrow_up_down"
|
||||
app:drawableTint="?colorPrimary" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/channel_groups"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
app:checkedChip="@id/chip_all"
|
||||
app:selectionRequired="true"
|
||||
app:singleLine="true"
|
||||
app:singleSelection="true">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_all"
|
||||
style="@style/ElevatedFilterChip"
|
||||
android:text="@string/all" />
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
<ImageView
|
||||
android:id="@+id/filter_sort"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginEnd="7dp"
|
||||
android:alpha="0.7"
|
||||
android:contentDescription="@string/tooltip_filter"
|
||||
android:padding="6dp"
|
||||
android:src="@drawable/ic_filter_sort" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="blocksDescendants">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_feed"
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/channel_groups_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="false" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="3dp"
|
||||
android:scrollbars="none">
|
||||
|
||||
</RelativeLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<ImageView
|
||||
android:id="@+id/edit_groups"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_edit"
|
||||
android:tooltipText="@string/tooltip_edit_groups" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/channel_groups"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
app:checkedChip="@id/chip_all"
|
||||
app:selectionRequired="true"
|
||||
app:singleLine="true"
|
||||
app:singleSelection="true">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
android:id="@+id/chip_all"
|
||||
style="@style/ElevatedFilterChip"
|
||||
android:text="@string/all" />
|
||||
|
||||
</com.google.android.material.chip.ChipGroup>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_feed"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/sub_channels"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
</com.github.libretube.ui.views.CustomSwipeToRefresh>
|
||||
</RelativeLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user