添加init界面,调整了认证后逻辑,调整了扫描枪扫描处理
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package com.sw.platecabinet.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.text.Editable
|
||||
import android.text.TextUtils
|
||||
import android.text.TextWatcher
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
import com.sw.plate.utils.comn.SerialApi
|
||||
import com.sw.plate.utils.comn.SerialPortManager
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.activity.MainActivity
|
||||
import com.sw.platecabinet.activity.PageType
|
||||
@@ -23,6 +24,7 @@ import com.sw.platecabinet.ext.maskName
|
||||
import com.sw.platecabinet.ext.maskPhone
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.model.response.SearchResult
|
||||
import com.sw.platecabinet.utils.Debouncer
|
||||
import com.sw.platecabinet.utils.KeyboardUtils
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -39,6 +41,7 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
private var info: EquipmentUserInfo? = null
|
||||
private var checkedItem: SearchResult.Member? = null
|
||||
private var lastText = ""
|
||||
private val debouncer = Debouncer(2000)
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@@ -94,21 +97,25 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
}
|
||||
})
|
||||
(activity as MainActivity).registerKeyEventInfo {
|
||||
binding.etCode.text = Editable.Factory.getInstance().newEditable(it)
|
||||
if (binding.etUserInfo.isFocused) return@registerKeyEventInfo
|
||||
binding.etCode.text.clear()
|
||||
binding.etCode.postDelayed({
|
||||
binding.etCode.text.clear()
|
||||
binding.etCode.text = Editable.Factory.getInstance().newEditable(it)
|
||||
binding.etUserInfo.requestFocus()
|
||||
}, 50)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initListener() {
|
||||
binding.etUserInfo.addTextChangedListener(object : TextWatcher {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val debounceDelay = 500L // 延迟 500 毫秒
|
||||
|
||||
binding.etCode.addTextChangedListener(object : TextWatcher {
|
||||
override fun beforeTextChanged(
|
||||
s: CharSequence?,
|
||||
start: Int,
|
||||
count: Int,
|
||||
after: Int
|
||||
) {
|
||||
Timber.d("beforeTextChanged s = ${s.toString()}, start = $start, count = $count, after = $after")
|
||||
}
|
||||
|
||||
override fun onTextChanged(
|
||||
@@ -117,20 +124,32 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
before: Int,
|
||||
count: Int
|
||||
) {
|
||||
Timber.d("onTextChanged s = ${s.toString()}, start = $start, count = $count, before = $before")
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
val currentText = s.toString()
|
||||
if (currentText == lastText) return // 内容未变化时不处理
|
||||
lastText = currentText
|
||||
handler.removeCallbacksAndMessages(null) // 取消之前的延迟任务
|
||||
handler.postDelayed({
|
||||
// if (currentText.isNotEmpty()) {
|
||||
viewModel.getSearchMemberList(param = currentText, pageNum = 1)
|
||||
// }
|
||||
}, debounceDelay)
|
||||
Timber.d("afterTextChanged s = ${s.toString()}")
|
||||
}
|
||||
})
|
||||
binding.etUserInfo.setOnEditorActionListener { _, actionId, keyEvent ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
val currentText = binding.etUserInfo.text.toString()
|
||||
val containsNewlines = currentText.contains('\n') || currentText.contains('\r')
|
||||
if (containsNewlines) {
|
||||
Timber.d("非用户主动搜索")
|
||||
true
|
||||
}
|
||||
debouncer.debounce {
|
||||
// 执行搜索操作
|
||||
viewModel.getSearchMemberList(param = currentText, pageNum = 1)
|
||||
// 隐藏键盘
|
||||
KeyboardUtils.hideKeyboard(requireActivity())
|
||||
}
|
||||
true // 表示已处理该事件
|
||||
} else {
|
||||
false // 未处理其他动作
|
||||
}
|
||||
}
|
||||
binding.llBind.setOnClickListener {
|
||||
if (info == null || info!!.equipmentCode?.isEmpty() == true || info!!.equipmentBoxCode?.isEmpty() == true) {
|
||||
ToastUtils.showToast("传入的设备信息异常")
|
||||
@@ -176,15 +195,29 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
||||
if (it.first == null) return@collect // 解绑状态过滤
|
||||
val errorInfo = it.second
|
||||
if (errorInfo.isSuccess()) {
|
||||
if (errorInfo.equipmentUserInfo?.isOtherEquipment() == true) {
|
||||
if (errorInfo.equipmentUserInfo == null) {
|
||||
ToastUtils.showToast("数据异常")
|
||||
return@collect
|
||||
}
|
||||
if (errorInfo.equipmentUserInfo.isOtherEquipment() == true) {
|
||||
MainActivity.start(
|
||||
requireContext(),
|
||||
pageType = PageType.PLATE_TIP,
|
||||
equipmentUserInfo = errorInfo.equipmentUserInfo
|
||||
)
|
||||
} else {
|
||||
ToastUtils.showToast("绑定成功")
|
||||
activity?.finish()
|
||||
SerialApi.openPlate(
|
||||
errorInfo.equipmentUserInfo.equipmentBoxCode!!.toInt(),
|
||||
object : SerialPortManager.SendCallback {
|
||||
override fun onSuccess() {
|
||||
ToastUtils.showToast("绑定成功")
|
||||
activity?.finish()
|
||||
}
|
||||
|
||||
override fun onFail(e: Exception?) {
|
||||
ToastUtils.showToast("绑定失败")
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showToast(errorInfo.msg)
|
||||
|
||||
Reference in New Issue
Block a user