代码优化

This commit is contained in:
2026-03-06 15:30:25 +08:00
parent 6d8ca7c83f
commit f99538890c
@@ -167,7 +167,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
private val livenessType = LivenessType.RGB
private var openRectInfoDraw = false
private val leftDebouncer = Debouncer(30*1000)
private val leftDebouncer = Debouncer(30 * 1000)
private var registerHandler: RegisterCallbackHandler? = null
@@ -396,6 +396,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
SpTool.savePlateData(items)
}
}
private val openDebouncer by lazy { Debouncer(5000) }
private fun initArcView() {
@@ -407,10 +408,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
override fun onDestroy() {
loadLogInfo("onDestroy")
if (rgbCameraHelper != null) {
rgbCameraHelper?.release()
rgbCameraHelper = null
}
rgbCameraHelper?.release()
rgbCameraHelper = null
recognizeViewModel.destroy()
@@ -605,10 +604,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
}
}
fun openRectInfoDraw(view: View?) {
openRectInfoDraw = !openRectInfoDraw
recognizeViewModel.setDrawRectInfoTextValue(openRectInfoDraw)
}
// fun openRectInfoDraw(view: View?) {
// openRectInfoDraw = !openRectInfoDraw
// recognizeViewModel.setDrawRectInfoTextValue(openRectInfoDraw)
// }
override fun onGlobalLayout() {
@@ -623,7 +622,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
loadLogInfo("collectFace,resumeCamera: ")
isRecognition = true
rgbCameraHelper?.start()
rgbCameraHelper!!.start()
} else {
//recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
@@ -662,7 +661,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
private val emptyFrame = createBlackNV21Frame(1280, 720)
// 传递“空帧” recognizeViewModel.onPreviewFrame(emptyFrame, true)
// /**
// /**
// * 临时用户id
// */
// private var tempUserId: String = ""
@@ -736,7 +735,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
private fun judgeRecognizeState(): Boolean {
val rectColor = binding.dualCameraFaceRectView.rectColor
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank().not() && facePreviewInfoList.isNullOrEmpty().not()) {
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
.not() && facePreviewInfoList.isNullOrEmpty().not()
) {
//人未离开,再次识别
loadLogInfo("userId=$currentUserId")
openPlateDebouncer.debounce {
@@ -801,9 +802,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
return@addUserFace
}
lifecycleScope.launch(Dispatchers.IO) {
saveFaceInfo(faceModel) {
saveFaceInfo(faceModel) {
runOnUiThread {
Glide.with(this@LoginByFaceActivity).load(imageFile).into(binding.ivCollectPhoto)
Glide.with(this@LoginByFaceActivity).load(imageFile)
.into(binding.ivCollectPhoto)
}
}
uploadFaceDebouncer.reset()
@@ -891,12 +893,11 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
return@startCountDown
}
}, onFinish = {
CountDownUtil.cancelCountDown()
if (facePreviewInfoList.isNullOrEmpty().not()) {
loadLogInfo("leftCountDown.onFinish-cancel()")
CountDownUtil.cancelCountDown()
return@startCountDown
}
CountDownUtil.cancelCountDown()
goInitActivity()
})
}