package com.swago.room.gift

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.swago.baseswago.model.live.gift.GiftModel
import com.swago.room.R

/**
 *@date 2021/12/13 16:13
 *description:
 */
class GiftAdapter(private val type: Int, layoutResId: Int, data: ArrayList<GiftModel>) :
    BaseQuickAdapter<GiftModel, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: GiftModel) {
        helper.apply {
            setText(R.id.tvCoin, item.gift_coins)
            setText(R.id.tvName, item.gift_name)
            val ivGift = itemView.findViewById<ImageView>(R.id.ivGift)
            Glide.with(itemView.context).load(item.gift_icon_url)
                .placeholder(R.mipmap.default_avatar)
                .error(R.mipmap.default_avatar).into(ivGift)
            if (item.isSelected) {
                setVisible(R.id.tvNum,true)
                setBackgroundRes(R.id.rootView, R.drawable.shape_9ffd88_5_stroke)
            } else {
                setVisible(R.id.tvNum,false)
                setBackgroundRes(R.id.rootView, R.drawable.shape_touming)
            }

            if (type == 3) {
                if (GiftConfig.clickCount >= 0) {
                    setText(R.id.tvNum, "x" + GiftConfig.list[GiftConfig.clickCount])
                }
            } else {
                setText(R.id.tvNum, "x1")
            }

        }
    }
}