Use BindableItem in FeedGroupCarouselItem.
This commit is contained in:
parent
ee94b296ae
commit
761f6568fa
2 changed files with 23 additions and 26 deletions
|
@ -17,7 +17,6 @@ import android.view.MenuInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.lifecycle.Observer
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
@ -27,12 +26,13 @@ import com.xwray.groupie.Group
|
||||||
import com.xwray.groupie.GroupAdapter
|
import com.xwray.groupie.GroupAdapter
|
||||||
import com.xwray.groupie.Item
|
import com.xwray.groupie.Item
|
||||||
import com.xwray.groupie.Section
|
import com.xwray.groupie.Section
|
||||||
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
|
import com.xwray.groupie.viewbinding.GroupieViewHolder
|
||||||
import icepick.State
|
import icepick.State
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.databinding.DialogTitleBinding
|
import org.schabi.newpipe.databinding.DialogTitleBinding
|
||||||
|
import org.schabi.newpipe.databinding.FeedItemCarouselBinding
|
||||||
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
|
import org.schabi.newpipe.databinding.FragmentSubscriptionBinding
|
||||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItem
|
||||||
import org.schabi.newpipe.fragments.BaseStateFragment
|
import org.schabi.newpipe.fragments.BaseStateFragment
|
||||||
|
@ -79,7 +79,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
||||||
|
|
||||||
private var subscriptionBroadcastReceiver: BroadcastReceiver? = null
|
private var subscriptionBroadcastReceiver: BroadcastReceiver? = null
|
||||||
|
|
||||||
private val groupAdapter = GroupAdapter<GroupieViewHolder>()
|
private val groupAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
|
||||||
private val feedGroupsSection = Section()
|
private val feedGroupsSection = Section()
|
||||||
private var feedGroupsCarousel: FeedGroupCarouselItem? = null
|
private var feedGroupsCarousel: FeedGroupCarouselItem? = null
|
||||||
private lateinit var importExportItem: FeedImportExportItem
|
private lateinit var importExportItem: FeedImportExportItem
|
||||||
|
@ -234,7 +234,7 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
||||||
|
|
||||||
private fun setupInitialLayout() {
|
private fun setupInitialLayout() {
|
||||||
Section().apply {
|
Section().apply {
|
||||||
val carouselAdapter = GroupAdapter<GroupieViewHolder>()
|
val carouselAdapter = GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>()
|
||||||
|
|
||||||
carouselAdapter.add(FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS))
|
carouselAdapter.add(FeedGroupCardItem(-1, getString(R.string.all), FeedGroupIcon.RSS))
|
||||||
carouselAdapter.add(feedGroupsSection)
|
carouselAdapter.add(feedGroupsSection)
|
||||||
|
@ -288,15 +288,12 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
||||||
binding.itemsList.adapter = groupAdapter
|
binding.itemsList.adapter = groupAdapter
|
||||||
|
|
||||||
viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java)
|
viewModel = ViewModelProvider(this).get(SubscriptionViewModel::class.java)
|
||||||
viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleResult) })
|
viewModel.stateLiveData.observe(viewLifecycleOwner, { it?.let(this::handleResult) })
|
||||||
viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, Observer { it?.let(this::handleFeedGroups) })
|
viewModel.feedGroupsLiveData.observe(viewLifecycleOwner, { it?.let(this::handleFeedGroups) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLongTapDialog(selectedItem: ChannelInfoItem) {
|
private fun showLongTapDialog(selectedItem: ChannelInfoItem) {
|
||||||
val commands = arrayOf(
|
val commands = arrayOf(getString(R.string.share), getString(R.string.unsubscribe))
|
||||||
getString(R.string.share),
|
|
||||||
getString(R.string.unsubscribe)
|
|
||||||
)
|
|
||||||
|
|
||||||
val actions = DialogInterface.OnClickListener { _, i ->
|
val actions = DialogInterface.OnClickListener { _, i ->
|
||||||
when (i) {
|
when (i) {
|
||||||
|
@ -439,11 +436,8 @@ class SubscriptionFragment : BaseStateFragment<SubscriptionState>() {
|
||||||
return when (listMode) {
|
return when (listMode) {
|
||||||
getString(R.string.list_view_mode_auto_key) -> {
|
getString(R.string.list_view_mode_auto_key) -> {
|
||||||
val configuration = resources.configuration
|
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
|
getString(R.string.list_view_mode_grid_key) -> true
|
||||||
else -> false
|
else -> false
|
||||||
|
|
|
@ -6,13 +6,16 @@ import android.view.View
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.xwray.groupie.GroupAdapter
|
import com.xwray.groupie.GroupAdapter
|
||||||
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
|
import com.xwray.groupie.viewbinding.BindableItem
|
||||||
import com.xwray.groupie.kotlinandroidextensions.Item
|
import com.xwray.groupie.viewbinding.GroupieViewHolder
|
||||||
import kotlinx.android.synthetic.main.feed_item_carousel.recycler_view
|
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
import org.schabi.newpipe.databinding.FeedItemCarouselBinding
|
||||||
import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecoration
|
import org.schabi.newpipe.local.subscription.decoration.FeedGroupCarouselDecoration
|
||||||
|
|
||||||
class FeedGroupCarouselItem(context: Context, private val carouselAdapter: GroupAdapter<GroupieViewHolder>) : Item() {
|
class FeedGroupCarouselItem(
|
||||||
|
context: Context,
|
||||||
|
private val carouselAdapter: GroupAdapter<GroupieViewHolder<FeedItemCarouselBinding>>
|
||||||
|
) : BindableItem<FeedItemCarouselBinding>() {
|
||||||
private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context)
|
private val feedGroupCarouselDecoration = FeedGroupCarouselDecoration(context)
|
||||||
|
|
||||||
private var linearLayoutManager: LinearLayoutManager? = null
|
private var linearLayoutManager: LinearLayoutManager? = null
|
||||||
|
@ -30,12 +33,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group
|
||||||
listState = state
|
listState = state
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createViewHolder(itemView: View): GroupieViewHolder {
|
override fun initializeViewBinding(view: View): FeedItemCarouselBinding {
|
||||||
val viewHolder = super.createViewHolder(itemView)
|
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
|
layoutManager = linearLayoutManager
|
||||||
adapter = carouselAdapter
|
adapter = carouselAdapter
|
||||||
addItemDecoration(feedGroupCarouselDecoration)
|
addItemDecoration(feedGroupCarouselDecoration)
|
||||||
|
@ -44,12 +47,12 @@ class FeedGroupCarouselItem(context: Context, private val carouselAdapter: Group
|
||||||
return viewHolder
|
return viewHolder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
|
override fun bind(viewBinding: FeedItemCarouselBinding, position: Int) {
|
||||||
viewHolder.recycler_view.apply { adapter = carouselAdapter }
|
viewBinding.recyclerView.apply { adapter = carouselAdapter }
|
||||||
linearLayoutManager?.onRestoreInstanceState(listState)
|
linearLayoutManager?.onRestoreInstanceState(listState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun unbind(viewHolder: GroupieViewHolder) {
|
override fun unbind(viewHolder: GroupieViewHolder<FeedItemCarouselBinding>) {
|
||||||
super.unbind(viewHolder)
|
super.unbind(viewHolder)
|
||||||
|
|
||||||
listState = linearLayoutManager?.onSaveInstanceState()
|
listState = linearLayoutManager?.onSaveInstanceState()
|
||||||
|
|
Loading…
Reference in a new issue