feat: ui opt

This commit is contained in:
2025-11-27 11:28:50 +08:00
parent 7e80d0e789
commit bea8a8c8c8
5 changed files with 236 additions and 277 deletions

View File

@@ -1,7 +1,5 @@
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
@@ -14,8 +12,6 @@ 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
@@ -26,32 +22,6 @@ class GjcCheckInRecordViewHolder(view: View) :
binding.record = record
binding.isEditMode = isEditMode
binding.position = position // 传入位置用于显示序号
// 移除旧的监听器
pcTextWatcher?.let { binding.etPc.removeTextChangedListener(it) }
weightTextWatcher?.let { binding.etWeight.removeTextChangedListener(it) }
// 在编辑模式下监听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()
}
}