package com.dahe.gldriver.adapter

import android.content.Context
import android.os.Build
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.dahe.gldriver.R
import com.dahe.gldriver.bean.DriverBean
import com.dahe.gldriver.bean.RateBean
import com.dahe.glex.bean.WayBillBean
import com.dahe.mylibrary.utils.ImageLoader
import me.zhanghai.android.materialratingbar.MaterialRatingBar

/**
 * @ClassName WaybillAdapter
 * @Author 用户
 * @Date 2024/3/18 16:27
 * @Description 评价管理adapter
 */
class RateAdapter(var isInvite: Boolean = false) :
    BaseQuickAdapter<RateBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: RateBean?) {
        item?.let {
            holder.run {
                setText(R.id.tvDate, item.createTime)
                setText(R.id.tvContent, item.opinionsContent)
                setText(R.id.tvComName, item.realCompanyName)
                setText(
                    R.id.tvRate,
                    """交易${item.shipperPositiveReviewRate} 好评率${item.shipperTransactionVolume.toInt() * 100}%"""
                )

                val rating = getView<MaterialRatingBar>(R.id.rating)
                rating.rating = item.opinionsStarRating.toFloat() / 2
                ImageLoader.getInstance()
                    .loadRoundImage(context, it.avatar, 6, getView<ImageView>(R.id.ivHead))
            }
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): QuickViewHolder {
        // 返回一个 ViewHolder
        return QuickViewHolder(R.layout.item_rate, parent)
    }
}