feat(face): 人脸库为空时自动进入新用户采集模式
- 新增 newUserCollect() 方法,人脸数据库记录为零时自动显示采集界面 - onResume 中异步查询人脸数量,据此决定进入采集模式或正常识别模式 - 修复 isFirstOpen 依赖 1000ms 延迟的竞态问题,改为立即置 false - 顺带修改 FunActivity 按钮文案为「清除并拉取全量数据」 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,7 @@ import com.sw.platecabinet.utils.SoundPoolUtil
|
|||||||
import com.sw.platecabinet.utils.SpTool
|
import com.sw.platecabinet.utils.SpTool
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
@@ -348,6 +349,20 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
binding.ivCollectPhoto.visible()
|
binding.ivCollectPhoto.visible()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun newUserCollect() {
|
||||||
|
recognizeCountDownUtil.cancelCountDown()
|
||||||
|
binding.tvToInit.text = ""
|
||||||
|
binding.tvSimilarValue.text = ""
|
||||||
|
binding.llCollectButton.visible()
|
||||||
|
binding.btnRetry.gone()
|
||||||
|
binding.btnCollect.run {
|
||||||
|
visible()
|
||||||
|
text = "新用户采集"
|
||||||
|
}
|
||||||
|
binding.ivCollectPhoto.gone()
|
||||||
|
resumeCamera()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询餐盘数据
|
* 查询餐盘数据
|
||||||
*/
|
*/
|
||||||
@@ -674,13 +689,24 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
try {
|
try {
|
||||||
if (isFirstOpen) {
|
if (isFirstOpen) {
|
||||||
|
isFirstOpen = false
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
binding.root.postDelayed({
|
|
||||||
isFirstOpen = false
|
|
||||||
}, 1000)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resetRecognizeState()
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
try {
|
||||||
|
val faceDao = FaceDatabase.getInstance(this@LoginByFaceActivity).faceDao()
|
||||||
|
val faceCount = withContext(Dispatchers.IO) { faceDao.faceCount }
|
||||||
|
if (faceCount == 0) {
|
||||||
|
newUserCollect()
|
||||||
|
} else {
|
||||||
|
resetRecognizeState()
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
android:layout_marginHorizontal="50dp"
|
android:layout_marginHorizontal="50dp"
|
||||||
android:paddingHorizontal="30dp"
|
android:paddingHorizontal="30dp"
|
||||||
android:background="@drawable/btn_outline"
|
android:background="@drawable/btn_outline"
|
||||||
android:text="清除并重新拉取数据"
|
android:text="清除并拉取全量数据"
|
||||||
android:textColor="#FFCC99" />
|
android:textColor="#FFCC99" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
|||||||
Reference in New Issue
Block a user