package com.sw.dualscreen.adapter import android.annotation.SuppressLint import android.content.Context import android.graphics.Color import android.view.LayoutInflater import android.view.ViewGroup import android.widget.TextView import androidx.core.graphics.toColorInt import androidx.core.view.updateLayoutParams import androidx.recyclerview.widget.RecyclerView import com.chad.library.adapter4.BaseQuickAdapter import com.chad.library.adapter4.viewholder.QuickViewHolder import com.sw.dualscreen.databinding.ListItemFoodOrderBinding import com.sw.dualscreen.ext.dp import com.sw.dualscreen.ext.format2String import com.sw.dualscreen.ext.gone import com.sw.dualscreen.ext.visible import com.sw.dualscreen.model.response.FoodItem class FoodOrderAdapter(list: MutableList) : BaseQuickAdapter(list) { inner class VH(var binding: ListItemFoodOrderBinding) : QuickViewHolder(binding.root) override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH { val inflater = LayoutInflater.from(context) val binding = ListItemFoodOrderBinding.inflate(inflater, parent, false) return VH(binding) } @SuppressLint("SetTextI18n") override fun onBindViewHolder(holder: VH, position: Int, item: FoodItem?) { val binding = holder.binding setTextColor(binding.tvFoodName, binding.tvPriceNorm, binding.tvWeight, binding.tvAmount) item?.let { binding.tvFoodName.text = it.foodName binding.tvFoodName.setTextColor(if (it.isLocalData) Color.GREEN else "#FF33446A".toColorInt()) if (it.orderFrom == 2) { binding.tvPriceNorm.text = if (it.specName.isNullOrBlank()) "${it.specWeight}克" else "${it.specName}/${it.specWeight}克" } else { // 营养秤结算:规格栏显示规格重量 specWeight binding.tvPriceNorm.text = "${it.specWeight}克" } //if (it.specName.isNullOrBlank().not()) { // binding.tvPriceFlag.text = "[${it.specName}]" //} binding.tvWeight.text = "${it.num}克" binding.tvAmount.text = it.price.format2String(2) binding.tvLabel.run { if (it.orderFrom == 2) visible() else gone() } } binding.root.updateLayoutParams { topMargin = 2.dp bottomMargin = 2.dp } } fun setTextColor(vararg tvList: TextView) { tvList.forEach { it.setTextColor("#FF33446A".toColorInt()) } } }