package com.zj365.health.adapter

import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.zj365.health.R
import com.zj365.health.model.BloodBean

class BloodCalibrationAdapter: BaseAdapter<BloodBean>(R.layout.item_blood_calib) {
    val titleArray by lazy{context.resources.getStringArray(R.array.blood_array)}
    override fun convert(holder: BaseViewHolder, item: BloodBean) {
        var position=holder.layoutPosition
        holder.setText(R.id.mTitle,titleArray[holder.layoutPosition])
       var v1= holder.getView<EditText>(R.id.mEditGdbp)
       var v2= holder.getView<EditText>(R.id.mEditDdbp)
        setTextChange(v1,position,true)
        setTextChange(v2,position,false)

    }

   private  fun setTextChange(v:EditText,position:Int,isGDbg:Boolean){
        v.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                var value=s.toString().trim()
                if(isGDbg){
                    data[position].hsbp=value
                }else{
                    data[position].hdbp=value
                }

            }
        })
    }

}