Use BindableItem in HeaderItem.

This commit is contained in:
Isira Seneviratne 2020-11-28 13:58:34 +05:30
parent 51a948bfcf
commit 9e5f079cf2
1 changed files with 12 additions and 8 deletions

View File

@ -1,19 +1,23 @@
package org.schabi.newpipe.local.subscription.item
import android.view.View
import android.view.View.OnClickListener
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item
import kotlinx.android.synthetic.main.header_item.header_title
import com.xwray.groupie.viewbinding.BindableItem
import org.schabi.newpipe.R
import org.schabi.newpipe.databinding.HeaderItemBinding
class HeaderItem(val title: String, private val onClickListener: (() -> Unit)? = null) : Item() {
class HeaderItem(
val title: String,
private val onClickListener: (() -> Unit)? = null
) : BindableItem<HeaderItemBinding>() {
override fun getLayout(): Int = R.layout.header_item
override fun bind(viewHolder: GroupieViewHolder, position: Int) {
viewHolder.header_title.text = title
override fun bind(viewBinding: HeaderItemBinding, position: Int) {
viewBinding.headerTitle.text = title
val listener: OnClickListener? = if (onClickListener != null) OnClickListener { onClickListener.invoke() } else null
viewHolder.root.setOnClickListener(listener)
viewBinding.root.setOnClickListener(listener)
}
override fun initializeViewBinding(view: View) = HeaderItemBinding.bind(view)
}