优化
This commit is contained in:
@@ -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
|
||||
}
|
||||
/**
|
||||
* 计算每百克含量
|
||||
|
||||
Reference in New Issue
Block a user