1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-22 00:06:48 +02:00

Refactor diffs so that it's easier to add a new one

This commit is contained in:
Milena May
2016-08-11 21:19:36 +02:00
parent 635044290d
commit 3cad32c7b6
2 changed files with 100 additions and 56 deletions

View File

@@ -457,62 +457,69 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
if (scaleDataIterator.hasNext()) { if (scaleDataIterator.hasNext()) {
ScaleData diffScaleData = scaleDataIterator.next(); ScaleData diffScaleData = scaleDataIterator.next();
double diffWeight = lastScaleData.weight - diffScaleData.weight; ScaleDiff.setDiff(
double diffBMI = currentScaleUser.getBMI(lastScaleData.weight) - currentScaleUser.getBMI(diffScaleData.weight); txtLabelWeight,
double diffFat = lastScaleData.fat - diffScaleData.fat; lastScaleData.weight - diffScaleData.weight,
double diffMuscle = lastScaleData.muscle - diffScaleData.muscle; getResources().getString(R.string.label_weight),
double diffWater = lastScaleData.water - diffScaleData.water; "%.1f ",
double diffWaist = lastScaleData.waist - diffScaleData.waist; ScaleUser.UNIT_STRING[currentScaleUser.scale_unit]
double diffWHtR = currentScaleUser.getWHtR(lastScaleData.waist) - currentScaleUser.getWHtR(diffScaleData.waist); );
double diffHip = lastScaleData.hip - diffScaleData.hip; ScaleDiff.setDiff(
double diffWHR = currentScaleUser.getWHR(lastScaleData.waist, lastScaleData.hip) - currentScaleUser.getWHR(diffScaleData.waist, diffScaleData.hip); txtLabelBMI,
currentScaleUser.getBMI(lastScaleData.weight) - currentScaleUser.getBMI(diffScaleData.weight),
getResources().getString(R.string.label_bmi),
if (diffWeight > 0.0) "%.1f ",
txtLabelWeight.setText(Html.fromHtml(getResources().getString(R.string.label_weight) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f ", diffWeight) + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit] + "</small></font>")); ""
else );
txtLabelWeight.setText(Html.fromHtml(getResources().getString(R.string.label_weight) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f ", diffWeight) + ScaleUser.UNIT_STRING[currentScaleUser.scale_unit] + "</small></font>")); ScaleDiff.setDiff(
txtLabelFat,
lastScaleData.fat - diffScaleData.fat,
if (diffBMI > 0.0) getResources().getString(R.string.label_fat),
txtLabelBMI.setText(Html.fromHtml(getResources().getString(R.string.label_bmi) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffBMI) + "</small></font>")); "%.1f ",
else "%"
txtLabelBMI.setText(Html.fromHtml(getResources().getString(R.string.label_bmi) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffBMI) + "</small></font>")); );
ScaleDiff.setDiff(
if (diffFat > 0.0) txtLabelMuscle,
txtLabelFat.setText(Html.fromHtml(getResources().getString(R.string.label_fat) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffFat) + "%</small></font>")); lastScaleData.muscle - diffScaleData.muscle,
else getResources().getString(R.string.label_muscle),
txtLabelFat.setText(Html.fromHtml(getResources().getString(R.string.label_fat) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffFat) + "%</small></font>")); "%.1f ",
"%"
if (diffMuscle > 0.0) );
txtLabelMuscle.setText(Html.fromHtml(getResources().getString(R.string.label_muscle) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffMuscle) + "%</small></font>")); ScaleDiff.setDiff(
else txtLabelWater,
txtLabelMuscle.setText(Html.fromHtml(getResources().getString(R.string.label_muscle) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffMuscle) + "%</small></font>")); lastScaleData.water - diffScaleData.water,
getResources().getString(R.string.label_water),
if (diffWater > 0.0) "%.1f ",
txtLabelWater.setText(Html.fromHtml(getResources().getString(R.string.label_water) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffWater) + "%</small></font>")); "%"
else );
txtLabelWater.setText(Html.fromHtml(getResources().getString(R.string.label_water) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffWater) + "%</small></font>")); ScaleDiff.setDiff(
txtLabelWaist,
if (diffWaist > 0.0) lastScaleData.waist - diffScaleData.waist,
txtLabelWaist.setText(Html.fromHtml(getResources().getString(R.string.label_waist) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffWaist) + "cm</small></font>")); getResources().getString(R.string.label_waist),
else "%.1f ",
txtLabelWaist.setText(Html.fromHtml(getResources().getString(R.string.label_waist) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffWaist) + "cm</small></font>")); "cm"
);
if (diffWHtR > 0.0) ScaleDiff.setDiff(
txtLabelWHtR.setText(Html.fromHtml(getResources().getString(R.string.label_whtr) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.2f", diffWHtR) + "</small></font>")); txtLabelWHtR,
else currentScaleUser.getWHtR(lastScaleData.waist) - currentScaleUser.getWHtR(diffScaleData.waist),
txtLabelWHtR.setText(Html.fromHtml(getResources().getString(R.string.label_whtr) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.2f", diffWHtR) + "</small></font>")); getResources().getString(R.string.label_whtr),
"%.2f ",
if (diffHip > 0.0) ""
txtLabelHip.setText(Html.fromHtml(getResources().getString(R.string.label_hip) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.1f", diffHip) + "cm</small></font>")); );
else ScaleDiff.setDiff(
txtLabelHip.setText(Html.fromHtml(getResources().getString(R.string.label_hip) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.1f", diffHip) + "cm</small></font>")); txtLabelHip,
lastScaleData.hip - diffScaleData.hip,
if (diffWHR > 0.0) getResources().getString(R.string.label_hip),
txtLabelWHR.setText(Html.fromHtml(getResources().getString(R.string.label_whr) + " <br> <font color='grey'>&#x2197;<small> " + String.format("%.2f", diffWHR) + "</small></font>")); "%.1f ",
else "cm"
txtLabelWHR.setText(Html.fromHtml(getResources().getString(R.string.label_whr) + " <br> <font color='grey'>&#x2198;<small> " + String.format("%.2f", diffWHR) + "</small></font>")); );
ScaleDiff.setDiff(
txtLabelWHR,
currentScaleUser.getWHR(lastScaleData.waist, lastScaleData.hip) - currentScaleUser.getWHR(diffScaleData.waist, diffScaleData.hip),
getResources().getString(R.string.label_whr),
"%.2f ",
""
);
} }
} }
} }

View File

@@ -0,0 +1,37 @@
package com.health.openscale.gui;
import android.text.Html;
import android.widget.TextView;
public class ScaleDiff {
private static String SYMBOL_UP = "&#x2197;";
private static String SYMBOL_DOWN = "&#x2198;";
public static void setDiff(TextView txtLabel,
double diff,
String labelResource,
String format,
String unit) {
String symbol;
if (diff > 0.0) {
symbol = SYMBOL_UP;
} else {
symbol = SYMBOL_DOWN;
}
txtLabel.setText(
Html.fromHtml(
labelResource +
" <br> <font color='grey'>" +
symbol +
"<small> " +
String.format(format, diff) +
unit +
"</small></font>"
)
);
}
}