This commit is contained in:
2026-01-09 16:10:57 +08:00
parent a0452e985a
commit a6fa5f153a
3 changed files with 10 additions and 9 deletions
@@ -988,7 +988,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
params["foodVector"] = foodVectorJson.toRequestBody()
val idList = viewModel.uploadCollectFoodPics(files, params)
if (idList.isNullOrEmpty()) {
loadRemindDialog("未返回id")
loadRemindDialog("上传失败,未返回向量数据id")
Timber.tag(TAG).d("idList为空")
return
}
@@ -225,7 +225,8 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>() {
ToastUtils.showToast("请选择菜品名称")
return@setOnClickListener
}
if (foodCollectionList.size <= 1) {
val count = foodCollectionList.count { it.imageFile != null }
if (count == 0) {
ToastUtils.showToast("请拍摄菜品照片")
return@setOnClickListener
}
@@ -29,10 +29,10 @@ object UserNutritionUtils {
// 处理食物信息
if (weight > 0.0) {
calorie = calculateValue2(foodInfo.calorie,foodInfo.specWeight, weight)
grain = calculateValue2(foodInfo.stapleFood, foodInfo.specWeight,weight)
fruitsVegetables = calculateValue2(foodInfo.fruitsVegetables, foodInfo.specWeight,weight)
meatEggs = calculateValue2(foodInfo.meatEggs, foodInfo.specWeight,weight)
calorie = calculateValue2(foodInfo.calorie,weight)
grain = calculateValue2(foodInfo.stapleFood, weight)
fruitsVegetables = calculateValue2(foodInfo.fruitsVegetables, weight)
meatEggs = calculateValue2(foodInfo.meatEggs, weight)
}
// 合并用户数据
@@ -142,9 +142,9 @@ object UserNutritionUtils {
else -> 0
}
}
private fun calculateValue2(nutrient: Double?, specWeight: Double?, weight: Double): Double {
if ((nutrient?:0.0) == 0.0 || (specWeight?:0.0) == 0.0) return 0.0
return nutrient!! * weight / specWeight!!
private fun calculateValue2(nutrient: Double?, weight: Double): Double {
if ((nutrient?:0.0) == 0.0) return 0.0
return nutrient!! * weight / 100.0
}
/**
* 计算每百克含量