package com.yidian.shenghuoquan.buserorder.adapter

import android.annotation.SuppressLint
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
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 com.yidian.bcommon.extensions.hide
import com.yidian.bcommon.extensions.show
import com.yidian.news.util.DensityUtil
import com.yidian.shenghuoquan.buserorder.R
import com.yidian.shenghuoquan.buserorder.dto.GoodsDto

/**
 * 确认订单页面商品列表适配器
 */
class OrderConfirmCommodityListAdapter : BaseQuickAdapter<GoodsDto, BaseViewHolder>(R.layout.border_item_order_confirm_commodity_list) {

  @SuppressLint("SetTextI18n")
  override fun convert(holder: BaseViewHolder, item: GoodsDto) {
    holder.getView<TextView>(R.id.tv_commodity_name).text = item.goodsName
    holder.getView<TextView>(R.id.tv_commodity_count).text = "共" + item.goodsNum + "件"
    holder.getView<TextView>(R.id.tv_commodity_amount).text = "¥" + String.format("%.2f", item.price)
    val ivCommodityPic = holder.getView<ImageView>(R.id.iv_commodity_pic)
    if (item.picUrl.isBlank()) {
      ivCommodityPic.hide()
    } else {
      ivCommodityPic.show()
      Glide.with(context).load(item.picUrl)
        .apply(
          RequestOptions()
            .transform(CenterCrop(), RoundedCorners(DensityUtil.dp2px(12F)))
            .error(R.drawable.img_order_commodity_placeholder)
            .placeholder(R.drawable.img_order_commodity_placeholder)
        )
        .into(ivCommodityPic)
    }
  }

}
