From 761f6568fa1e4a3da0964552e60376224158e5e0 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 28 Nov 2020 13:32:39 +0530 Subject: [PATCH] Use BindableItem in FeedGroupCarouselItem. --- .../subscription/SubscriptionFragment.kt | 24 +++++++----------- .../item/FeedGroupCarouselItem.kt | 25 +++++++++++-------- 2 files changed, 23 insertions(+), 26 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 a84745dbf..61a6601fa 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 @@ -17,7 +17,6 @@ import android.view.MenuInflater import android.view.View import android.view.ViewGroup import android.widget.Toast -import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager @@ -27,12 +26,13 @@ import com.xwray.groupie.Group import com.xwray.groupie.GroupAdapter import com.xwray.groupie.Item import com.xwray.groupie.Section -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder +import com.xwray.groupie.viewbinding.GroupieViewHolder import icepick.State import io.reactivex.rxjava3.disposables.CompositeDisposable import org.schabi.newpipe.R import org.schabi.newpipe.database.feed.model.FeedGroupEntity import org.schabi.newpipe.databinding.DialogTitleBinding +import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.databinding.FragmentSubscriptionBinding import org.schabi.newpipe.extractor.channel.ChannelInfoItem import org.schabi.newpipe.fragments.BaseStateFragment @@ -79,7 +79,7 @@ class SubscriptionFragment : BaseStateFragment() { private var subscriptionBroadcastReceiver: BroadcastReceiver? = null - private val groupAdapter = GroupAdapter() + private val groupAdapter = GroupAdapter>() private val feedGroupsSection = Section() private var feedGroupsCarousel: FeedGroupCarouselItem? = null private lateinit var importExportItem: FeedImportExportItem @@ -234,7 +234,7 @@ class SubscriptionFragment : BaseStateFragment() { private fun setupInitialLayout() { Section().apply { - val carouselAdapter = GroupAdapter() + val carouselAdapter = GroupAdapter>() carouselAdapter.add(FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS)) carouselAdapter.add(feedGroupsSection) @@ -288,15 +288,12 @@ class SubscriptionFragment : BaseStateFragment() { binding.itemsList.adapter = groupAdapter viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java) - viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleResult) }) - viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleFeedGroups) }) + viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(this::handleResult) }) + viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, { it?.let(this::handleFeedGroups) }) } private fun showLongTapDialog(selectedItem: ChannelInfoItem) { - val commands = arrayOf( - getString(R.string.share), - getString(R.string.unsubscribe) - ) + val commands = arrayOf(getString(R.string.share), getString(R.string.unsubscribe)) val actions = DialogInterface.OnClickListener { _, i -> when (i) { @@ -439,11 +436,8 @@ class SubscriptionFragment : BaseStateFragment() { return when (listMode) { getString(R.string.list_view_mode_auto_key) -> { val configuration = resources.configuration - - ( - configuration.orientation == Configuration.ORIENTATION_LANDSCAPE && - configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) - ) + configuration.orientation == Configuration.ORIENTATION_LANDSCAPE + && configuration.isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE) } getString(R.string.list_view_mode_grid_key) -> true else -> false diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt index dfffce59c..44af16280 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/FeedGroupCarouselItem.kt @@ -6,13 +6,16 @@ import android.view.View import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.xwray.groupie.GroupAdapter -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.feed_item_carousel.recycler_view +import com.xwray.groupie.viewbinding.BindableItem +import com.xwray.groupie.viewbinding.GroupieViewHolder import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.FeedItemCarouselBinding import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecoration -class FeedGroupCarouselItem(context: Context, private val carouselAdapter: GroupAdapter) : Item() { +class FeedGroupCarouselItem( + context: Context, + private val carouselAdapter: GroupAdapter> +) : BindableItem() { private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context) private var linearLayoutManager: LinearLayoutManager? = null @@ -30,12 +33,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group listState = state } - override fun createViewHolder(itemView: View): GroupieViewHolder { - val viewHolder = super.createViewHolder(itemView) + override fun initializeViewBinding(view: View): FeedItemCarouselBinding { + val viewHolder = FeedItemCarouselBinding.bind(view) - linearLayoutManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false) + linearLayoutManager = LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, false) - viewHolder.recycler_view.apply { + viewHolder.recyclerView.apply { layoutManager = linearLayoutManager adapter = carouselAdapter addItemDecoration(feedGroupCarouselDecoration) @@ -44,12 +47,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group return viewHolder } - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.recycler_view.apply { adapter = carouselAdapter } + override fun bind(viewBinding: FeedItemCarouselBinding, position: Int) { + viewBinding.recyclerView.apply { adapter = carouselAdapter } linearLayoutManager?.onRestoreInstanceState(listState) } - override fun unbind(viewHolder: GroupieViewHolder) { + override fun unbind(viewHolder: GroupieViewHolder) { super.unbind(viewHolder) listState = linearLayoutManager?.onSaveInstanceState()