package com.cheng.blzb.ui.fragment.bid.detail

import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.UploadFileEntity
import com.cheng.blzb.utils.BitmapUtils

class BidImageAdapter: BaseQuickAdapter<UploadFileEntity, BaseViewHolder>(R.layout.listitem_bid_detail_image) {
    override fun convert(holder: BaseViewHolder, item: UploadFileEntity) {
        Glide.with(context)
            .asBitmap()
            .load(item.url)
            .into(object : CustomTarget<Bitmap>() {
                override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
                    val scale =  recyclerView.width / resource.width
                    val bitmap = BitmapUtils.resizeBitmap(resource, recyclerView.width, resource.height * scale )
                    holder.setImageBitmap(R.id.iv_image, bitmap)
                }

                override fun onLoadCleared(placeholder: Drawable?) {

                }

            })
    }
}