mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 08:43:15 +02:00
Update dependent values when a measurement is changed
I.e. when the weight is updated, update BMI as well.
This commit is contained in:
@@ -44,6 +44,7 @@ import com.health.openscale.gui.views.FatMeasurementView;
|
||||
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.MeasurementViewUpdateListener;
|
||||
import com.health.openscale.gui.views.MuscleMeasurementView;
|
||||
import com.health.openscale.gui.views.TimeMeasurementView;
|
||||
import com.health.openscale.gui.views.WHRMeasurementView;
|
||||
@@ -172,6 +173,7 @@ public class DataEntryActivity extends Activity {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||
measurement.setOnUpdateListener(null);
|
||||
measurement.updatePreferences(prefs);
|
||||
}
|
||||
|
||||
@@ -214,13 +216,7 @@ public class DataEntryActivity extends Activity {
|
||||
measurement.updateDiff(selectedScaleData, prevScaleData);
|
||||
measurement.setExpand(doExpand);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!OpenScale.getInstance(getApplicationContext()).getScaleDataList().isEmpty())
|
||||
{
|
||||
} else if (!OpenScale.getInstance(getApplicationContext()).getScaleDataList().isEmpty()) {
|
||||
setViewMode(MeasurementView.MeasurementViewMode.ADD);
|
||||
txtDataNr.setText(DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(new Date()));
|
||||
ScaleData lastScaleData = OpenScale.getInstance(getApplicationContext()).getScaleDataList().get(0);
|
||||
@@ -239,6 +235,11 @@ public class DataEntryActivity extends Activity {
|
||||
measurement.updateValue(newScaleData);
|
||||
}
|
||||
}
|
||||
|
||||
onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
|
||||
for (MeasurementView measurement : dataEntryMeasurements) {
|
||||
measurement.setOnUpdateListener(updateListener);
|
||||
}
|
||||
}
|
||||
|
||||
private void setViewMode(MeasurementView.MeasurementViewMode viewMode)
|
||||
@@ -352,6 +353,30 @@ public class DataEntryActivity extends Activity {
|
||||
return false;
|
||||
}
|
||||
|
||||
private class onMeasurementViewUpdateListener implements MeasurementViewUpdateListener {
|
||||
@Override
|
||||
public void onMeasurementViewUpdate(MeasurementView view) {
|
||||
ArrayList<MeasurementView> viewsToUpdate = new ArrayList<>();
|
||||
if (view == weightMeasurement) {
|
||||
viewsToUpdate.add(bmiMeasurementView);
|
||||
viewsToUpdate.add(bmrMeasurementView);
|
||||
} else if (view == waistMeasurement) {
|
||||
viewsToUpdate.add(wHtRMeasurementView);
|
||||
viewsToUpdate.add(whrMeasurementView);
|
||||
} else if (view == hipMeasurement) {
|
||||
viewsToUpdate.add(whrMeasurementView);
|
||||
} else if (view == dateMeasurement) {
|
||||
viewsToUpdate.add(bmrMeasurementView);
|
||||
}
|
||||
|
||||
if (!viewsToUpdate.isEmpty()) {
|
||||
ScaleData scaleData = createScaleDataFromMeasurement();
|
||||
for (MeasurementView measurement : viewsToUpdate) {
|
||||
measurement.updateValue(scaleData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class onClickListenerAdd implements View.OnClickListener {
|
||||
@Override
|
||||
|
@@ -80,6 +80,7 @@ public abstract class MeasurementView extends TableLayout {
|
||||
private float previousValue;
|
||||
private String diffValue;
|
||||
|
||||
private MeasurementViewUpdateListener updateListener = null;
|
||||
private MeasurementViewMode measurementMode;
|
||||
|
||||
public MeasurementView(Context context, String text, Drawable icon) {
|
||||
@@ -203,6 +204,10 @@ public abstract class MeasurementView extends TableLayout {
|
||||
evaluatorRow.setOnClickListener(onClickListener);
|
||||
}
|
||||
|
||||
public void setOnUpdateListener(MeasurementViewUpdateListener listener) {
|
||||
updateListener = listener;
|
||||
}
|
||||
|
||||
public abstract void updateValue(ScaleData updateData);
|
||||
public abstract void updateDiff(ScaleData updateData, ScaleData lastData);
|
||||
public abstract void updatePreferences(SharedPreferences preferences);
|
||||
@@ -302,6 +307,9 @@ public abstract class MeasurementView extends TableLayout {
|
||||
} catch (NumberFormatException e) {
|
||||
valueView.setText(value);
|
||||
}
|
||||
if (updateListener != null) {
|
||||
updateListener.onMeasurementViewUpdate(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setDiffOnView(float value, float prevValue) {
|
||||
|
@@ -0,0 +1,20 @@
|
||||
/* Copyright (C) 2017 Erik Johansson <erik@ejohansson.se>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
public interface MeasurementViewUpdateListener {
|
||||
public void onMeasurementViewUpdate(MeasurementView view);
|
||||
}
|
Reference in New Issue
Block a user