package xn.hxp.ui.adapter

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import xn.hxp.app.ChemicalApp
import xn.hxp.R
import com.rc.httpcore.HttpConfig

class SnapImgAdapter(private val ct: Context) :
    BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_snap_img) {
    init {
        addChildClickViewIds(R.id.img)
    }
    override fun convert(holder: BaseViewHolder, item: String) {
        var imageView = holder.getView<ImageView>(R.id.img)
        // 使用Glide加载图片并应用圆角转换，设置磁盘缓存策略为AUTOMATIC
        val requestOptions = RequestOptions()
            .transform(RoundedCorners(5)) // 设置圆角半径
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC) // 设置磁盘缓存策略
        // 使用图片加载库加载图片并显示在ImageView中
        Glide.with(ct)
            .load("${HttpConfig.API_BASE_IMG_URL}${ChemicalApp.userData!!.avatar}")
            .apply(requestOptions)
            .into(imageView)
    }
}