Skip to content

Commit

Permalink
Fixes #2202: Calculate nutrition facts doesn't take liquid units into…
Browse files Browse the repository at this point in the history
… account (#2211)
  • Loading branch information
balaji-ramavathu authored and PrajwalM2212 committed Feb 21, 2019
1 parent 49f7ee2 commit 46a8fbb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ private static String getValueInUnits(String stringValue, String unit) {
} else if (unit.equals("µg")) {
float value = Float.valueOf(stringValue);
return getRoundNumber(value * 1000000);
} else if (unit.equals("l")) {
float value = Float.valueOf(stringValue);
return getRoundNumber(value / 1000);
} else if (unit.equals("cl")) {
float value = Float.valueOf(stringValue);
return getRoundNumber(value / 10);
}
else {
return stringValue;
Expand Down Expand Up @@ -363,7 +369,15 @@ public String getForAnyValue(float userSetServing, String unit) {
float value = Float.valueOf(strValue);
value = (userSetServing / 100000) * value;
return getRoundNumber(value);
} else {
} else if (unit.equals("l")) {
float value = Float.valueOf(strValue);
value = (userSetServing * 10) * value;
return getRoundNumber(value);
} else if (unit.equals("cl")) {
float value = Float.valueOf(strValue);
value = (userSetServing / 10) * value;
return getRoundNumber(value);
}else {
return strValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ private String calculateCalories(float weight, String unit) {
case "kg":
weightInG = weight * 1000;
break;
case "l":
weightInG = weight * 1000;
break;
case "cl":
weightInG = weight * 10;
break;
default:
weightInG = weight;
break;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<item>g</item>
<item>mg</item>
<item>kg</item>
<item>l</item>
<item>cl</item>
</string-array>

<!-- nutrition energy units -->
Expand Down

0 comments on commit 46a8fbb

Please sign in to comment.