From 83d16dc656d913fe4bfde4a9082aa601e310a7bf Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 27 Oct 2022 14:01:04 +0200 Subject: [PATCH] Fix flickering in channel groups list --- .../subscription/SubscriptionFragment.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index 770da3afe..151e14cab 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -413,16 +413,6 @@ class SubscriptionFragment : BaseStateFragment() { private fun handleFeedGroups(groups: List) { val listViewMode = viewModel.getListViewMode() - carouselAdapter.clear() - carouselAdapter.add(if (listViewMode) FeedGroupAddNewItem() else FeedGroupAddNewGridItem()) - carouselAdapter.add( - if (listViewMode) - FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS) - else - FeedGroupCardGridItem(-1, getString(R.string.all), FeedGroupIcon.RSS) - ) - carouselAdapter.addAll(groups) - if (feedGroupsCarouselState != null) { feedGroupsCarousel.onRestoreInstanceState(feedGroupsCarouselState) feedGroupsCarouselState = null @@ -434,6 +424,19 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.post { feedGroupsCarousel.notifyChanged(FeedGroupCarouselItem.PAYLOAD_UPDATE_LIST_VIEW_MODE) feedGroupsSortMenuItem.notifyChanged(GroupsHeader.PAYLOAD_UPDATE_ICONS) + + // update items here to prevent flickering + carouselAdapter.apply { + clear() + if (listViewMode) { + add(FeedGroupAddNewItem()) + add(FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + } else { + add(FeedGroupAddNewGridItem()) + add(FeedGroupCardGridItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + } + addAll(groups) + } } }