From 6eddaa0d38d4c49136f3e3572e9555364884a209 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 02:20:14 +1100 Subject: [PATCH] Added boolean to handle feed groups. May need a better solution for this --- .../subscription/SubscriptionFragment.kt | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 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 d282e58c1..667243c83 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 @@ -80,6 +80,7 @@ class SubscriptionFragment : BaseStateFragment() { private var feedGroupsCarousel: FeedGroupCarouselItem? = null private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() + private var listView: Boolean = false private val requestExportLauncher = registerForActivityResult(StartActivityForResult(), this::requestExportResult) @@ -124,6 +125,7 @@ class SubscriptionFragment : BaseStateFragment() { super.onPause() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() + feedGroupsListVerticalState = feedGroupsCarousel?.onSaveInstanceState() } override fun onDestroy() { @@ -252,6 +254,7 @@ class SubscriptionFragment : BaseStateFragment() { // //////////////////////////////////////////////////////////////////////// private fun setupInitialLayout() { + listView = false Section().apply { val carouselAdapter = GroupAdapter>() @@ -301,6 +304,7 @@ class SubscriptionFragment : BaseStateFragment() { } private fun changeLayout() { + listView = true Section().apply { val carouselAdapter2 = GroupAdapter>() @@ -476,27 +480,31 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroups(groups: List) { - feedGroupsSection.update(groups) + if (!listView) { + feedGroupsSection.update(groups) - if (feedGroupsListState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) - feedGroupsListState = null + if (feedGroupsListState != null) { + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) + feedGroupsListState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } private fun handleFeedGroupsVertical(groups: List) { - feedGroupsSection.update(groups) + if (listView) { + feedGroupsSection.update(groups) - if (feedGroupsListState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListState) - feedGroupsListVerticalState = null + if (feedGroupsListVerticalState != null) { + feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsListVerticalState = null + } + + feedGroupsSortMenuItem.showMenuItem = groups.size > 1 + binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } // /////////////////////////////////////////////////////////////////////////