mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-26 09:44:31 +02:00
Round goal weight to one decimal on statistics fragment
This way it matches the other numbers. Also some minor refactoring.
This commit is contained in:
@@ -154,24 +154,27 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
|
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList) {
|
||||||
|
currentScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser();
|
||||||
|
|
||||||
if (scaleMeasurementList.isEmpty()) {
|
if (scaleMeasurementList.isEmpty()) {
|
||||||
lastScaleMeasurement = new ScaleMeasurement();
|
lastScaleMeasurement = new ScaleMeasurement();
|
||||||
|
lastScaleMeasurement.setUserId(currentScaleUser.getId());
|
||||||
} else {
|
} else {
|
||||||
lastScaleMeasurement = scaleMeasurementList.get(0);
|
lastScaleMeasurement = scaleMeasurementList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentScaleUser = OpenScale.getInstance(getContext()).getSelectedScaleUser();
|
|
||||||
|
|
||||||
updateStatistics(scaleMeasurementList);
|
updateStatistics(scaleMeasurementList);
|
||||||
updateGoal(scaleMeasurementList);
|
updateGoal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGoal(List<ScaleMeasurement> scaleMeasurementList) {
|
private void updateGoal() {
|
||||||
ScaleMeasurement goalScaleMeasurement = new ScaleMeasurement();
|
|
||||||
goalScaleMeasurement.setConvertedWeight(currentScaleUser.getGoalWeight(), currentScaleUser.getScaleUnit());
|
|
||||||
|
|
||||||
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
|
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
|
||||||
txtGoalWeight.setText(goalScaleMeasurement.getConvertedWeight(unit) + " " + unit.toString());
|
|
||||||
|
ScaleMeasurement goalScaleMeasurement = new ScaleMeasurement();
|
||||||
|
goalScaleMeasurement.setUserId(currentScaleUser.getId());
|
||||||
|
goalScaleMeasurement.setConvertedWeight(currentScaleUser.getGoalWeight(), unit);
|
||||||
|
|
||||||
|
txtGoalWeight.setText(String.format("%.1f %s", goalScaleMeasurement.getConvertedWeight(unit), unit.toString()));
|
||||||
|
|
||||||
double weight_diff = goalScaleMeasurement.getConvertedWeight(unit) - lastScaleMeasurement.getConvertedWeight(unit);
|
double weight_diff = goalScaleMeasurement.getConvertedWeight(unit) - lastScaleMeasurement.getConvertedWeight(unit);
|
||||||
txtGoalDiff.setText(String.format("%.1f %s", weight_diff, unit.toString()));
|
txtGoalDiff.setText(String.format("%.1f %s", weight_diff, unit.toString()));
|
||||||
@@ -181,19 +184,14 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
|||||||
int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
|
int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
|
||||||
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
|
txtGoalDayLeft.setText(getResources().getQuantityString(R.plurals.label_days, days, days));
|
||||||
|
|
||||||
lastScaleMeasurement.setUserId(currentScaleUser.getId());
|
final float goalBmi = goalScaleMeasurement.getBMI(currentScaleUser.getBodyHeight());
|
||||||
|
|
||||||
ScaleMeasurement goalData = new ScaleMeasurement();
|
|
||||||
goalData.setConvertedWeight(currentScaleUser.getGoalWeight(), unit);
|
|
||||||
goalData.setUserId(currentScaleUser.getId());
|
|
||||||
|
|
||||||
txtLabelGoalWeight.setText(
|
txtLabelGoalWeight.setText(
|
||||||
Html.fromHtml(
|
Html.fromHtml(
|
||||||
getResources().getString(R.string.label_goal_weight) +
|
getResources().getString(R.string.label_goal_weight) +
|
||||||
" <br> <font color='grey'><small>" +
|
" <br> <font color='grey'><small>" +
|
||||||
getResources().getString(R.string.label_bmi) +
|
getResources().getString(R.string.label_bmi) +
|
||||||
": " +
|
": " +
|
||||||
String.format("%.1f", goalData.getBMI(currentScaleUser.getBodyHeight())) +
|
String.format("%.1f", goalBmi) +
|
||||||
" </small></font>"
|
" </small></font>"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -203,7 +201,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
|||||||
" <br> <font color='grey'><small>" +
|
" <br> <font color='grey'><small>" +
|
||||||
getResources().getString(R.string.label_bmi) +
|
getResources().getString(R.string.label_bmi) +
|
||||||
": " +
|
": " +
|
||||||
String.format("%.1f", lastScaleMeasurement.getBMI(currentScaleUser.getBodyHeight()) - goalData.getBMI(currentScaleUser.getBodyHeight())) +
|
String.format("%.1f", lastScaleMeasurement.getBMI(currentScaleUser.getBodyHeight()) - goalBmi) +
|
||||||
" </small></font>"
|
" </small></font>"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -216,7 +214,7 @@ public class StatisticsFragment extends Fragment implements FragmentUpdateListen
|
|||||||
+ DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.getGoalDate()) +
|
+ DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.getGoalDate()) +
|
||||||
" </small></font>"
|
" </small></font>"
|
||||||
)
|
)
|
||||||
); // currentScaleUser.goalDate
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStatistics(List<ScaleMeasurement> scaleMeasurementList) {
|
private void updateStatistics(List<ScaleMeasurement> scaleMeasurementList) {
|
||||||
|
Reference in New Issue
Block a user