puzhibing
2026-08-21 5fa94b3718b4a78a4fcea4c97652b0ef20b7de3a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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)
//            }
        }
    }
 
}