lmw
2023-06-13 adf8013576cbdd12e5ebea8ff7e32baf5d558b27
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
78
79
80
81
82
83
84
85
86
87
88
89
package com.kuanzhai.user.ui.official.adapter
 
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
import android.widget.TextView
import cn.sinata.xldutils.adapter.HFRecyclerAdapter
import cn.sinata.xldutils.adapter.util.ViewHolder
import cn.sinata.xldutils.clickDelay
import com.kuanzhai.user.R
import com.kuanzhai.user.network.entity.Passenger
import java.util.ArrayList
 
class PassengerAdapter(data: ArrayList<Passenger>,private val tvCount:TextView? = null) : HFRecyclerAdapter<Passenger>(data, R.layout.item_passenger) {
    var callback:MoreCallback? = null
    override fun onBind(holder: ViewHolder, position: Int, data: Passenger) {
        holder.bind<View>(R.id.iv_del).apply {
            setOnClickListener {
                mData.removeAt(position)
                notifyDataSetChanged()
                tvCount?.text = "出行人数 ${mData.size}"
            }
            visibility = if (position == 0) View.INVISIBLE else View.VISIBLE
        }
        holder.bind<View>(R.id.iv_more).apply {
            visibility = if (position == mData.lastIndex) View.VISIBLE else View.INVISIBLE
            clickDelay {
                callback?.onClick(position)
            }
        }
        holder.bind<EditText>(R.id.et_name).apply {
            setText(data.name)
            setSelection(data.name.length)
            val watcher = object : TextWatcher {
                override fun beforeTextChanged(
                    s: CharSequence?,
                    start: Int,
                    count: Int,
                    after: Int
                ) {
                }
 
                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                }
 
                override fun afterTextChanged(s: Editable?) {
                    data.name = s.toString()
                }
            }
            setOnFocusChangeListener { v, hasFocus ->
                if (hasFocus)
                    addTextChangedListener(watcher)
                else
                    removeTextChangedListener(watcher)
            }
        }
        holder.bind<EditText>(R.id.et_phone).apply {
            setText(data.phone)
            setSelection(data.phone.length)
            val watcher = object : TextWatcher {
                override fun beforeTextChanged(
                    s: CharSequence?,
                    start: Int,
                    count: Int,
                    after: Int
                ) {
                }
 
                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                }
 
                override fun afterTextChanged(s: Editable?) {
                    data.phone = s.toString()
                }
            }
            setOnFocusChangeListener { v, hasFocus ->
                if (hasFocus)
                    addTextChangedListener(watcher)
                else
                    removeTextChangedListener(watcher)
            }
        }
    }
 
    interface MoreCallback{
        fun onClick(position:Int)
    }
}