package com.base.scanqrclear.ui.scan

import android.content.Context
import android.view.ViewGroup
import com.base.scanqrclear.R
import com.base.scanqrclear.bean.FunctionUIBean
import com.base.scanqrclear.databinding.ItemScanBinding
import com.base.scanqrclear.ui.adapter.CommonViewHolder
import com.base.scanqrclear.utils.XmlEx.inflate
import com.chad.library.adapter4.BaseQuickAdapter

class ScanOtherAdapter : BaseQuickAdapter<FunctionUIBean, CommonViewHolder>() {

    var itemClick: ((item: FunctionUIBean) -> Unit)? = null

    override fun onBindViewHolder(holder: CommonViewHolder, position: Int, item: FunctionUIBean?) {
        item ?: return
        val binding = ItemScanBinding.bind(holder.itemView)
        binding.iv.setImageResource(item.icon)
        binding.tv.text = item.desc
        binding.root.setOnClickListener {
            itemClick?.invoke(item)
        }
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): CommonViewHolder {
        return CommonViewHolder(R.layout.item_scan.inflate(parent))
    }
}