From 3bfcb16f9a5929ef5ace7d34960cfe22a372bc90 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 00:32:21 +1100 Subject: [PATCH] Bug: SubscriptionViewModel.kt did not map values for FeedGroupCardVerticalItem in line 26 --- .../subscription/SubscriptionFragment.kt | 45 +++++-------------- 1 file changed, 12 insertions(+), 33 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 659187ffa..eafa9f62c 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 @@ -78,7 +78,6 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null - private var feedGroupsCarouselVertical: FeedGroupCarouselItem? = feedGroupsCarousel private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() @@ -125,7 +124,6 @@ class SubscriptionFragment : BaseStateFragment() { super.onPause() itemsListState = binding.itemsList.layoutManager?.onSaveInstanceState() feedGroupsListState = feedGroupsCarousel?.onSaveInstanceState() - feedGroupsListVerticalState = feedGroupsCarouselVertical?.onSaveInstanceState() } override fun onDestroy() { @@ -275,6 +273,7 @@ class SubscriptionFragment : BaseStateFragment() { } feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.HORIZONTAL) + feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), R.drawable.ic_list, @@ -282,6 +281,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::changeLayout, menuItemOnClickListener = ::openReorderDialog ) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) groupAdapter.clear() groupAdapter.add(this) @@ -302,15 +302,16 @@ class SubscriptionFragment : BaseStateFragment() { private fun changeLayout() { Section().apply { - val carouselAdapter = GroupAdapter>() + val carouselAdapter2 = GroupAdapter>() - carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter.add(feedGroupsSection) - carouselAdapter.add(FeedGroupAddItem()) // change this button later - carouselAdapter.setOnItemClickListener { item, _ -> + carouselAdapter2.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + carouselAdapter2.add(feedGroupsSection) + carouselAdapter2.add(FeedGroupAddItem()) + + carouselAdapter2.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) } - carouselAdapter.setOnItemLongClickListener { item, _ -> + carouselAdapter2.setOnItemLongClickListener { item, _ -> if (item is FeedGroupCardVerticalItem) { if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) { return@setOnItemLongClickListener false @@ -319,8 +320,8 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter2, RecyclerView.VERTICAL) - feedGroupsCarouselVertical = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), R.drawable.ic_apps, @@ -328,7 +329,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::setupInitialLayout, menuItemOnClickListener = ::openReorderDialog ) - add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarouselVertical))) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) groupAdapter.clear() groupAdapter.add(this) } @@ -343,17 +344,6 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) - - // TODO: remove this - groupAdapter.spanCount = if (shouldUseGridLayout(context)) getGridSpanCountChannels(context) else 1 - binding.itemsList.layoutManager = GridLayoutManager(requireContext(), groupAdapter.spanCount).apply { - spanSizeLookup = groupAdapter.spanSizeLookup - } - binding.itemsList.adapter = groupAdapter - - viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) - viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } - viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedVerticalGroups) } } override fun initViews(rootView: View, savedInstanceState: Bundle?) { @@ -366,6 +356,7 @@ class SubscriptionFragment : BaseStateFragment() { } binding.itemsList.adapter = groupAdapter + //TODO: change viewModel or create another one viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) viewModel.stateLiveData.observe(viewLifecycleOwner) { it?.let(this::handleResult) } viewModel.feedGroupsLiveData.observe(viewLifecycleOwner) { it?.let(this::handleFeedGroups) } @@ -495,18 +486,6 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } } - private fun handleFeedVerticalGroups(groups: List) { - feedGroupsSection.update(groups) - - if (feedGroupsListState != null) { - feedGroupsCarouselVertical?.onRestoreInstanceState(feedGroupsListVerticalState) - feedGroupsListVerticalState = null - } - - feedGroupsSortMenuItem.showMenuItem = groups.size > 1 - binding.itemsList.post { feedGroupsSortMenuItem.notifyChanged(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM) } - } - // ///////////////////////////////////////////////////////////////////////// // Contract // /////////////////////////////////////////////////////////////////////////