From 082d7a3f187c46ab5a69412701934e2b2247f782 Mon Sep 17 00:00:00 2001 From: Samuel Wu Date: Tue, 25 Oct 2022 02:38:31 +1100 Subject: [PATCH] Added working binding for a "new" button that works in the list layout. --- .../subscription/SubscriptionFragment.kt | 18 ++++---- .../item/FeedGroupAddItemVertical.kt | 12 +++++ .../feed_group_add_new_item_vertical.xml | 45 +++++++++++++++++++ 3 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt create mode 100644 app/src/main/res/layout/feed_group_add_new_item_vertical.xml 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 667243c83..84e63554f 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,6 +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.FeedGroupCardItem import org.schabi.newpipe.local.subscription.item.FeedGroupCardVerticalItem import org.schabi.newpipe.local.subscription.item.FeedGroupCarouselItem @@ -306,16 +307,16 @@ class SubscriptionFragment : BaseStateFragment() { private fun changeLayout() { listView = true Section().apply { - val carouselAdapter2 = GroupAdapter>() + val carouselAdapter = GroupAdapter>() - carouselAdapter2.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) - carouselAdapter2.add(feedGroupsSection) - carouselAdapter2.add(FeedGroupAddItem()) + carouselAdapter.add(FeedGroupCardVerticalItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) + carouselAdapter.add(feedGroupsSection) + carouselAdapter.add(FeedGroupAddItemVertical()) - carouselAdapter2.setOnItemClickListener { item, _ -> + carouselAdapter.setOnItemClickListener { item, _ -> listenerFeedVerticalGroups.selected(item) } - carouselAdapter2.setOnItemLongClickListener { item, _ -> + carouselAdapter.setOnItemLongClickListener { item, _ -> if (item is FeedGroupCardVerticalItem) { if (item.groupId == FeedGroupEntity.GROUP_ALL_ID) { return@setOnItemLongClickListener false @@ -324,7 +325,7 @@ class SubscriptionFragment : BaseStateFragment() { listenerFeedVerticalGroups.held(item) return@setOnItemLongClickListener true } - feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter2, RecyclerView.VERTICAL) + feedGroupsCarousel = FeedGroupCarouselItem(requireContext(), carouselAdapter, RecyclerView.VERTICAL) feedGroupsSortMenuItem = HeaderWithMenuItem( getString(R.string.feed_groups_header_title), @@ -360,7 +361,6 @@ 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) } @@ -427,7 +427,7 @@ class SubscriptionFragment : BaseStateFragment() { override fun selected(selectedItem: Item<*>?) { when (selectedItem) { is FeedGroupCardVerticalItem -> NavigationHelper.openFeedFragment(fm, selectedItem.groupId, selectedItem.name) - is FeedGroupAddItem -> FeedGroupDialog.newInstance().show(fm, null) + is FeedGroupAddItemVertical -> FeedGroupDialog.newInstance().show(fm, 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/FeedGroupAddItemVertical.kt new file mode 100644 index 000000000..deb126219 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupAddItemVertical.kt @@ -0,0 +1,12 @@ +package org.schabi.newpipe.local.subscription.item + +import android.view.View +import com.xwray.groupie.viewbinding.BindableItem +import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedGroupAddNewItemVerticalBinding + +class FeedGroupAddItemVertical : 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) +} diff --git a/app/src/main/res/layout/feed_group_add_new_item_vertical.xml b/app/src/main/res/layout/feed_group_add_new_item_vertical.xml new file mode 100644 index 000000000..43427f291 --- /dev/null +++ b/app/src/main/res/layout/feed_group_add_new_item_vertical.xml @@ -0,0 +1,45 @@ + + + + + + + + + +