package com.xw.yunwei.ui.work.site
|
|
import android.annotation.SuppressLint
|
import android.view.View
|
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.OneItemElementClickListener
|
import com.xw.common.utils.BindUtils.getResColor
|
import com.xw.common.utils.BindUtils.getUrl
|
import com.xw.common.utils.GlideEngine
|
import com.xw.yunwei.R
|
import com.xw.yunwei.databinding.ItemWorkSiteBinding
|
import com.xw.yunwei.model.SiteModel
|
import com.xw.yunwei.model.sitePlaceHolder
|
import org.json.JSONArray
|
|
class SiteAdapter(
|
val activity: FragmentActivity,
|
var listener: OneItemElementClickListener<SiteModel>
|
) :
|
BaseQuickAdapter<SiteModel, BaseViewHolder>(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.parent.visibility = if (item == sitePlaceHolder) View.GONE else View.VISIBLE
|
it.tips.visibility = if (item == sitePlaceHolder) View.VISIBLE else View.GONE
|
if (item == sitePlaceHolder) {
|
return
|
}
|
it.parent.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) {
|
e.printStackTrace()
|
}
|
GlideEngine.createGlideEngine()
|
.load(binding.icon, url, R.drawable.img_site_bg, R.drawable.img_site_bg, 5f)
|
|
|
// 接口未返回
|
// 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)
|
// }
|
}
|
}
|
|
}
|