package com.lukouguoji.gjj.holder

import android.view.View
import com.lukouguoji.gjj.databinding.ItemJianBinding
import com.lukouguoji.module_base.base.BaseViewHolder
import com.lukouguoji.module_base.bean.JianBean
import com.lukouguoji.module_base.ktx.loge

class JianViewHolder(view: View) : BaseViewHolder<JianBean, ItemJianBinding>(view) {

    override fun onBind(item: Any?, position: Int) {
        val bean = getItemBean(item) ?: return

        binding.tv.text = bean.code
        binding.iv.visibility = if (bean.checked.get()) View.VISIBLE else View.GONE

        bean.checked.addOnPropertyChangedCallback(object :
            androidx.databinding.Observable.OnPropertyChangedCallback() {
            override fun onPropertyChanged(
                sender: androidx.databinding.Observable?,
                propertyId: Int
            ) {
                binding.iv.visibility = if (bean.checked.get()) View.VISIBLE else View.GONE
            }
        })

        notifyItemClick(position, binding.rl)
    }

}