Added working binding for a "new" button that works in the list layout.

This commit is contained in:
Samuel Wu 2022-10-25 02:38:31 +11:00
parent 6eddaa0d38
commit 082d7a3f18
3 changed files with 66 additions and 9 deletions

View File

@ -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<SubscriptionState>() {
private fun changeLayout() {
listView = true
Section().apply {
val carouselAdapter2 = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
val carouselAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
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<SubscriptionState>() {
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<SubscriptionState>() {
}
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<SubscriptionState>() {
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)
}
}

View File

@ -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<FeedGroupAddNewItemVerticalBinding>() {
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)
}

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="388dp"
android:layout_height="48dp"
android:layout_gravity="center_vertical"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:cardBackgroundColor="?attr/card_item_background_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/dashed_border"
android:gravity="center"
android:orientation="vertical"
android:padding="4dp">
<ImageView
android:id="@+id/icon"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_gravity="center"
android:scaleType="centerInside"
android:src="@drawable/ic_add"
tools:ignore="ContentDescription" />
<org.schabi.newpipe.views.NewPipeTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@string/feed_create_new_group_button_title"
android:textAllCaps="true"
android:textColor="?attr/colorAccent"
android:textSize="10sp"
android:textStyle="bold"
tools:ignore="SmallSp" />
</LinearLayout>
</androidx.cardview.widget.CardView>