package com.zj365.health.adapter.binddevice

import android.widget.TextView
import androidx.core.content.ContextCompat
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.act.binddevice.BlueUtil
import com.xty.network.model.BindDeviceListBean


class BindBodyFatAdapter: BaseAdapter<BindDeviceListBean>(R.layout.item_body_fat_bind_device) {

    var isMe = false
    override fun convert(holder: BaseViewHolder, item: BindDeviceListBean) {

        if (isMe){
            holder.setVisible(R.id.tvConnectStatus,true)
            holder.setEnabled(R.id.tvBindButton,true)
            holder.setTextColor(R.id.tvBindButton,ContextCompat.getColor(context,R.color.col_25C))
        }else{
            holder.setGone(R.id.tvConnectStatus,true)
            holder.setEnabled(R.id.tvBindButton,false)
            holder.setTextColor(R.id.tvBindButton,ContextCompat.getColor(context,R.color.white))

        }
        holder.setText(R.id.tvDevName,item.sn)
//        if (item.bindTime.length>)
        holder.setText(R.id.tvBindDate,"绑定日期: ${item.bindTime}")

        val bindView = holder.getView<TextView>(R.id.tvConnectStatus)
        when (BlueUtil.getBlueManage().getDeviceConnectState(item.mac)) {
            ConnectionState.CONNECTING -> {
                bindView.setTextColor(ContextCompat.getColor(context,R.color.col_7c7))
                bindView.text = "连接中"
                item.type = 1
            }
            ConnectionState.CONNECTED -> {
                bindView.setTextColor(ContextCompat.getColor(context,R.color.col_02c))
                bindView.text = "已连接"
                item.type = 2
            }
            else -> {
                bindView.setTextColor(ContextCompat.getColor(context,R.color.col_7c7))
                bindView.text = "未连接"
                item.type = 0
            }
        }
        holder.setText(R.id.tvBindStatus,"已绑定")
    }
}