fix(main): 修复菜品切换和重量计算相关问题
- 移除未使用的LinearLayoutManager和FoodOrderAdapter导入 - 添加isSwitchFood标志用于菜品切换时重置数据 - 优化resetSelectedFood方法,根据用户状态决定是否重新打开识别功能 - 将currentWeight修改为public访问权限 - 在重量变化时添加判断避免重复更新 - 注释掉不需要的重量更新调用 - 在菜品识别完成时添加重量更新 - 在清空选中项目时重置isSwitchFood标志 - 优化updateWeight方法中的逻辑判断 - 将倒计时重置任务提取为单独方法 - 添加switchFood逻辑控制,避免重复人脸识别 - 修复余量计量模式下的最后餐品处理逻辑
This commit is contained in:
@@ -24,11 +24,9 @@ import androidx.camera.lifecycle.ProcessCameraProvider
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
import com.sw.dualscreen.GlobalData
|
import com.sw.dualscreen.GlobalData
|
||||||
import com.sw.dualscreen.GlobalKey
|
import com.sw.dualscreen.GlobalKey
|
||||||
import com.sw.dualscreen.adapter.FoodOrderAdapter
|
|
||||||
import com.sw.dualscreen.adapter.MainFoodListAdapter
|
import com.sw.dualscreen.adapter.MainFoodListAdapter
|
||||||
import com.sw.dualscreen.databinding.ActivityMainBinding
|
import com.sw.dualscreen.databinding.ActivityMainBinding
|
||||||
import com.sw.dualscreen.dialog.EnvSwitchDialog
|
import com.sw.dualscreen.dialog.EnvSwitchDialog
|
||||||
@@ -130,17 +128,27 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var isSwitchFood = false
|
||||||
|
/**
|
||||||
|
* 用于切换菜品时重置数据
|
||||||
|
*/
|
||||||
fun resetSelectedFood(foodInfo: FoodInfo) {
|
fun resetSelectedFood(foodInfo: FoodInfo) {
|
||||||
|
isSwitchFood = true
|
||||||
recognizeViewModel.resetFaceState()
|
recognizeViewModel.resetFaceState()
|
||||||
updateCurrentFood(foodInfo)
|
updateCurrentFood(foodInfo)
|
||||||
if (settlementMode == 0) {
|
if (settlementMode == 0) {
|
||||||
//联合支付,切换菜品重新请求接口
|
//联合支付,切换菜品重新请求接口
|
||||||
presentation?.let {
|
presentation?.let {
|
||||||
|
val userId = presentation?.currentUserId
|
||||||
|
if(userId.isNullOrBlank()) {
|
||||||
|
//切换菜品时,用户已离开重新打开识别功能
|
||||||
it.pauseCamera()
|
it.pauseCamera()
|
||||||
it.step2FaceRecognizing(foodInfo, true)
|
it.step2FaceRecognizing(foodInfo, true)
|
||||||
|
} else{
|
||||||
|
//切换菜品时,用户未离开,重新请求接口
|
||||||
|
it.step3ShowRecognizeResult(userId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// presentation?.step3ShowRecognizeResult(presentation!!.currentUserId?:"")
|
|
||||||
} else {
|
} else {
|
||||||
//0-计费,1-不计费
|
//0-计费,1-不计费
|
||||||
val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
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 canIdentify: Boolean = false
|
||||||
private var bottomSheetDialog: CustomBottomSheetDialog? = null
|
private var bottomSheetDialog: CustomBottomSheetDialog? = null
|
||||||
private var lastWeight: Int = 0
|
private var lastWeight: Int = 0
|
||||||
private var currentWeight: Int = 0
|
var currentWeight: Int = 0
|
||||||
private var lastPhotoUri: Uri? = null // 最后拍照的图片
|
private var lastPhotoUri: Uri? = null // 最后拍照的图片
|
||||||
private var debouncer = Debouncer(2000)
|
private var debouncer = Debouncer(2000)
|
||||||
private var isRecognitionFood = true
|
private var isRecognitionFood = true
|
||||||
@@ -360,9 +368,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
//余量计量+联合支付人脸查询订单完成
|
//余量计量+联合支付人脸查询订单完成
|
||||||
if (presentation!!.jointPaymentQueryFinish) {
|
if (presentation!!.jointPaymentQueryFinish) {
|
||||||
log("registerDataChange weight 联合支付-余量计量,updateWeight")
|
log("registerDataChange weight 联合支付-余量计量,updateWeight")
|
||||||
|
if (lastWeight != weight) {
|
||||||
presentation?.updateWeight(weight)
|
presentation?.updateWeight(weight)
|
||||||
log("registerDataChange weight 重置lastWeight与weigh:${weight}一致----------------1000006")
|
log("registerDataChange weight 重置lastWeight与weigh:${weight}一致----------------1000006")
|
||||||
lastWeight = weight
|
lastWeight = weight
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val isWeightChange = weight - lastWeight > WEIGHT_CHANGE_VALUE
|
val isWeightChange = weight - lastWeight > WEIGHT_CHANGE_VALUE
|
||||||
@@ -443,7 +453,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
val payTypeDesc = if (settlementMode == 0) "联合支付" else "独立支付"
|
val payTypeDesc = if (settlementMode == 0) "联合支付" else "独立支付"
|
||||||
log("registerDataChange weight readWeight-${payTypeDesc},weight=$weight,lastWeight=$lastWeight,isWeightChange=$isWeightChange")
|
log("registerDataChange weight readWeight-${payTypeDesc},weight=$weight,lastWeight=$lastWeight,isWeightChange=$isWeightChange")
|
||||||
}
|
}
|
||||||
presentation?.updateWeight(weight)
|
// presentation?.updateWeight(weight)
|
||||||
|
|
||||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||||
log("registerDataChange weight recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}克")
|
log("registerDataChange weight recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}克")
|
||||||
@@ -540,6 +550,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
foodRecognizeState = true
|
foodRecognizeState = true
|
||||||
//查询到菜品信息,同步设置lastWeight=currentWeight
|
//查询到菜品信息,同步设置lastWeight=currentWeight
|
||||||
lastWeight=currentWeight
|
lastWeight=currentWeight
|
||||||
|
presentation?.updateWeight(currentWeight)
|
||||||
|
|
||||||
list.forEach { foodInfo ->
|
list.forEach { foodInfo ->
|
||||||
val scoreItem = scoreList.firstOrNull { it.name == foodInfo.foodName }
|
val scoreItem = scoreList.firstOrNull { it.name == foodInfo.foodName }
|
||||||
val score = scoreItem?.score ?: 0.0
|
val score = scoreItem?.score ?: 0.0
|
||||||
@@ -749,6 +761,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
checkedItem = null
|
checkedItem = null
|
||||||
lastWeight = 0
|
lastWeight = 0
|
||||||
foodRecognizeState = true
|
foodRecognizeState = true
|
||||||
|
isSwitchFood = false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDateTime() {
|
private fun updateDateTime() {
|
||||||
|
|||||||
@@ -139,21 +139,20 @@ class MainScreenPresentation(
|
|||||||
private var isFirstGetWeight = true
|
private var isFirstGetWeight = true
|
||||||
|
|
||||||
fun updateWeight(weight: Int) {
|
fun updateWeight(weight: Int) {
|
||||||
lastWeight = weight
|
|
||||||
Timber.tag(TAG)
|
Timber.tag(TAG)
|
||||||
.d("updateWeight lastWeight = $weight, currentStep = $currentStep, isGoStep1 = $isGoStep1")
|
.d("updateWeight weight = $weight, currentStep = $currentStep, isGoStep1 = $isGoStep1")
|
||||||
//0-即放即取,1-余量计量
|
//0-即放即取,1-余量计量
|
||||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||||
//0-计费,1-不计费
|
//0-计费,1-不计费
|
||||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||||
if (currentStep == 2 && lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE && isGoStep1) {
|
if (currentStep == 2 && weight <= MainActivity.WEIGHT_RESET_RECOGNIZE && isGoStep1) {
|
||||||
//人脸识别过程中,秤上物品拿走
|
//人脸识别过程中,秤上物品拿走
|
||||||
isGoStep1 = false
|
isGoStep1 = false
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
Timber.tag(TAG).e("切回step1,------2000000000000")
|
Timber.tag(TAG).e("切回step1,------2000000000000")
|
||||||
step1FoodRecognizing()
|
step1FoodRecognizing()
|
||||||
}
|
}
|
||||||
} else if (lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
} else if (weight <= MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||||
isGoStep1 = false
|
isGoStep1 = false
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
Timber.tag(TAG).e("切回step1,------2000000000001")
|
Timber.tag(TAG).e("切回step1,------2000000000001")
|
||||||
@@ -165,25 +164,7 @@ class MainScreenPresentation(
|
|||||||
return@runOnUiThread
|
return@runOnUiThread
|
||||||
}
|
}
|
||||||
//余量计量
|
//余量计量
|
||||||
if (countDownResetJob == null || countDownResetJob?.isActive == false) {
|
initCountDownResetJob(weight)
|
||||||
countDownResetJob = countDownByFlow(
|
|
||||||
total = 30,
|
|
||||||
scope = activity.lifecycleScope,
|
|
||||||
onStart = {},
|
|
||||||
onTick = { seconds ->
|
|
||||||
Timber.tag(TAG).e("余量计量模型秤重量已清空,等待${seconds}秒后继续重置识别状态")
|
|
||||||
if (lastWeight > MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
|
||||||
countDownResetJob?.cancel()
|
|
||||||
countDownResetJob = null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onFinish = {
|
|
||||||
step1FoodRecognizing()
|
|
||||||
countDownResetJob?.cancel()
|
|
||||||
countDownResetJob = null
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,16 +182,39 @@ class MainScreenPresentation(
|
|||||||
//不计费或者联合支付模式更新营养热量数据
|
//不计费或者联合支付模式更新营养热量数据
|
||||||
if (mealPickupMode == 0) {
|
if (mealPickupMode == 0) {
|
||||||
//即放即取
|
//即放即取
|
||||||
calculateNutrition(lastWeight)
|
calculateNutrition(weight)
|
||||||
} else {
|
} else {
|
||||||
//余量计量
|
//余量计量
|
||||||
calculateNutrition(recognitionWeight - lastWeight)
|
calculateNutrition(recognitionWeight - weight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lastWeight = weight
|
||||||
}
|
}
|
||||||
|
|
||||||
private var countDownResetJob: Job? = null
|
private var countDownResetJob: Job? = null
|
||||||
|
|
||||||
|
private fun initCountDownResetJob(weight: Int) {
|
||||||
|
if (countDownResetJob == null || countDownResetJob?.isActive == false) {
|
||||||
|
countDownResetJob = countDownByFlow(
|
||||||
|
total = 30,
|
||||||
|
scope = activity.lifecycleScope,
|
||||||
|
onStart = {},
|
||||||
|
onTick = { seconds ->
|
||||||
|
Timber.tag(TAG).e("余量计量模型秤重量已清空,等待${seconds}秒后继续重置识别状态")
|
||||||
|
if (weight > MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||||
|
countDownResetJob?.cancel()
|
||||||
|
countDownResetJob = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onFinish = {
|
||||||
|
step1FoodRecognizing()
|
||||||
|
countDownResetJob?.cancel()
|
||||||
|
countDownResetJob = null
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setStepChangeCallback(callback: (Int) -> Unit) {
|
fun setStepChangeCallback(callback: (Int) -> Unit) {
|
||||||
stepChangeCallback = callback
|
stepChangeCallback = callback
|
||||||
}
|
}
|
||||||
@@ -321,10 +325,11 @@ class MainScreenPresentation(
|
|||||||
loadUserNutritionData(userId)
|
loadUserNutritionData(userId)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//独立支队
|
//独立支付
|
||||||
loadUserNutritionData(userId)
|
loadUserNutritionData(userId)
|
||||||
}
|
}
|
||||||
step3Debouncer.reset()
|
step3Debouncer.reset()
|
||||||
|
activity.isSwitchFood = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -455,23 +460,11 @@ class MainScreenPresentation(
|
|||||||
/**
|
/**
|
||||||
* 餐品识别成功,不计费模式
|
* 餐品识别成功,不计费模式
|
||||||
*/
|
*/
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
fun loadUnbilledMode() {
|
fun loadUnbilledMode() {
|
||||||
if (currentUserId.isNullOrBlank()) {
|
if (currentUserId.isNullOrBlank()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//todo 清除人脸数据
|
|
||||||
// binding.dualCameraFaceRectView.clearFaceInfo()
|
|
||||||
// clearLeftFaceData()
|
|
||||||
// facePreviewInfoList?.clear()
|
|
||||||
// recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
|
||||||
|
|
||||||
// pauseCamera()
|
|
||||||
|
|
||||||
// resumeCamera()
|
|
||||||
|
|
||||||
// TODO: 如何清除人脸数据重新识别
|
|
||||||
// stopCamera()
|
|
||||||
// setupArcCamera()
|
|
||||||
|
|
||||||
isLoadUnbilledMode = true
|
isLoadUnbilledMode = true
|
||||||
Timber.tag(TAG).d("loadUnbilledMode")
|
Timber.tag(TAG).d("loadUnbilledMode")
|
||||||
@@ -491,11 +484,8 @@ class MainScreenPresentation(
|
|||||||
binding.nutritionInclude.tvUserName.text = userNutrition?.name.maskName()
|
binding.nutritionInclude.tvUserName.text = userNutrition?.name.maskName()
|
||||||
val recommendCalorie = (userNutrition?.recommendCalorie ?: 0.0).roundedDecimalPlace(1)
|
val recommendCalorie = (userNutrition?.recommendCalorie ?: 0.0).roundedDecimalPlace(1)
|
||||||
|
|
||||||
binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${recommendCalorie.roundedDecimalPlace(1)}kcal"
|
binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${recommendCalorie}kcal"
|
||||||
// binding.nutritionInclude.tvRecommendHeat.text = "推荐热量:${recommendCalorie.removeTrailingZeros()}kcal"
|
|
||||||
//updateWeight(lastWeight / 1000)
|
|
||||||
// -------------------------------------------------
|
|
||||||
// 删除userNutritionData,改为userNutrition
|
|
||||||
//0-即放即取,1-余量计量
|
//0-即放即取,1-余量计量
|
||||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||||
calculateNutrition(
|
calculateNutrition(
|
||||||
@@ -536,12 +526,6 @@ class MainScreenPresentation(
|
|||||||
if (isFirstOpen.not()) {
|
if (isFirstOpen.not()) {
|
||||||
activity.resumeAnalysis()
|
activity.resumeAnalysis()
|
||||||
}
|
}
|
||||||
//if (abs(lastWeight.toInt()) <= 5) {
|
|
||||||
// activity.runOnUiThread {
|
|
||||||
// ToastUtils.showToast("秤上重量几乎为0,请确认")
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
LightManager.closeGreenLight()
|
LightManager.closeGreenLight()
|
||||||
LightManager.closeRedLight()
|
LightManager.closeRedLight()
|
||||||
|
|
||||||
@@ -576,22 +560,6 @@ class MainScreenPresentation(
|
|||||||
stepChangeCallback(currentStep)
|
stepChangeCallback(currentStep)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun foodRecSuccess(foodInfo: FoodInfo) {
|
|
||||||
// //识别逻辑完成根据是否计费显示不同页面
|
|
||||||
// val mode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
|
||||||
// if (mode == 0) {
|
|
||||||
// //计费
|
|
||||||
// loadBilledMode()
|
|
||||||
// } else {
|
|
||||||
// //不计费
|
|
||||||
// //userViewModel.getUserNutritionData(
|
|
||||||
// // userId = userId,
|
|
||||||
// // foodId = currentFood!!.foodId!!
|
|
||||||
// //)
|
|
||||||
// loadUnbilledMode()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户人脸识别中
|
* 用户人脸识别中
|
||||||
*/
|
*/
|
||||||
@@ -672,19 +640,18 @@ class MainScreenPresentation(
|
|||||||
} else {
|
} else {
|
||||||
//联合支付,进行人脸识别
|
//联合支付,进行人脸识别
|
||||||
if (activity.settlementMode == 0) {
|
if (activity.settlementMode == 0) {
|
||||||
|
if (activity.isSwitchFood.not()) {
|
||||||
step2FaceRecognizing(foodInfo)
|
step2FaceRecognizing(foodInfo)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//不计费,开启人脸识别
|
//不计费,开启人脸识别
|
||||||
if (currentStep == 1 || binding.tvFaceTip.isVisible.not()) {
|
if (currentStep == 1 || binding.tvFaceTip.isVisible.not()) {
|
||||||
|
if (activity.isSwitchFood.not()) {
|
||||||
step2FaceRecognizing(foodInfo)
|
step2FaceRecognizing(foodInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//if (currentStep == 1) {
|
}
|
||||||
// step2FaceRecognizing(foodInfo)
|
|
||||||
//} else {
|
|
||||||
// updateFoodInfo(foodInfo)
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFoodInfo(foodInfo: FoodInfo) {
|
private fun updateFoodInfo(foodInfo: FoodInfo) {
|
||||||
@@ -1030,6 +997,8 @@ class MainScreenPresentation(
|
|||||||
Timber.tag(TAG)
|
Timber.tag(TAG)
|
||||||
.i("recognizeUserId observe compareResult = ${result.trackId}, userId = ${result.faceEntity.userName}, step = $currentStep")
|
.i("recognizeUserId observe compareResult = ${result.trackId}, userId = ${result.faceEntity.userName}, step = $currentStep")
|
||||||
recognitionTime = System.currentTimeMillis()
|
recognitionTime = System.currentTimeMillis()
|
||||||
|
//识别成功时更新lastWeight,解决使用过程中给秤上放东西,导致重量错误问题
|
||||||
|
lastWeight = activity.currentWeight
|
||||||
recognitionWeight = lastWeight
|
recognitionWeight = lastWeight
|
||||||
lastFaceTrackId = result.trackId
|
lastFaceTrackId = result.trackId
|
||||||
val faceEntity = result.faceEntity
|
val faceEntity = result.faceEntity
|
||||||
@@ -1359,7 +1328,10 @@ class MainScreenPresentation(
|
|||||||
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,mealPickupMode=$mealPickupMode")
|
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,mealPickupMode=$mealPickupMode")
|
||||||
if (mealPickupMode == 1) {
|
if (mealPickupMode == 1) {
|
||||||
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step2FaceRecognizing")
|
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step2FaceRecognizing")
|
||||||
|
if (activity.currentWeight > MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||||
|
//余量计量拿走秤上最后一点餐品时,不用再进行人脸识别了
|
||||||
step2FaceRecognizing(currentFood!!)
|
step2FaceRecognizing(currentFood!!)
|
||||||
|
}
|
||||||
isKeepFaceState = false
|
isKeepFaceState = false
|
||||||
if (activity.settlementMode == 0) {
|
if (activity.settlementMode == 0) {
|
||||||
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step2FaceRecognizing,联合支付")
|
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step2FaceRecognizing,联合支付")
|
||||||
|
|||||||
Reference in New Issue
Block a user