优化不足一份的识别问题

This commit is contained in:
2026-01-09 11:59:24 +08:00
parent a79f7db867
commit a0452e985a
2 changed files with 41 additions and 21 deletions
@@ -336,6 +336,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
if (isPageVisible.not() || isStartRecognize.not()) {
if (ActivityManager.currentActivity() is MainActivity) {
isPageVisible = true
isStartRecognize = true
}
return@addWeightListener
}
@@ -765,18 +766,24 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
eatWeight: Int,
eatNum: Int,
userId: String?,
notEnoughOneBlock: ()-> Unit = {},
block: () -> Unit
) {
Timber.tag(TAG).d("foodWeight=$foodWeight,eatWeight=$eatWeight")
val pickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
if (pickupMode == 0) {
if (foodWeight <= 5 || eatWeight <= 5) {
ToastUtils.showToast("请取走餐品")
if (foodWeight <= 5) {
ToastUtils.showToast("餐品重量不足")
return
}
if (eatWeight <= 5) {
ToastUtils.showToast("取餐重量过小")
return
}
}
if (eatNum == 0) {
ToastUtils.showToast("您好,当前重量不足一份")
notEnoughOneBlock()
return
}
showWaitingDialog("加载中,请稍候……")
@@ -109,7 +109,8 @@ class MainScreenPresentation(
private var lastFaceTrackId: Int = -1 // 上一次的人脸信息
var mealPickupMode: Int = 0 // 取餐模式 0 即放即取 1 余量取餐
var isKeepFaceState = true
// var isKeepFaceState = true
var isKeepFaceState = false
var currentUserId: String? = null
@@ -986,6 +987,9 @@ class MainScreenPresentation(
if (facePreviewInfoList != null && rgbFaceRectTransformer != null) {
drawPreviewInfo(facePreviewInfoList!!)
}
if (facePreviewInfoList.isNullOrEmpty()) {
currentUserId = null
}
//recognizeViewModel.clearLeftFace(facePreviewInfoList)
clearLeftFaceData()
}
@@ -1154,23 +1158,31 @@ class MainScreenPresentation(
if (userNutrition == null || currentFood == null || currentUserId == null) {
return
}
postUserData()
if (mealPickupMode == 1 || isKeepFaceState) {
step2FaceRecognizing(currentFood!!)
isKeepFaceState = false
} else {
activity.isAnalyzing = false
step1FoodRecognizing()
createOrder(notEnoughOneBlock = {
if (mealPickupMode == 0) {
currentStep = 2
step2FaceRecognizing(currentFood!!)
}
}){
if (MyApp.DEBUG) {
ToastUtils.showToast("订单已生成")
}
currentUserId = null
//ToastUtils.showToast("isKeepFaceState=$isKeepFaceState,mealPickupMode=$mealPickupMode")
//|| isKeepFaceState
if (mealPickupMode == 1) {
step2FaceRecognizing(currentFood!!)
isKeepFaceState = false
} else {
activity.isAnalyzing = false
step1FoodRecognizing()
}
}
}
}
}
fun postUserData() {
createOrder()
}
fun createOrder() {
fun createOrder(notEnoughOneBlock: ()-> Unit={}, block: ()-> Unit) {
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
val eatWeight = if (mealPickupMode == 0) {
//即放即取
@@ -1192,13 +1204,14 @@ class MainScreenPresentation(
foodWeight = lastWeight.roundToInt(),
eatWeight = eatWeight.roundToInt(),
eatNum = activity.getEatNum(eatWeight, currentFood!!.specWeight),
userId = currentUserId
) {
if (MyApp.DEBUG) {
ToastUtils.showToast("订单已生成")
userId = currentUserId,
notEnoughOneBlock = notEnoughOneBlock,
block = {
activity.runOnUiThread {
block()
}
}
currentUserId = null
}
)
}
private fun clearLeftFaceData() {