package com.cheng.blzb.ui.fragment.mine.vip

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import coil.load
import coil.transform.CircleCropTransformation
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.example.base.utils.DensityUtils

class VipUserTipsAdapter(val context: Context, val data: MutableList<String>): RecyclerView.Adapter<BaseViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        val view = View.inflate(context, R.layout.listitem_vip_user_tip, null)
        val lp = ConstraintLayout.LayoutParams(LayoutParams.WRAP_CONTENT, DensityUtils.dp2px(24f))
        lp.leftMargin = DensityUtils.dp2px(10f)
        view.layoutParams = lp
        return BaseViewHolder(view)
    }

    @SuppressLint("DiscouragedApi")
    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.getView<ImageView>(R.id.iv_avatar).load(context.resources.getIdentifier("yq_${position % 50}", "mipmap", context.packageName)) {
            transformations(CircleCropTransformation())
        }
        holder.setText(R.id.tv_content, data[position % data.size])
    }

    override fun getItemCount(): Int {
        return if (data.isNotEmpty()) Int.MAX_VALUE else 0
    }

}