package com.yzx.escreen.adapter

import android.annotation.SuppressLint
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yzx.escreen.R
import com.yzx.escreen.model.Device
import kotlinx.android.synthetic.main.layout_device_item.view.*

class DeviceListAdapter(list: MutableList<Device>) :
    BaseQuickAdapter<Device, BaseViewHolder>(R.layout.layout_device_item, list) {

    init {
        addChildClickViewIds(R.id.actionOpen, R.id.actionNormal)
    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: Device) {
        holder.itemView.deviceName.text = item.name
        holder.itemView.deviceTypeName.text = "进出校考勤设备"
        holder.itemView.deviceTagName.text = if (item.type == 1) {
            "进闸设备"
        } else {
            "出闸设备"
        }
        holder.itemView.deviceName.isChecked = item.isChecked
        holder.itemView.deviceName.setOnCheckedChangeListener { _, isChecked ->
            item.isChecked = isChecked
        }

        holder.itemView.bottomLine.visibility = if (holder.adapterPosition == data.size - 1) {
            View.GONE
        } else {
            View.VISIBLE
        }


    }
}