package com.xw.yunwei.ui.work.site import android.annotation.SuppressLint import android.view.LayoutInflater import androidx.databinding.DataBindingUtil import androidx.fragment.app.FragmentActivity import com.chad.library.adapter.base.BaseQuickAdapter import com.chad.library.adapter.base.viewholder.BaseViewHolder import com.xw.common.base.OnItemClickListener import com.xw.common.base.OneItemElementClickListener import com.xw.common.databinding.ItemTextBinding 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.ItemWorkSiteBinding import com.xw.yunwei.model.CarModel import com.xw.yunwei.model.SiteModel import org.json.JSONArray class SiteAdapter(val activity: FragmentActivity, var listener: OneItemElementClickListener) : BaseQuickAdapter(R.layout.item_work_site) { var selectItem: SiteModel? = null @SuppressLint("NotifyDataSetChanged") set(value) { field = value notifyDataSetChanged() } override fun convert(holder: BaseViewHolder, item: SiteModel) { val binding: ItemWorkSiteBinding? = DataBindingUtil.bind(holder.itemView) binding?.let { it.root.setOnClickListener { listener.onItemClick(item) } it.nav.setOnClickListener { listener.oneItemElementClick(item) } if (item == selectItem) { it.parent.setBackgroundColor(getResColor(com.xw.common.R.color.gray_3)) } else { it.parent.setBackgroundColor(getResColor(com.xw.common.R.color.white)) } binding.name.text = item.pointName binding.address.text = item.pointAddress var url = "" try { url = JSONArray(item.pointPictures).get(0).toString().getUrl() } catch (e: Exception) { } ViewAdapter.loadImage(binding.icon, ImageDefault(url, R.mipmap.img_site_bg)) // 接口未返回 // binding.tagLayout.removeAllViews() // listOf("上车点", "下车点").forEach { // val tvBind: ItemTextBinding = DataBindingUtil.inflate( // LayoutInflater.from(activity), // com.xw.common.R.layout.item_text, // null, // false // ) // tvBind.tv.text = it // binding.tagLayout.addView(tvBind.root) // } } } }