| | |
| | | import com.chad.library.adapter.base.viewholder.BaseViewHolder |
| | | import com.xw.common.base.OnItemClickListener |
| | | import com.xw.common.utils.BindUtils.getResColor |
| | | import com.xw.common.utils.BindUtils.getUrl |
| | | import com.xw.common.viewAdapter.ImageDefault |
| | | import com.xw.common.viewAdapter.ViewAdapter |
| | | import com.xw.yunwei.R |
| | | import com.xw.yunwei.databinding.ItemSelectCarBinding |
| | | import com.xw.yunwei.extension.colorIdToColorValue |
| | | import com.xw.yunwei.model.CarModel |
| | | |
| | | /** |
| | | * 选择车辆列表适配器 |
| | | * |
| | | * 展示车辆基本信息(车牌号、颜色、编码、车辆照片), |
| | | * 根据运营状态显示不同颜色标签,并支持单选高亮效果。 |
| | | * |
| | | * @property listener 列表项点击事件回调 |
| | | */ |
| | | class SelectCarAdapter(var listener: OnItemClickListener<CarModel>) : |
| | | BaseQuickAdapter<CarModel, BaseViewHolder>(R.layout.item_select_car) { |
| | | |
| | | /** 当前选中的车辆,为空表示未选择 */ |
| | | var selectCar: CarModel? = null |
| | | |
| | | @SuppressLint("SetTextI18n", "NotifyDataSetChanged") |
| | | override fun convert(holder: BaseViewHolder, item: CarModel) { |
| | | val binding = DataBindingUtil.bind<ItemSelectCarBinding>(holder.itemView) |
| | | binding?.let { |
| | | var url = "" |
| | | try { |
| | | url = item.vehiclePictures?.getUrl() ?: "" |
| | | } catch (e: Exception) { |
| | | } |
| | | ViewAdapter.loadImage(binding.icon, ImageDefault(url, R.mipmap.img_work_car)) |
| | | // 加载车辆图片,异常时显示默认车辆图 |
| | | ViewAdapter.loadImage(binding.icon, ImageDefault(item.getShowVehiclePicture(), R.mipmap.img_work_car)) |
| | | binding.name.text = item.plateNumber |
| | | binding.color.text = "${item.vehicleColor} | 车身编码:${item.vehicleCode}" |
| | | binding.color.text = "${item.vehicleColor} | 车身编码:${item.getShowVehicleCode(6)}" |
| | | binding.status.setBackgroundResource(item.getShowStatusBgResource()) |
| | | binding.status.setTextColor(item.getShowStatusTextColor().colorIdToColorValue(it.root.context)) |
| | | binding.status.text=item.getShowStatus() |
| | | |
| | | val setStatus: (Int, Int) -> Unit = { text, bg -> |
| | | binding.status.setTextColor(text) |
| | | binding.status.setBackgroundResource(bg) |
| | | } |
| | | |
| | | // 1=运营中 2=维修中 3=已收车 4=车辆异常 |
| | | when (item.operatingStatus) { |
| | | 1 -> { |
| | | setStatus( |
| | | getResColor(com.xw.common.R.color.blue_5), com.xw.common.R.color.blue_1 |
| | | ) |
| | | binding.status.text = "运营中" |
| | | } |
| | | |
| | | 2 -> { |
| | | setStatus( |
| | | getResColor(com.xw.common.R.color.red_5), com.xw.common.R.color.red_1 |
| | | ) |
| | | binding.status.text = "维修中" |
| | | } |
| | | |
| | | 3 -> { |
| | | setStatus( |
| | | getResColor(com.xw.common.R.color.gray_7), com.xw.common.R.color.gray_3 |
| | | ) |
| | | binding.status.text = "已收车" |
| | | } |
| | | |
| | | 4 -> { |
| | | setStatus( |
| | | getResColor(com.xw.common.R.color.orange_5), com.xw.common.R.color.orange_1 |
| | | ) |
| | | binding.status.text = "车辆异常" |
| | | } |
| | | } |
| | | |
| | | // 选中状态高亮:变更背景与文字颜色 |
| | | if (item.id == selectCar?.id) { |
| | | binding.llContent.setBackgroundColor(getResColor(com.xw.common.R.color.blue_1)) |
| | | binding.name.setTextColor(getResColor(com.xw.common.R.color.blue_5)) |
| | |
| | | binding.color.setTextColor(getResColor(com.xw.common.R.color.gray_7)) |
| | | } |
| | | it.root.setOnClickListener { |
| | | // 切换选中状态:再次点击取消选中 |
| | | selectCar = if (selectCar == item) null else item |
| | | notifyDataSetChanged() |
| | | listener.onItemClick(item) |