package com.zj365.health.adapter

import android.graphics.Typeface
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.setImageUser
import com.xty.common.util.SpannableUtils
import com.zj365.health.R
import com.xty.network.model.RankBean
import de.hdodenhof.circleimageview.CircleImageView

class RankAdapter : BaseAdapter<RankBean.All>(R.layout.item_rank_list) {
    val arrayImage by lazy { arrayOf(R.mipmap.jin, R.mipmap.yin, R.mipmap.tong) }
    override fun convert(holder: BaseViewHolder, item: RankBean.All) {
        if (holder.layoutPosition <= 2) {
            holder.setImageResource(R.id.mIvRank, arrayImage[holder.layoutPosition])
                .setGone(R.id.mIvRank, false).setGone(R.id.mTvRank, true)
        } else {
            holder.setGone(R.id.mIvRank, true).setGone(R.id.mTvRank, false)
                .setText(R.id.mTvRank, "${holder.layoutPosition + 1}")
        }

//        holder.getView<TextView>(R.id.mRank).text = SpannableUtils.setStrSpan(
//            "第${holder.layoutPosition + 1}名",
//            18,
//            ContextCompat.getColor(
//                context, R.color.col_455
//            ),
//            Typeface.BOLD,
//            1,
//            (holder.layoutPosition + 1).toString().length - 1
//        )
        val rank = "第${holder.layoutPosition + 1}名"
        holder.setText(  R.id.mRank, rank  )
        holder.getView<CircleImageView>(R.id.mImage).setImageUser(context, item.images)
        holder.setText(R.id.mName, item.name)
        holder.setText(R.id.mAddress, if (item.address.isNullOrEmpty() || "null" == item.address) "- - -" else item.address)
    }
}