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

import android.text.Html
import android.text.TextUtils
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.cheng.blzb.R
import com.cheng.blzb.bean.BidItemEntity
import com.cheng.blzb.utils.BidTypeUtils
import com.cheng.blzb.widget.CommonShapeView
import com.example.base.ui.list.LoadMoreAdapter
import java.text.DecimalFormat

class BidAdapter(private val showTipsTime: Boolean = false) : LoadMoreAdapter<BidItemEntity>(R.layout.listitem_bid) {

    override fun convert(holder: BaseViewHolder, item: BidItemEntity) {
        val tvTag = holder.getView<CommonShapeView>(R.id.tv_tag)
        tvTag.setBgColor(BidTypeUtils.getTypeColor(item.typeName))
        tvTag.text = BidTypeUtils.getShortName(item.typeName)

        holder.setText(R.id.tv_title, Html.fromHtml(item.title, Html.FROM_HTML_MODE_LEGACY))
        holder.setText(R.id.tv_content, Html.fromHtml(item.content, Html.FROM_HTML_MODE_LEGACY))
        holder.setText(R.id.tv_location, if (TextUtils.isEmpty(item.regionName)) "全国" else item.regionName)
        holder.setText(R.id.tv_amount, item.money)
        holder.setText(R.id.tv_time, item.tipsTime)
        holder.setText(R.id.tv_rate, DecimalFormat("0.0").format(item.star.toFloat()))

        holder.setGone(R.id.tv_amount, TextUtils.isEmpty(item.money))
        holder.setGone(R.id.tv_time, !showTipsTime || TextUtils.isEmpty(item.tipsTime))
    }
}