From a0452e985aea01a4f6a72481b05d066d46c922aa Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Fri, 9 Jan 2026 11:59:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8D=E8=B6=B3=E4=B8=80?= =?UTF-8?q?=E4=BB=BD=E7=9A=84=E8=AF=86=E5=88=AB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sw/dualscreen/activity/MainActivity.kt | 11 +++- .../presentation/MainScreenPresentation.kt | 51 ++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt index 5602e18..722d403 100644 --- a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt +++ b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt @@ -336,6 +336,7 @@ class MainActivity : BaseActivity() { if (isPageVisible.not() || isStartRecognize.not()) { if (ActivityManager.currentActivity() is MainActivity) { isPageVisible = true + isStartRecognize = true } return@addWeightListener } @@ -765,18 +766,24 @@ class MainActivity : BaseActivity() { 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("加载中,请稍候……") diff --git a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt index 6c5aa3f..a7a0e3d 100644 --- a/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt +++ b/app/src/main/java/com/sw/dualscreen/presentation/MainScreenPresentation.kt @@ -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() {