添加了初始化界面,修复了人脸数据更新后不能识别的问题

This commit is contained in:
zxj
2025-08-07 16:23:21 +08:00
parent 742b3a0775
commit 1f1c3804ac
18 changed files with 509 additions and 70 deletions
@@ -45,11 +45,17 @@ class UserViewModel : BaseViewModel() {
private val _dinnerTypeInfo = MutableStateFlow<DinnerTypeInfo?>(null)
val dinnerTypeInfo: StateFlow<DinnerTypeInfo?> = _dinnerTypeInfo
/**
* 人脸加载完成
*/
private val _loadFaceResult = MutableStateFlow<Boolean>(false)
val loadFaceResult : StateFlow<Boolean> = _loadFaceResult
/**
* 获取token
*/
fun getEquipmentToken(qrcodeId: String = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e") {
fun getEquipmentToken(qrcodeId: String = GlobalData.deviceId) {
Timber.d("getEquipmentToken")
launchWithLoading {
val response = repository.getEquipmentToken(qrcodeId)
@@ -70,6 +76,7 @@ class UserViewModel : BaseViewModel() {
fun getUserFaceCache(index: Int = 0) {
Timber.d("getUserFaceCache index = $index")
launch {
_loadFaceResult.value = false
val response = repository.getUserFaceCache(index)
if (parseResponse(response)) {
// 获取成功一次后缓存状态
@@ -80,11 +87,12 @@ class UserViewModel : BaseViewModel() {
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureString))
}
faceApi.updateFaceData(index, faceEntity)
activeEngine()
}
val nextPageIndex = response.result?.nextPageIndex ?: -1
if (nextPageIndex > 0) {
getUserFaceCache(nextPageIndex)
} else{
_loadFaceResult.value = true
}
}
}
@@ -129,13 +137,6 @@ class UserViewModel : BaseViewModel() {
})
}
/**
* 重置用户信息
*/
fun resetUserInfo() {
Timber.d("resetUserInfo")
}
fun getIdentifiedFoodList() {
Timber.d("identifiedFoodList")
launchWithLoading {
@@ -180,7 +181,7 @@ class UserViewModel : BaseViewModel() {
fun getUserNutritionData(userId: String, foodId: String) {
Timber.d("getUserNutritionData userId = ${userId}, foodId = $foodId")
_nutritionData.value = null
launchWithLoading {
launch {
val response = repository.getUserNutritionData(userId = userId, foodId = foodId)
if (parseResponse(response)) {
_nutritionData.value = response.result
@@ -191,7 +192,7 @@ class UserViewModel : BaseViewModel() {
fun getDinnerType() {
Timber.d("getDinnerType")
_dinnerTypeInfo.value = null
launchWithLoading {
launch {
val response = repository.getDinnerType()
if (parseResponse(response)) {
_dinnerTypeInfo.value = response.result