fix(main): 修复菜品切换和重量计算相关问题

- 移除未使用的LinearLayoutManager和FoodOrderAdapter导入
- 添加isSwitchFood标志用于菜品切换时重置数据
- 优化resetSelectedFood方法,根据用户状态决定是否重新打开识别功能
- 将currentWeight修改为public访问权限
- 在重量变化时添加判断避免重复更新
- 注释掉不需要的重量更新调用
- 在菜品识别完成时添加重量更新
- 在清空选中项目时重置isSwitchFood标志
- 优化updateWeight方法中的逻辑判断
- 将倒计时重置任务提取为单独方法
- 添加switchFood逻辑控制,避免重复人脸识别
- 修复余量计量模式下的最后餐品处理逻辑
This commit is contained in:
2026-04-10 16:03:27 +08:00
parent e5b682f021
commit d378cdcf97
2 changed files with 70 additions and 85 deletions
@@ -24,11 +24,9 @@ import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.core.content.ContextCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.common.util.concurrent.ListenableFuture
import com.sw.dualscreen.GlobalData
import com.sw.dualscreen.GlobalKey
import com.sw.dualscreen.adapter.FoodOrderAdapter
import com.sw.dualscreen.adapter.MainFoodListAdapter
import com.sw.dualscreen.databinding.ActivityMainBinding
import com.sw.dualscreen.dialog.EnvSwitchDialog
@@ -130,17 +128,27 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
}
}
}
var isSwitchFood = false
/**
* 用于切换菜品时重置数据
*/
fun resetSelectedFood(foodInfo: FoodInfo) {
isSwitchFood = true
recognizeViewModel.resetFaceState()
updateCurrentFood(foodInfo)
if (settlementMode == 0) {
//联合支付,切换菜品重新请求接口
presentation?.let {
it.pauseCamera()
it.step2FaceRecognizing(foodInfo, true)
val userId = presentation?.currentUserId
if(userId.isNullOrBlank()) {
//切换菜品时,用户已离开重新打开识别功能
it.pauseCamera()
it.step2FaceRecognizing(foodInfo, true)
} else{
//切换菜品时,用户未离开,重新请求接口
it.step3ShowRecognizeResult(userId)
}
}
// presentation?.step3ShowRecognizeResult(presentation!!.currentUserId?:"")
} else {
//0-计费,1-不计费
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
@@ -158,7 +166,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
private var canIdentify: Boolean = false
private var bottomSheetDialog: CustomBottomSheetDialog? = null
private var lastWeight: Int = 0
private var currentWeight: Int = 0
var currentWeight: Int = 0
private var lastPhotoUri: Uri? = null // 最后拍照的图片
private var debouncer = Debouncer(2000)
private var isRecognitionFood = true
@@ -360,9 +368,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
//余量计量+联合支付人脸查询订单完成
if (presentation!!.jointPaymentQueryFinish) {
log("registerDataChange weight 联合支付-余量计量,updateWeight")
presentation?.updateWeight(weight)
log("registerDataChange weight 重置lastWeight与weigh${weight}一致----------------1000006")
lastWeight = weight
if (lastWeight != weight) {
presentation?.updateWeight(weight)
log("registerDataChange weight 重置lastWeight与weigh${weight}一致----------------1000006")
lastWeight = weight
}
return
}
val isWeightChange = weight - lastWeight > WEIGHT_CHANGE_VALUE
@@ -443,7 +453,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
val payTypeDesc = if (settlementMode == 0) "联合支付" else "独立支付"
log("registerDataChange weight readWeight-${payTypeDesc},weight=$weight,lastWeight=$lastWeight,isWeightChange=$isWeightChange")
}
presentation?.updateWeight(weight)
// presentation?.updateWeight(weight)
if (weight <= WEIGHT_RESET_RECOGNIZE) {
log("registerDataChange weight recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}")
@@ -540,6 +550,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
foodRecognizeState = true
//查询到菜品信息,同步设置lastWeight=currentWeight
lastWeight=currentWeight
presentation?.updateWeight(currentWeight)
list.forEach { foodInfo ->
val scoreItem = scoreList.firstOrNull { it.name == foodInfo.foodName }
val score = scoreItem?.score ?: 0.0
@@ -749,6 +761,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
checkedItem = null
lastWeight = 0
foodRecognizeState = true
isSwitchFood = false
}
private fun updateDateTime() {