feat: opt ui
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.lukouguoji.gjc.holder
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjc.databinding.ItemGjcCheckInRecordBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
@@ -12,6 +14,8 @@ class GjcCheckInRecordViewHolder(view: View) :
|
||||
BaseViewHolder<GjcCheckInRecord, ItemGjcCheckInRecordBinding>(view) {
|
||||
|
||||
private var isEditMode: Boolean = false
|
||||
private var pcTextWatcher: TextWatcher? = null
|
||||
private var weightTextWatcher: TextWatcher? = null
|
||||
|
||||
fun updateEditMode(editMode: Boolean) {
|
||||
this.isEditMode = editMode
|
||||
@@ -23,17 +27,29 @@ class GjcCheckInRecordViewHolder(view: View) :
|
||||
binding.isEditMode = isEditMode
|
||||
binding.position = position // 传入位置用于显示序号
|
||||
|
||||
// 设置refreshCallBack来捕获用户输入的变化
|
||||
if (isEditMode) {
|
||||
binding.padPc.refreshCallBack = {
|
||||
val pcStr = binding.padPc.value
|
||||
record.pc = pcStr.toLongOrNull() ?: 0L
|
||||
}
|
||||
// 移除旧的监听器
|
||||
pcTextWatcher?.let { binding.etPc.removeTextChangedListener(it) }
|
||||
weightTextWatcher?.let { binding.etWeight.removeTextChangedListener(it) }
|
||||
|
||||
binding.padWeight.refreshCallBack = {
|
||||
val weightStr = binding.padWeight.value
|
||||
record.weight = weightStr.toDoubleOrNull() ?: 0.0
|
||||
// 在编辑模式下监听EditText输入
|
||||
if (isEditMode) {
|
||||
pcTextWatcher = 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?) {
|
||||
record.pc = s?.toString()?.toLongOrNull() ?: 0L
|
||||
}
|
||||
}
|
||||
binding.etPc.addTextChangedListener(pcTextWatcher)
|
||||
|
||||
weightTextWatcher = 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?) {
|
||||
record.weight = s?.toString()?.toDoubleOrNull() ?: 0.0
|
||||
}
|
||||
}
|
||||
binding.etWeight.addTextChangedListener(weightTextWatcher)
|
||||
}
|
||||
|
||||
binding.executePendingBindings()
|
||||
|
||||
Reference in New Issue
Block a user