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)
|
}
|
}
|