fix(weight): 修复称重逻辑和支付模式相关问题
- 将 WEIGHT_CHANGE_VALUE 从 25 修改为 20 - 添加 currentWeight 变量用于准确记录当前称重值 - 临时修改 settlementMode 为独立支付模式用于测试 - 更新日志输出以更好地跟踪称重变化 - 修复即放即取和余量计量模式下的称重处理逻辑 - 添加食物识别状态控制变量 foodRecognizeState - 在不同模式下正确设置 eatWeight 和 foodWeight 计算方式 - 优化余量计量模式下的状态重置逻辑 - 添加倒计时功能用于余量计量模式状态重置 - 修复营养计算相关的日志输出格式
This commit is contained in:
@@ -43,6 +43,7 @@ import com.sw.dualscreen.model.response.UserEnergy
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.utils.Debouncer
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
import com.sw.dualscreen.utils.countDownByFlow
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import com.sw.plate.utils.LightManager
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
@@ -59,6 +60,7 @@ import com.sw.plate.utils.arcface.face.model.CompareResult
|
||||
import com.sw.plate.utils.arcface.face.model.FacePreviewInfo
|
||||
import com.sw.plate.utils.arcface.face.model.RecognizeConfiguration
|
||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
@@ -75,7 +77,7 @@ class MainScreenPresentation(
|
||||
) : Presentation(activity, display), ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
companion object {
|
||||
const val TAG = "SubScreenPresentation"
|
||||
const val TAG = "MainScreenPresentation"
|
||||
}
|
||||
|
||||
private lateinit var binding: PresentationMainScreenBinding
|
||||
@@ -144,55 +146,55 @@ class MainScreenPresentation(
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
//0-计费,1-不计费
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
// if (mealPickupMode == 1 && chargeMode == 0) {
|
||||
// //余量计量+计费模式
|
||||
// if (isFirstGetWeight && lastWeight > 5) {
|
||||
// recognitionWeight = lastWeight
|
||||
// isFirstGetWeight = false
|
||||
// }
|
||||
// if (lastWeight > 5) {
|
||||
// //余量计量,有重量的情况下不回到重新识别状态
|
||||
// return
|
||||
// }
|
||||
// isFirstGetWeight = true
|
||||
// }
|
||||
if (currentStep == 2 && lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE && isGoStep1) {
|
||||
//人脸识别过程中,秤上物品拿走
|
||||
isGoStep1 = false
|
||||
activity.runOnUiThread {
|
||||
Timber.tag(TAG).e("切回step1")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000000")
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
} else if (lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||
isGoStep1 = false
|
||||
activity.runOnUiThread {
|
||||
Timber.tag(TAG).e("切回step1")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000001")
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
step1FoodRecognizing()
|
||||
} else {
|
||||
//秤上菜品不足,请补充
|
||||
if (currentStep == 1 && currentFood == null) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
//余量计量
|
||||
if (countDownResetJob == null) {
|
||||
countDownResetJob = countDownByFlow(
|
||||
total = 30,
|
||||
scope = activity.lifecycleScope,
|
||||
onStart = {},
|
||||
onTick = { seconds ->
|
||||
Timber.tag(TAG).e("余量计量模型秤重量已清空,等待${seconds}秒后继续重置识别状态")
|
||||
if (lastWeight > MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||
countDownResetJob?.cancel()
|
||||
}
|
||||
},
|
||||
onFinish = {
|
||||
step1FoodRecognizing()
|
||||
countDownResetJob?.cancel()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (currentStep != 3) {
|
||||
// return
|
||||
// }
|
||||
if (currentFood == null) {
|
||||
Timber.tag(TAG).e("updateWeight currentFood is null")
|
||||
return
|
||||
}
|
||||
|
||||
//if (userNutritionData == null) {
|
||||
if (userNutrition == null) {
|
||||
Timber.tag(TAG).e("updateWeight userNutritionData is null")
|
||||
return
|
||||
}
|
||||
// if (dinnerTypeInfo == null) {
|
||||
// Timber.tag(TAG).e("updateWeight dinnerType is null")
|
||||
// return
|
||||
// }
|
||||
if (chargeMode == 1 || activity.settlementMode == 0) {
|
||||
//不计费或者联合支付模式更新营养热量数据
|
||||
if (mealPickupMode == 0) {
|
||||
@@ -205,6 +207,8 @@ class MainScreenPresentation(
|
||||
}
|
||||
}
|
||||
|
||||
private var countDownResetJob: Job? = null
|
||||
|
||||
fun setStepChangeCallback(callback: (Int) -> Unit) {
|
||||
stepChangeCallback = callback
|
||||
}
|
||||
@@ -518,7 +522,7 @@ class MainScreenPresentation(
|
||||
* 餐品识别中
|
||||
*/
|
||||
fun step1FoodRecognizing() {
|
||||
if (currentStep == 1) {
|
||||
if (currentStep == 1 && currentFood == null) {
|
||||
return
|
||||
}
|
||||
Timber.tag(TAG).d("main,step1,耗时:${System.currentTimeMillis() - startTime}")
|
||||
@@ -764,10 +768,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
|
||||
private fun calculateNutrition(value: Int) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"addFoodToOrder: weight = $value, recognitionWeight = $recognitionWeight foodInfo = $currentFood"
|
||||
)
|
||||
Timber.tag(TAG) .d("calculateNutrition:weight=$value,recognitionWeight=$recognitionWeight,foodInfo=$currentFood")
|
||||
if (currentFood == null || userNutrition == null) {
|
||||
return
|
||||
}
|
||||
@@ -906,6 +907,7 @@ class MainScreenPresentation(
|
||||
*/
|
||||
fun updateMealPickupMode(mode: Int) {
|
||||
Timber.tag(TAG).d("updateMealPickupMode mode = $mode")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000003")
|
||||
mealPickupMode = mode
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
@@ -1359,6 +1361,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
} else {
|
||||
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step1FoodRecognizing")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000002")
|
||||
activity.isAnalyzing = false
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user