package com.zj365.health.adapter.familyhealth

import android.graphics.Typeface
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.util.SpannableUtils
import com.xty.network.model.WatchCurrentTimeBean
import com.zj365.health.R

class FamilyHealthRealTimeAdapter : BaseAdapter<WatchCurrentTimeBean.MeasureBean>(R.layout.item_family_health_real_time) {
    //器官名
    private val units = arrayOf(
        R.string.info_4_unit, R.string.info_1_unit,  R.string.info_2_unit, R.string.info_3_unit


    )

    override fun convert(holder: BaseViewHolder, item: WatchCurrentTimeBean.MeasureBean) {

        var imgTarget = holder.getView<ImageView>(R.id.img_body)
        holder.setText(R.id.tv_update,"更新时间：${item.time}")
        var tvValue = holder.getView<TextView>(R.id.tv_body_name)
        var typeName = "心率："
        when(item.type){
            1 ->{
                imgTarget.setImageResource(R.mipmap.ic_temp)
                typeName = "体温："

            }

            2 ->{
                imgTarget.setImageResource(R.mipmap.ic_xl)
                typeName = "心率："
            }

            3 ->{
                imgTarget.setImageResource(R.mipmap.ic_xya)
                typeName = "血压："

            }

            4 ->{
                imgTarget.setImageResource(R.mipmap.ic_oo)
                typeName = "血氧："
            }
        }

        tvValue.text = SpannableUtils.setStrSpan(
            "${typeName}${item.value}${context.getString(units[item.type-1])}",
            14,
            ContextCompat.getColor(
                context, R.color.col_313
            ),
            Typeface.BOLD,
            0,
            "${typeName}${item.value}${context.getString(units[item.type-1])}".length -
                    context.getString(units[item.type-1]).length)
    }
}