mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 03:30:30 +02:00
get measurements list for all fragments from a central point.
This commit is contained in:
@@ -43,19 +43,8 @@ import com.health.openscale.core.OpenScale;
|
|||||||
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||||
import com.health.openscale.core.utils.PolynomialFitter;
|
import com.health.openscale.core.utils.PolynomialFitter;
|
||||||
import com.health.openscale.gui.activities.DataEntryActivity;
|
import com.health.openscale.gui.activities.DataEntryActivity;
|
||||||
import com.health.openscale.gui.views.BMIMeasurementView;
|
|
||||||
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.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.MeasurementView;
|
||||||
import com.health.openscale.gui.views.MuscleMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WHRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WHtRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaistMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaterMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WeightMeasurementView;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -94,7 +83,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
private PopupMenu popup;
|
private PopupMenu popup;
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
private ArrayList<MeasurementView> measurementViews;
|
private List<MeasurementView> measurementViews;
|
||||||
|
|
||||||
private int textColor;
|
private int textColor;
|
||||||
|
|
||||||
@@ -147,20 +136,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
|
|
||||||
floatingActionBar = (LinearLayout) graphView.findViewById(R.id.floatingActionBar);
|
floatingActionBar = (LinearLayout) graphView.findViewById(R.id.floatingActionBar);
|
||||||
|
|
||||||
measurementViews = new ArrayList<>();
|
|
||||||
|
|
||||||
measurementViews.add(new WeightMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new BMIMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new WaterMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new MuscleMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new LBWMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new FatMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new BoneMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new WaistMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new WHtRMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new HipMeasurementView(getContext()));
|
|
||||||
measurementViews.add(new WHRMeasurementView(getContext()));
|
|
||||||
|
|
||||||
optionMenu = (ImageView) graphView.findViewById(R.id.optionMenu);
|
optionMenu = (ImageView) graphView.findViewById(R.id.optionMenu);
|
||||||
optionMenu.setOnClickListener(new View.OnClickListener() {
|
optionMenu.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -180,7 +155,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
if (!scaleMeasurementList.isEmpty()) {
|
if (!scaleMeasurementList.isEmpty()) {
|
||||||
calLastSelected.setTime(scaleMeasurementList.get(0).getDateTime());
|
calLastSelected.setTime(scaleMeasurementList.get(0).getDateTime());
|
||||||
}
|
}
|
||||||
updateOnView(null);
|
generateGraphs();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -195,10 +170,12 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
if (!scaleMeasurementList.isEmpty()) {
|
if (!scaleMeasurementList.isEmpty()) {
|
||||||
calLastSelected.setTime(scaleMeasurementList.get(scaleMeasurementList.size() - 1).getDateTime());
|
calLastSelected.setTime(scaleMeasurementList.get(scaleMeasurementList.size() - 1).getDateTime());
|
||||||
}
|
}
|
||||||
updateOnView(null);
|
generateGraphs();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
measurementViews = MeasurementView.getMeasurementList(getContext());
|
||||||
|
|
||||||
popup = new PopupMenu(getContext(), optionMenu);
|
popup = new PopupMenu(getContext(), optionMenu);
|
||||||
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@@ -38,20 +38,10 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
import com.health.openscale.core.utils.Converters;
|
import com.health.openscale.core.utils.Converters;
|
||||||
import com.health.openscale.core.utils.DateTimeHelpers;
|
import com.health.openscale.core.utils.DateTimeHelpers;
|
||||||
import com.health.openscale.gui.views.BMIMeasurementView;
|
import com.health.openscale.gui.views.DateMeasurementView;
|
||||||
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.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.MeasurementView;
|
||||||
import com.health.openscale.gui.views.MuscleMeasurementView;
|
import com.health.openscale.gui.views.TimeMeasurementView;
|
||||||
import com.health.openscale.gui.views.WHRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WHtRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaistMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaterMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WeightMeasurementView;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -82,7 +72,7 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
|
|
||||||
private TableLayout tableOverviewLayout;
|
private TableLayout tableOverviewLayout;
|
||||||
|
|
||||||
private ArrayList<MeasurementView> measurementViews;
|
private List<MeasurementView> measurementViews;
|
||||||
|
|
||||||
private PieChartView pieChartLast;
|
private PieChartView pieChartLast;
|
||||||
private LineChartView lineChartLast;
|
private LineChartView lineChartLast;
|
||||||
@@ -120,25 +110,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
|
|
||||||
tableOverviewLayout = (TableLayout)overviewView.findViewById(R.id.tableLayoutMeasurements);
|
tableOverviewLayout = (TableLayout)overviewView.findViewById(R.id.tableLayoutMeasurements);
|
||||||
|
|
||||||
measurementViews = new ArrayList<>();
|
|
||||||
|
|
||||||
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 : measurementViews) {
|
|
||||||
tableOverviewLayout.addView(measurement);
|
|
||||||
}
|
|
||||||
|
|
||||||
pieChartLast = (PieChartView) overviewView.findViewById(R.id.pieChartLast);
|
pieChartLast = (PieChartView) overviewView.findViewById(R.id.pieChartLast);
|
||||||
lineChartLast = (LineChartView) overviewView.findViewById(R.id.lineChartLast);
|
lineChartLast = (LineChartView) overviewView.findViewById(R.id.lineChartLast);
|
||||||
|
|
||||||
@@ -149,6 +120,12 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener());
|
pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener());
|
||||||
pieChartLast.setChartRotationEnabled(false);
|
pieChartLast.setChartRotationEnabled(false);
|
||||||
|
|
||||||
|
measurementViews = MeasurementView.getMeasurementList(getContext());
|
||||||
|
|
||||||
|
for (MeasurementView measurement : measurementViews) {
|
||||||
|
tableOverviewLayout.addView(measurement);
|
||||||
|
}
|
||||||
|
|
||||||
userSelectedData = null;
|
userSelectedData = null;
|
||||||
|
|
||||||
spinUserAdapter = new ArrayAdapter<>(overviewView.getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<String>());
|
spinUserAdapter = new ArrayAdapter<>(overviewView.getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<String>());
|
||||||
@@ -162,6 +139,8 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
|
||||||
|
|
||||||
OpenScale.getInstance(getContext()).registerFragment(this);
|
OpenScale.getInstance(getContext()).registerFragment(this);
|
||||||
|
|
||||||
return overviewView;
|
return overviewView;
|
||||||
@@ -177,8 +156,17 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
lastScaleMeasurement = scaleMeasurementList.get(0);
|
lastScaleMeasurement = scaleMeasurementList.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
|
||||||
|
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
|
for (MeasurementView measurement : measurementViews) {
|
||||||
|
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
measurement.updatePreferences(prefs);
|
||||||
|
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
|
||||||
|
}
|
||||||
|
|
||||||
txtTitleUser.setText(getResources().getString(R.string.label_title_user).toUpperCase());
|
txtTitleUser.setText(getResources().getString(R.string.label_title_user).toUpperCase());
|
||||||
txtTitleLastMeasurement.setText(getResources().getString(R.string.label_title_last_measurement).toUpperCase());
|
txtTitleLastMeasurement.setText(getResources().getString(R.string.label_title_last_measurement).toUpperCase());
|
||||||
@@ -186,14 +174,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
updateUserSelection();
|
updateUserSelection();
|
||||||
updateLastPieChart();
|
updateLastPieChart();
|
||||||
updateLastLineChart(scaleMeasurementList);
|
updateLastLineChart(scaleMeasurementList);
|
||||||
|
|
||||||
ScaleMeasurement[] tupleScaleData = OpenScale.getInstance(context).getTupleScaleData(lastScaleMeasurement.getId());
|
|
||||||
ScaleMeasurement prevScaleMeasurement = tupleScaleData[0];
|
|
||||||
|
|
||||||
for (MeasurementView measurement : measurementViews) {
|
|
||||||
measurement.updatePreferences(prefs);
|
|
||||||
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserSelection() {
|
private void updateUserSelection() {
|
||||||
@@ -226,7 +206,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
|
|||||||
|
|
||||||
|
|
||||||
private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
|
private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
|
||||||
|
|
||||||
int max_i = 7;
|
int max_i = 7;
|
||||||
|
|
||||||
if (scaleMeasurementList.size() < 7) {
|
if (scaleMeasurementList.size() < 7) {
|
||||||
|
@@ -57,22 +57,7 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
import com.health.openscale.gui.activities.DataEntryActivity;
|
import com.health.openscale.gui.activities.DataEntryActivity;
|
||||||
import com.health.openscale.gui.utils.PermissionHelper;
|
import com.health.openscale.gui.utils.PermissionHelper;
|
||||||
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.CommentMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.DateMeasurementView;
|
|
||||||
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.MeasurementView;
|
||||||
import com.health.openscale.gui.views.MuscleMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.TimeMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WHRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WHtRMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaistMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WaterMeasurementView;
|
|
||||||
import com.health.openscale.gui.views.WeightMeasurementView;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -92,7 +77,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
private ImageView optionMenu;
|
private ImageView optionMenu;
|
||||||
private PopupMenu popup;
|
private PopupMenu popup;
|
||||||
|
|
||||||
private ArrayList <MeasurementView> measurementsList;
|
private List<MeasurementView> measurementViews;
|
||||||
|
|
||||||
private int selectedSubpageNr;
|
private int selectedSubpageNr;
|
||||||
private static final String SELECTED_SUBPAGE_NR_KEY = "selectedSubpageNr";
|
private static final String SELECTED_SUBPAGE_NR_KEY = "selectedSubpageNr";
|
||||||
@@ -118,28 +103,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
|
|
||||||
optionMenu = (ImageView) tableView.findViewById(R.id.optionMenu);
|
optionMenu = (ImageView) tableView.findViewById(R.id.optionMenu);
|
||||||
|
|
||||||
measurementsList = new ArrayList<>();
|
|
||||||
|
|
||||||
measurementsList.add(new DateMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new TimeMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new WeightMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new BMIMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new WaterMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new MuscleMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new LBWMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new FatMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new BoneMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new WaistMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new WHtRMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new HipMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new WHRMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new BMRMeasurementView(tableView.getContext()));
|
|
||||||
measurementsList.add(new CommentMeasurementView(tableView.getContext()));
|
|
||||||
|
|
||||||
for (MeasurementView measurement : measurementsList) {
|
|
||||||
measurement.setUpdateViews(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(tableView.getContext());
|
prefs = PreferenceManager.getDefaultSharedPreferences(tableView.getContext());
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
@@ -149,6 +112,12 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY);
|
selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
measurementViews = MeasurementView.getMeasurementList(getContext());
|
||||||
|
|
||||||
|
for (MeasurementView measurement : measurementViews) {
|
||||||
|
measurement.setUpdateViews(false);
|
||||||
|
}
|
||||||
|
|
||||||
optionMenu.setOnClickListener(new View.OnClickListener() {
|
optionMenu.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -248,7 +217,7 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
tableHeaderView.removeAllViews();
|
tableHeaderView.removeAllViews();
|
||||||
|
|
||||||
ArrayList<MeasurementView> visibleMeasurements = new ArrayList<>();
|
ArrayList<MeasurementView> visibleMeasurements = new ArrayList<>();
|
||||||
for (MeasurementView measurement : measurementsList) {
|
for (MeasurementView measurement : measurementViews) {
|
||||||
measurement.updatePreferences(prefs);
|
measurement.updatePreferences(prefs);
|
||||||
|
|
||||||
if (measurement.isVisible()) {
|
if (measurement.isVisible()) {
|
||||||
|
@@ -43,6 +43,9 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
|||||||
import com.health.openscale.core.datatypes.ScaleUser;
|
import com.health.openscale.core.datatypes.ScaleUser;
|
||||||
import com.health.openscale.core.evaluation.EvaluationResult;
|
import com.health.openscale.core.evaluation.EvaluationResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import lecho.lib.hellocharts.util.ChartUtils;
|
import lecho.lib.hellocharts.util.ChartUtils;
|
||||||
|
|
||||||
import static com.health.openscale.gui.views.MeasurementView.MeasurementViewMode.ADD;
|
import static com.health.openscale.gui.views.MeasurementView.MeasurementViewMode.ADD;
|
||||||
@@ -77,6 +80,28 @@ public abstract class MeasurementView extends TableLayout {
|
|||||||
iconView.setImageDrawable(icon);
|
iconView.setImageDrawable(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final List<MeasurementView> getMeasurementList(Context context) {
|
||||||
|
final List<MeasurementView> measurementViews = new ArrayList<>();
|
||||||
|
|
||||||
|
measurementViews.add(new DateMeasurementView(context));
|
||||||
|
measurementViews.add(new TimeMeasurementView(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));
|
||||||
|
measurementViews.add(new CommentMeasurementView(context));
|
||||||
|
|
||||||
|
return measurementViews;
|
||||||
|
}
|
||||||
|
|
||||||
private void initView(Context context) {
|
private void initView(Context context) {
|
||||||
measurementRow = new TableRow(context);
|
measurementRow = new TableRow(context);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user