package com.zj365.health.adapter.binddevice

import android.widget.TextView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lifesense.android.ble.core.application.model.enums.ConnectionState
import com.xty.base.adapter.BaseAdapter
import com.zj365.health.R
import com.zj365.health.model.LSEDeviceInfoApp

class DeviceListAdapter:BaseAdapter<LSEDeviceInfoApp>(R.layout.item_device_list) {
    override fun convert(holder: BaseViewHolder, item: LSEDeviceInfoApp) {

        holder.setText(R.id.tvDeviceName,item.getDeviceName())
        holder.setText(R.id.tvMac,item.getMacAddress())

        val bindView = holder.getView<TextView>(R.id.tvBindDate)
        when (item.getConnectionState()) {
            ConnectionState.CONNECTING -> {
                bindView.text = "蓝牙连接中"
                holder.setImageResource(R.id.ivBlutooth,R.mipmap.ic_disconnect_bluetooth)
                holder.setEnabled(R.id.tvBindButton,false)
            }
            ConnectionState.CONNECTED,ConnectionState.CONNECT_GATT -> {
                bindView.text = "蓝牙已连接"
                holder.setImageResource(R.id.ivBlutooth,R.mipmap.ic_bluetooth)
                holder.setEnabled(R.id.tvBindButton,false)
            }
            else -> {
                bindView.text = "蓝牙未连接"
                holder.setImageResource(R.id.ivBlutooth,R.mipmap.ic_disconnect_bluetooth)
                holder.setEnabled(R.id.tvBindButton,true)
            }
        }
    }
}