Use BindableItem in FeedGroupReorderItem.

This commit is contained in:
Isira Seneviratne 2020-11-28 13:43:15 +05:30
parent 761f6568fa
commit 9d27d49c1f
1 changed files with 12 additions and 11 deletions

View File

@ -1,16 +1,15 @@
package org.schabi.newpipe.local.subscription.item package org.schabi.newpipe.local.subscription.item
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.ItemTouchHelper.DOWN import androidx.recyclerview.widget.ItemTouchHelper.DOWN
import androidx.recyclerview.widget.ItemTouchHelper.UP import androidx.recyclerview.widget.ItemTouchHelper.UP
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_group_reorder_item.group_icon
import kotlinx.android.synthetic.main.feed_group_reorder_item.group_name
import kotlinx.android.synthetic.main.feed_group_reorder_item.handle
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.FeedGroupReorderItemBinding
import org.schabi.newpipe.local.subscription.FeedGroupIcon import org.schabi.newpipe.local.subscription.FeedGroupIcon
data class FeedGroupReorderItem( data class FeedGroupReorderItem(
@ -18,7 +17,7 @@ data class FeedGroupReorderItem(
val name: String, val name: String,
val icon: FeedGroupIcon, val icon: FeedGroupIcon,
val dragCallback: ItemTouchHelper val dragCallback: ItemTouchHelper
) : Item() { ) : BindableItem<FeedGroupReorderItemBinding>() {
constructor (feedGroupEntity: FeedGroupEntity, dragCallback: ItemTouchHelper) : constructor (feedGroupEntity: FeedGroupEntity, dragCallback: ItemTouchHelper) :
this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon, dragCallback) this(feedGroupEntity.uid, feedGroupEntity.name, feedGroupEntity.icon, dragCallback)
@ -31,12 +30,12 @@ data class FeedGroupReorderItem(
override fun getLayout(): Int = R.layout.feed_group_reorder_item override fun getLayout(): Int = R.layout.feed_group_reorder_item
override fun bind(viewHolder: GroupieViewHolder, position: Int) { override fun bind(viewBinding: FeedGroupReorderItemBinding, position: Int) {
viewHolder.group_name.text = name viewBinding.groupName.text = name
viewHolder.group_icon.setImageResource(icon.getDrawableRes(viewHolder.containerView.context)) viewBinding.groupIcon.setImageResource(icon.getDrawableRes(viewBinding.root.context))
viewHolder.handle.setOnTouchListener { _, event -> viewBinding.handle.setOnTouchListener { _, event ->
if (event.actionMasked == MotionEvent.ACTION_DOWN) { if (event.actionMasked == MotionEvent.ACTION_DOWN) {
dragCallback.startDrag(viewHolder) dragCallback.startDrag(GroupieViewHolder(viewBinding))
return@setOnTouchListener true return@setOnTouchListener true
} }
@ -47,4 +46,6 @@ data class FeedGroupReorderItem(
override fun getDragDirs(): Int { override fun getDragDirs(): Int {
return UP or DOWN return UP or DOWN
} }
override fun initializeViewBinding(view: View) = FeedGroupReorderItemBinding.bind(view)
} }