package com.zj365.health.adapter

import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xty.base.adapter.BaseAdapter
import com.xty.common.setImageUser
import com.zj365.health.R
import com.xty.network.model.RankBean
import de.hdodenhof.circleimageview.CircleImageView

class StepRankAdapter : BaseAdapter<RankBean.All>(R.layout.item_step_rank_list) {
    private val arrayImage by lazy { arrayOf(R.mipmap.ic_gold, R.mipmap.ic_silver, R.mipmap.ic_bronze) }
    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}")
        }

        val rank = "${item.rankSumStep}步"
        holder.setText(
            R.id.mRank , rank)
//        holder.setText(
//            R.id.mRank, SpannableUtils.setStrSpan(
//                rank,
//                20,
//                ContextCompat.getColor(
//                    context, R.color.col_009
//                ),
//                Typeface.BOLD,
//                0,
//                rank.length - 1
//            )
//        )
//        holder.getView<TextView>(R.id.mRank).gravity = Gravity.CENTER_VERTICAL
        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)
    }
}