添加了初始化界面,修复了人脸数据更新后不能识别的问题
This commit is contained in:
@@ -11,7 +11,6 @@ import android.hardware.Camera
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.view.Display
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -69,19 +68,18 @@ class SecondaryScreenPresentation(
|
||||
|
||||
// 当前食物信息
|
||||
private var currentFood: FoodInfo? = null
|
||||
private var lastFood: FoodInfo? = null
|
||||
private var userNutritionData: UserNutritionData? = null
|
||||
private var dinnerTypeInfo: DinnerTypeInfo? = null
|
||||
private lateinit var itemUserNutritionBinding: ItemUserNutritionBinding
|
||||
private lateinit var stepChangeCallback: (Int) -> Unit
|
||||
|
||||
// 上一次的计算热量结果
|
||||
private var lastCalcResultInfo: UserNutritionUtils.CalcResultInfo? = null
|
||||
private var lastWeight = 0.0
|
||||
private val debouncer = Debouncer(500)
|
||||
private var faceTime: Long = 0L // 人脸识别时的时间
|
||||
private var recognitionTime: Long = 0L // 人脸识别时的时间
|
||||
private var recognitionWeight: Double = 0.0 // 人脸识别时的重量
|
||||
private var lastFaceTrackId: Int = 0 // 上一次的人脸信息
|
||||
private var mealPickupMode: Int = 0 // 取餐模式 0 即放即取 1 余量取餐
|
||||
|
||||
// 当前步骤
|
||||
var currentStep: Int = 0
|
||||
@@ -99,6 +97,13 @@ class SecondaryScreenPresentation(
|
||||
}
|
||||
|
||||
private fun registerDataChange() {
|
||||
activity.lifecycleScope.launch {
|
||||
viewModel.loadFaceResult.collect { needUpdate ->
|
||||
if (needUpdate){
|
||||
recognizeViewModel.refreshFaceList()
|
||||
}
|
||||
}
|
||||
}
|
||||
activity.lifecycleScope.launch {
|
||||
viewModel.nutritionData.collect {
|
||||
Timber.d("registerDataChange nutritionData = $it")
|
||||
@@ -161,8 +166,6 @@ class SecondaryScreenPresentation(
|
||||
dinnerTypeInfo = null
|
||||
currentFood = null
|
||||
userNutritionData = null
|
||||
lastFood = null
|
||||
lastCalcResultInfo = null
|
||||
recognitionWeight = 0.0
|
||||
|
||||
stepChangeCallback(currentStep)
|
||||
@@ -182,6 +185,11 @@ class SecondaryScreenPresentation(
|
||||
fun step2(foodInfo: FoodInfo) {
|
||||
Timber.d("step2")
|
||||
currentStep = 2
|
||||
|
||||
dinnerTypeInfo = null
|
||||
userNutritionData = null
|
||||
recognitionWeight = 0.0
|
||||
|
||||
stepChangeCallback(currentStep)
|
||||
currentFood = foodInfo
|
||||
viewModel.getDinnerType()
|
||||
@@ -262,6 +270,14 @@ class SecondaryScreenPresentation(
|
||||
calculateNutrition(recognitionWeight - lastWeight)
|
||||
}
|
||||
|
||||
/**
|
||||
* 余量取餐
|
||||
*/
|
||||
fun updateMealPickupMode(mode: Int) {
|
||||
Timber.d("updateMealPickupMode mode = $mode")
|
||||
mealPickupMode = mode
|
||||
}
|
||||
|
||||
private fun calculateNutrition(weight: Double) {
|
||||
debouncer.debounce {
|
||||
Timber.d("calculateNutrition weight = $weight, recognitionWeight = $recognitionWeight")
|
||||
@@ -274,11 +290,6 @@ class SecondaryScreenPresentation(
|
||||
dinnerType = dinnerType
|
||||
)
|
||||
Timber.d("calculateNutrition calcResultInfo = $calcResultInfo")
|
||||
if (lastCalcResultInfo == calcResultInfo) {
|
||||
Timber.d("calculateNutrition 与上次计算结果无变化")
|
||||
return@debounce
|
||||
}
|
||||
lastCalcResultInfo = calcResultInfo
|
||||
val columnMax = UserNutritionUtils.getMaxInt(calcResultInfo)
|
||||
|
||||
activity.runOnUiThread {
|
||||
@@ -346,7 +357,7 @@ class SecondaryScreenPresentation(
|
||||
}
|
||||
try {
|
||||
val cameraCount = Camera.getNumberOfCameras()
|
||||
if (cameraCount < 3){
|
||||
if (cameraCount < 3) {
|
||||
ToastUtils.showToast("摄像头数量异常")
|
||||
return
|
||||
}
|
||||
@@ -418,14 +429,14 @@ class SecondaryScreenPresentation(
|
||||
Timber.i("recognizeConfiguration: observe = ${recognizeConfiguration.toString()}")
|
||||
})
|
||||
recognizeViewModel.recognizeNotice.observe(activity, Observer { notice: String? ->
|
||||
// Timber.i("recognizeNotice observe notice = $notice")
|
||||
Timber.i("recognizeNotice observe notice = $notice")
|
||||
})
|
||||
|
||||
recognizeViewModel.recognizeUserId.observe(
|
||||
activity,
|
||||
Observer { compareResult: CompareResult ->
|
||||
Timber.i("recognizeUserId observe compareResult = ${compareResult.trackId}, userId = ${compareResult.faceEntity.userName}")
|
||||
faceTime = System.currentTimeMillis()
|
||||
recognitionTime = System.currentTimeMillis()
|
||||
recognitionWeight = lastWeight
|
||||
lastFaceTrackId = compareResult.trackId
|
||||
val faceEntity = compareResult.faceEntity
|
||||
@@ -701,7 +712,11 @@ class SecondaryScreenPresentation(
|
||||
Timber.i("$lastFaceTrackId 用户离开")
|
||||
lastFaceTrackId = 0
|
||||
postUserData()
|
||||
step1()
|
||||
if (mealPickupMode == 0) {
|
||||
step1()
|
||||
}else{
|
||||
step2(currentFood!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -715,7 +730,7 @@ class SecondaryScreenPresentation(
|
||||
val userNutritionParam = UserNutritionParam(
|
||||
userId = userNutritionData?.userId!!,
|
||||
foodId = currentFood?.id!!,
|
||||
faceTime = faceTime,
|
||||
faceTime = recognitionTime,
|
||||
faceEndTime = System.currentTimeMillis(),
|
||||
eatWeight = recognitionWeight - lastWeight,
|
||||
foodWeight = lastWeight
|
||||
|
||||
Reference in New Issue
Block a user