package com.zj365.health.adapter.familyhealth

import android.view.View
import android.view.ViewGroup
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.setImageUser
import com.zj365.health.R
import de.hdodenhof.circleimageview.CircleImageView


class HealthFamilyUserAvatorAdapter : BaseAdapter<String>(R.layout.item_health_family_user_avator) {
    override fun convert(holder: BaseViewHolder, item: String) {
        val position = holder.layoutPosition
        if (position == 0){
            setMargins(holder.itemView,0,0,0,0)
        }
        if (item != null){
            holder.getView<CircleImageView>(R.id.img_user_avator).setImageUser(context,item)

        }else{
            holder.getView<CircleImageView>(R.id.img_user_avator).setImageResource(R.mipmap.icon_default_avator)

        }

        holder.getView<CircleImageView>(R.id.img_user_avator).setOnClickListener {
            RouteManager.goAct(ARouterUrl.FAMILY_GUARDIAN_LIST_ACT)
        }

    }

    fun setMargins(v: View, l: Int, t: Int, r: Int, b: Int) {
        if (v.layoutParams is ViewGroup.MarginLayoutParams) {
            val p = v.layoutParams as ViewGroup.MarginLayoutParams
            p.setMargins(l, t, r, b)
            v.requestLayout()
        }
    }
}