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

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

class MessageAdapter: LoadMoreAdapter<SubscriptionMessageEntity>(R.layout.listitem_message) {
    override fun convert(holder: BaseViewHolder, item: SubscriptionMessageEntity) {
        val tvTag = holder.getView<CommonShapeView>(R.id.tv_tag)
        tvTag.setBgColor(BidTypeUtils.getTypeColor(item.extra.typeName))
        tvTag.text = BidTypeUtils.getShortName(item.extra.typeName)

        holder.setText(R.id.tv_time, item.create_time)
        holder.setText(R.id.tv_title, item.extra.title)
        holder.setText(R.id.tv_location, if (TextUtils.isEmpty(item.extra.regionName)) "全国" else item.extra.regionName)
        holder.setText(R.id.tv_amount, StringUtils.formatAmount(item.extra.money))
        holder.setText(R.id.tv_rate, DecimalFormat("0.0").format(item.extra.star.toFloat()))

        holder.setGone(R.id.tv_amount, TextUtils.isEmpty(item.extra.money))
    }
}