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 84e63554f..89d394a4a 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 @@ -45,7 +45,7 @@ import org.schabi.newpipe.local.subscription.dialog.FeedGroupReorderDialog import org.schabi.newpipe.local.subscription.item.ChannelItem import org.schabi.newpipe.local.subscription.item.EmptyPlaceholderItem import org.schabi.newpipe.local.subscription.item.FeedGroupAddItem -import org.schabi.newpipe.local.subscription.item.FeedGroupAddItemVertical +import org.schabi.newpipe.local.subscription.item.FeedGroupAddVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem @@ -78,10 +78,12 @@ class SubscriptionFragment : BaseStateFragment() { private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() + private val feedGroupsVerticalSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null + private var feedGroupsVerticalCarousel: FeedGroupCarouselItem? = null private lateinit var feedGroupsSortMenuItem: HeaderWithMenuItem private val subscriptionsSection = Section() - private var listView: Boolean = false + private var defaultListView: Boolean = true private val requestExportLauncher = registerForActivityResult(StartActivityForResult(), this::requestExportResult) @@ -255,7 +257,7 @@ class SubscriptionFragment : BaseStateFragment() { // //////////////////////////////////////////////////////////////////////// private fun setupInitialLayout() { - listView = false + defaultListView = true Section().apply { val carouselAdapter = GroupAdapter>() @@ -302,16 +304,17 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) + view?.let { initViews(it, savedInstanceState = Bundle()) } } private fun changeLayout() { - listView = true + defaultListView = false Section().apply { val carouselAdapter = GroupAdapter>() carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter.add(feedGroupsSection) - carouselAdapter.add(FeedGroupAddItemVertical()) + carouselAdapter.add(feedGroupsVerticalSection) + carouselAdapter.add(FeedGroupAddVerticalItem()) carouselAdapter.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) @@ -325,7 +328,7 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } - feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) + feedGroupsVerticalCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), @@ -334,7 +337,7 @@ class SubscriptionFragment : BaseStateFragment() { listViewOnClickListener = ::setupInitialLayout, menuItemOnClickListener = ::openReorderDialog ) - add(Section(feedGroupsSortMenuItem, listOf(feedGroupsCarousel))) + add(Section(feedGroupsSortMenuItem, listOf(feedGroupsVerticalCarousel))) groupAdapter.clear() groupAdapter.add(this) } @@ -349,6 +352,7 @@ class SubscriptionFragment : BaseStateFragment() { listOf(subscriptionsSection) ) ) + view?.let { initViews(it, savedInstanceState = Bundle()) } } override fun initViews(rootView: View, savedInstanceState: Bundle?) { @@ -427,7 +431,7 @@ class SubscriptionFragment : BaseStateFragment() { override fun selected(selectedItem: Item<*>?) { when (selectedItem) { is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name) - is FeedGroupAddItemVertical -> FeedGroupDialog.newInstance().show(fm, null) + is FeedGroupAddVerticalItem -> FeedGroupDialog.newInstance().show(fm, null) } } @@ -480,7 +484,7 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroups(groups: List) { - if (!listView) { + if (defaultListView) { feedGroupsSection.update(groups) if (feedGroupsListState != null) { @@ -494,11 +498,11 @@ class SubscriptionFragment : BaseStateFragment() { } private fun handleFeedGroupsVertical(groups: List) { - if (listView) { - feedGroupsSection.update(groups) + if (!defaultListView) { + feedGroupsVerticalSection.update(groups) if (feedGroupsListVerticalState != null) { - feedGroupsCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) + feedGroupsVerticalCarousel?.onRestoreInstanceState(feedGroupsListVerticalState) feedGroupsListVerticalState = null } diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt similarity index 89% rename from app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt rename to app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt index deb126219..eae8bd5f2 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddVerticalItem.kt @@ -5,7 +5,7 @@ import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R import org.schabi.newpipe.databinding.FeedGroupAddNewItemVerticalBinding -class FeedGroupAddItemVertical : BindableItem() { +class FeedGroupAddVerticalItem : BindableItem() { override fun getLayout(): Int = R.layout.feed_group_add_new_item_vertical override fun bind(viewBinding: FeedGroupAddNewItemVerticalBinding, position: Int) {} override fun initializeViewBinding(view: View) = FeedGroupAddNewItemVerticalBinding.bind(view)