diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt index b5aa6b1d0..55f56b3f5 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/HeaderWithMenuItem.kt @@ -1,13 +1,12 @@ package org.schabi.newpipe.local.subscription.item +import android.view.View import android.view.View.OnClickListener import androidx.annotation.DrawableRes import androidx.core.view.isVisible -import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder -import com.xwray.groupie.kotlinandroidextensions.Item -import kotlinx.android.synthetic.main.header_with_menu_item.header_menu_item -import kotlinx.android.synthetic.main.header_with_menu_item.header_title +import com.xwray.groupie.viewbinding.BindableItem import org.schabi.newpipe.R +import org.schabi.newpipe.databinding.HeaderWithMenuItemBinding class HeaderWithMenuItem( val title: String, @@ -15,37 +14,39 @@ class HeaderWithMenuItem( var showMenuItem: Boolean = true, private val onClickListener: (() -> Unit)? = null, private val menuItemOnClickListener: (() -> Unit)? = null -) : Item() { +) : BindableItem() { companion object { const val PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM = 1 } override fun getLayout(): Int = R.layout.header_with_menu_item - override fun bind(viewHolder: GroupieViewHolder, position: Int, payloads: MutableList) { + override fun bind(viewBinding: HeaderWithMenuItemBinding, position: Int, payloads: MutableList) { if (payloads.contains(PAYLOAD_UPDATE_VISIBILITY_MENU_ITEM)) { - updateMenuItemVisibility(viewHolder) + updateMenuItemVisibility(viewBinding) return } - super.bind(viewHolder, position, payloads) + super.bind(viewBinding, position, payloads) } - override fun bind(viewHolder: GroupieViewHolder, position: Int) { - viewHolder.header_title.text = title - viewHolder.header_menu_item.setImageResource(itemIcon) + override fun bind(viewBinding: HeaderWithMenuItemBinding, position: Int) { + viewBinding.headerTitle.text = title + viewBinding.headerMenuItem.setImageResource(itemIcon) val listener: OnClickListener? = - onClickListener?.let { OnClickListener { onClickListener.invoke() } } - viewHolder.root.setOnClickListener(listener) + onClickListener?.let { OnClickListener { onClickListener.invoke() } } + viewBinding.root.setOnClickListener(listener) val menuItemListener: OnClickListener? = - menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } - viewHolder.header_menu_item.setOnClickListener(menuItemListener) - updateMenuItemVisibility(viewHolder) + menuItemOnClickListener?.let { OnClickListener { menuItemOnClickListener.invoke() } } + viewBinding.headerMenuItem.setOnClickListener(menuItemListener) + updateMenuItemVisibility(viewBinding) } - private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) { - viewHolder.header_menu_item.isVisible = showMenuItem + override fun initializeViewBinding(view: View) = HeaderWithMenuItemBinding.bind(view) + + private fun updateMenuItemVisibility(viewBinding: HeaderWithMenuItemBinding) { + viewBinding.headerMenuItem.isVisible = showMenuItem } }