diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java index e812612a..a0e51ada 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/GraphFragment.java @@ -49,6 +49,7 @@ import com.health.openscale.gui.views.FatMeasurementView; import com.health.openscale.gui.views.FloatMeasurementView; import com.health.openscale.gui.views.HipMeasurementView; import com.health.openscale.gui.views.LBWMeasurementView; +import com.health.openscale.gui.views.MeasurementView; import com.health.openscale.gui.views.MuscleMeasurementView; import com.health.openscale.gui.views.WHRMeasurementView; import com.health.openscale.gui.views.WHtRMeasurementView; @@ -93,7 +94,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { private PopupMenu popup; private SharedPreferences prefs; - private ArrayList measurementViews; + private ArrayList measurementViews; private int textColor; @@ -329,31 +330,39 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { floatingActionBar.removeAllViews(); - for (FloatMeasurementView measurementView : measurementViews) { - measurementView.updatePreferences(prefs); - Stack valuesStack = new Stack(); + for (MeasurementView view : measurementViews) { + if (view instanceof FloatMeasurementView) { + FloatMeasurementView measurementView = (FloatMeasurementView) view; - for (ScaleMeasurement measurement : scaleMeasurementList) { - measurementView.loadFrom(measurement, null); - - calDB.setTime(measurement.getDateTime()); - - if (addPointValue(valuesStack, calDB.get(field), measurementView.getValue())) { - pointIndexScaleMeasurementList.add(measurement); // if new point was added, add this point to pointIndexScaleDataList to get the correct point index after selecting an point + if (measurementView.getName().equals(getString(R.string.label_bmr))) { + continue; } - } - Line diagramLine = new Line(valuesStack). - setColor(measurementView.getColor()). - setHasLabels(prefs.getBoolean("labelsEnable", true)). - setHasPoints(prefs.getBoolean("pointsEnable", true)). - setFormatter(new SimpleLineChartValueFormatter(1)); + measurementView.updatePreferences(prefs); + Stack valuesStack = new Stack(); - if (measurementView.isVisible()) { - addFloatingActionButton(measurementView); + for (ScaleMeasurement measurement : scaleMeasurementList) { + measurementView.loadFrom(measurement, null); - if (prefs.getBoolean(String.valueOf("actionButton" + measurementView.getName()), true)) { - diagramLineList.add(diagramLine); + calDB.setTime(measurement.getDateTime()); + + if (addPointValue(valuesStack, calDB.get(field), measurementView.getValue())) { + pointIndexScaleMeasurementList.add(measurement); // if new point was added, add this point to pointIndexScaleDataList to get the correct point index after selecting an point + } + } + + Line diagramLine = new Line(valuesStack). + setColor(measurementView.getColor()). + setHasLabels(prefs.getBoolean("labelsEnable", true)). + setHasPoints(prefs.getBoolean("pointsEnable", true)). + setFormatter(new SimpleLineChartValueFormatter(1)); + + if (measurementView.isVisible()) { + addFloatingActionButton(measurementView); + + if (prefs.getBoolean(String.valueOf("actionButton" + measurementView.getName()), true)) { + diagramLineList.add(diagramLine); + } } } } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/OverviewFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/OverviewFragment.java index 1b4693de..7f7eac33 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/OverviewFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/OverviewFragment.java @@ -42,6 +42,7 @@ import com.health.openscale.gui.views.BMIMeasurementView; import com.health.openscale.gui.views.BMRMeasurementView; import com.health.openscale.gui.views.BoneMeasurementView; import com.health.openscale.gui.views.FatMeasurementView; +import com.health.openscale.gui.views.FloatMeasurementView; import com.health.openscale.gui.views.HipMeasurementView; import com.health.openscale.gui.views.LBWMeasurementView; import com.health.openscale.gui.views.MeasurementView; @@ -56,6 +57,7 @@ import java.text.DateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.Stack; import lecho.lib.hellocharts.formatter.SimpleLineChartValueFormatter; import lecho.lib.hellocharts.listener.LineChartOnValueSelectListener; @@ -67,7 +69,6 @@ import lecho.lib.hellocharts.model.LineChartData; import lecho.lib.hellocharts.model.PieChartData; import lecho.lib.hellocharts.model.PointValue; import lecho.lib.hellocharts.model.SliceValue; -import lecho.lib.hellocharts.util.ChartUtils; import lecho.lib.hellocharts.view.LineChartView; import lecho.lib.hellocharts.view.PieChartView; @@ -81,7 +82,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener private TableLayout tableOverviewLayout; - private ArrayList overviewMeasurements; + private ArrayList measurementViews; private PieChartView pieChartLast; private LineChartView lineChartLast; @@ -119,22 +120,22 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener tableOverviewLayout = (TableLayout)overviewView.findViewById(R.id.tableLayoutMeasurements); - overviewMeasurements = new ArrayList<>(); + measurementViews = new ArrayList<>(); - overviewMeasurements.add(new WeightMeasurementView(context)); - overviewMeasurements.add(new BMIMeasurementView(context)); - overviewMeasurements.add(new WaterMeasurementView(context)); - overviewMeasurements.add(new MuscleMeasurementView(context)); - overviewMeasurements.add(new LBWMeasurementView(context)); - overviewMeasurements.add(new FatMeasurementView(context)); - overviewMeasurements.add(new BoneMeasurementView(context)); - overviewMeasurements.add(new WaistMeasurementView(context)); - overviewMeasurements.add(new WHtRMeasurementView(context)); - overviewMeasurements.add(new HipMeasurementView(context)); - overviewMeasurements.add(new WHRMeasurementView(context)); - overviewMeasurements.add(new BMRMeasurementView(context)); + measurementViews.add(new WeightMeasurementView(context)); + measurementViews.add(new BMIMeasurementView(context)); + measurementViews.add(new WaterMeasurementView(context)); + measurementViews.add(new MuscleMeasurementView(context)); + measurementViews.add(new LBWMeasurementView(context)); + measurementViews.add(new FatMeasurementView(context)); + measurementViews.add(new BoneMeasurementView(context)); + measurementViews.add(new WaistMeasurementView(context)); + measurementViews.add(new WHtRMeasurementView(context)); + measurementViews.add(new HipMeasurementView(context)); + measurementViews.add(new WHRMeasurementView(context)); + measurementViews.add(new BMRMeasurementView(context)); - for (MeasurementView measurement : overviewMeasurements) { + for (MeasurementView measurement : measurementViews) { tableOverviewLayout.addView(measurement); } @@ -189,7 +190,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId()); ScaleMeasurement prevScaleMeasurement = tupleScaleData[0]; - for (MeasurementView measurement : overviewMeasurements) { + for (MeasurementView measurement : measurementViews) { measurement.updatePreferences(prefs); measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement); } @@ -225,17 +226,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener private void updateLastLineChart(List scaleMeasurementList) { - List axisValues = new ArrayList(); - - List valuesWeight = new ArrayList(); - List valuesFat = new ArrayList(); - List valuesWater = new ArrayList(); - List valuesMuscle = new ArrayList(); - List valuesLBW = new ArrayList(); - List valuesWaist = new ArrayList(); - List valuesHip = new ArrayList(); - List valuesBone = new ArrayList(); - List lines = new ArrayList(); int max_i = 7; @@ -243,112 +233,54 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener max_i = scaleMeasurementList.size(); } + List diagramLineList = new ArrayList<>(); + List axisValues = new ArrayList<>(); + final Calendar now = Calendar.getInstance(); Calendar histCalendar = Calendar.getInstance(); - scaleMeasurementLastDays = new ArrayList(); + for (MeasurementView view : measurementViews) { + if (view instanceof FloatMeasurementView) { + FloatMeasurementView measurementView = (FloatMeasurementView) view; - for (int i=0; i valuesStack = new Stack(); - histCalendar.setTime(histData.getDateTime()); - int days = DateTimeHelpers.daysBetween(now, histCalendar); - String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days); - axisValues.add(new AxisValue(i, label.toCharArray())); + scaleMeasurementLastDays = new ArrayList<>(); + + for (int i=0; i arcValuesLast = new ArrayList<>(); - List arcValuesLast = new ArrayList(); + for (MeasurementView view : measurementViews) { + if (view instanceof FloatMeasurementView) { + FloatMeasurementView measurementView = (FloatMeasurementView) view; - if (lastScaleMeasurement.getFat() == 0) { - arcValuesLast.add(new SliceValue(1, ChartUtils.COLOR_ORANGE)); - } - else { - arcValuesLast.add(new SliceValue(lastScaleMeasurement.getFat(), ChartUtils.COLOR_ORANGE)); - } + if (measurementView.getName().equals(getString(R.string.label_bmr))) { + continue; + } - if (lastScaleMeasurement.getWater() == 0) { - arcValuesLast.add(new SliceValue(1, ChartUtils.COLOR_BLUE)); - } - else { - arcValuesLast.add(new SliceValue(lastScaleMeasurement.getWater(), ChartUtils.COLOR_BLUE)); - } + measurementView.updatePreferences(prefs); + measurementView.loadFrom(lastScaleMeasurement, null); - if (lastScaleMeasurement.getMuscle() == 0) { - arcValuesLast.add(new SliceValue(1, ChartUtils.COLOR_GREEN)); - } - else { - arcValuesLast.add(new SliceValue(lastScaleMeasurement.getMuscle(), ChartUtils.COLOR_GREEN)); + if (measurementView.getValue() != 0) { + arcValuesLast.add(new SliceValue(measurementView.getValue(), measurementView.getColor())); + } + } } final Converters.WeightUnit unit = currentScaleUser.getScaleUnit(); @@ -423,16 +350,16 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener String date_time = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT).format(lastScaleMeasurement.getDateTime()); - switch (i) { - case 0: - Toast.makeText(getActivity(), getResources().getString(R.string.info_your_fat) + " " + lastScaleMeasurement.getFat() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show(); - break; - case 1: - Toast.makeText(getActivity(), getResources().getString(R.string.info_your_water) + " " + lastScaleMeasurement.getWater() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show(); - break; - case 2: - Toast.makeText(getActivity(), getResources().getString(R.string.info_your_muscle) + " " + lastScaleMeasurement.getMuscle() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show(); - break; + for (MeasurementView view : measurementViews) { + if (view instanceof FloatMeasurementView) { + FloatMeasurementView measurementView = (FloatMeasurementView) view; + + measurementView.loadFrom(lastScaleMeasurement, null); + + if (measurementView.getColor() == arcValue.getColor()) { + Toast.makeText(getActivity(), measurementView.getName() + " " + measurementView.getValueAsString() + measurementView.getUnit() + " " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show(); + } + } } } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/BMIMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/BMIMeasurementView.java index 68080cca..e7ebaeda 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/BMIMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/BMIMeasurementView.java @@ -52,7 +52,7 @@ public class BMIMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return ""; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/BMRMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/BMRMeasurementView.java index d6bd5c59..a54dfee3 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/BMRMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/BMRMeasurementView.java @@ -59,7 +59,7 @@ public class BMRMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return "kCal"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/BoneMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/BoneMeasurementView.java index ef8ba692..f22e16eb 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/BoneMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/BoneMeasurementView.java @@ -47,7 +47,7 @@ public class BoneMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return "kg"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/FatMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/FatMeasurementView.java index 5b0f8fe2..dd758c70 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/FatMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/FatMeasurementView.java @@ -61,7 +61,7 @@ public class FatMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { if (percentageEnable) { return "%"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/FloatMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/FloatMeasurementView.java index 5d75a42b..b5b324db 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/FloatMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/FloatMeasurementView.java @@ -210,7 +210,7 @@ public abstract class FloatMeasurementView extends MeasurementView { protected abstract float getMeasurementValue(ScaleMeasurement measurement); protected abstract void setMeasurementValue(float value, ScaleMeasurement measurement); - protected abstract String getUnit(); + public abstract String getUnit(); protected abstract float getMaxValue(); public abstract int getColor(); diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/HipMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/HipMeasurementView.java index 37bd5365..89636d02 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/HipMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/HipMeasurementView.java @@ -47,7 +47,7 @@ public class HipMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return "cm"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/LBWMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/LBWMeasurementView.java index c0815631..f5513b75 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/LBWMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/LBWMeasurementView.java @@ -50,7 +50,7 @@ public class LBWMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return "kg"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/MuscleMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/MuscleMeasurementView.java index 2cc13efc..29f0ef2b 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/MuscleMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/MuscleMeasurementView.java @@ -59,7 +59,7 @@ public class MuscleMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { if (percentageEnable) { return "%"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/WHRMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/WHRMeasurementView.java index c3173414..831882ff 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/WHRMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/WHRMeasurementView.java @@ -53,7 +53,7 @@ public class WHRMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return ""; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/WHtRMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/WHtRMeasurementView.java index 44d45cc7..a082a49f 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/WHtRMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/WHtRMeasurementView.java @@ -52,7 +52,7 @@ public class WHtRMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return ""; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/WaistMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/WaistMeasurementView.java index 327ebacc..2c332a89 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/WaistMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/WaistMeasurementView.java @@ -47,7 +47,7 @@ public class WaistMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return "cm"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/WaterMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/WaterMeasurementView.java index 87bf6d28..fea5a73f 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/WaterMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/WaterMeasurementView.java @@ -61,7 +61,7 @@ public class WaterMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { if (percentageEnable) { return "%"; } diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/WeightMeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/WeightMeasurementView.java index 08f78ed4..ee904256 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/WeightMeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/WeightMeasurementView.java @@ -49,7 +49,7 @@ public class WeightMeasurementView extends FloatMeasurementView { } @Override - protected String getUnit() { + public String getUnit() { return getScaleUser().getScaleUnit().toString(); }