From 18559bb57a606de618d499588cc21b3e724fedb0 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 23:00:57 +0100 Subject: [PATCH] Load preferences only when creating measurement views --- .../health/openscale/gui/activities/DataEntryActivity.java | 6 ------ .../com/health/openscale/gui/fragments/GraphFragment.java | 1 - .../health/openscale/gui/fragments/OverviewFragment.java | 4 ---- .../com/health/openscale/gui/fragments/TableFragment.java | 1 - .../com/health/openscale/gui/views/MeasurementView.java | 7 +++++++ 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java index e45dfae6..521f37b2 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/activities/DataEntryActivity.java @@ -261,12 +261,6 @@ public class DataEntryActivity extends AppCompatActivity { } private void updateOnView() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - - for (MeasurementView measurement : dataEntryMeasurements) { - measurement.updatePreferences(prefs); - } - int id = 0; if (getIntent().hasExtra(EXTRA_ID)) { id = getIntent().getExtras().getInt(EXTRA_ID); 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 56c29826..57b36677 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 @@ -315,7 +315,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { continue; } - measurementView.updatePreferences(prefs); Stack valuesStack = new Stack(); for (ScaleMeasurement measurement : scaleMeasurementList) { 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 7689e84d..32fadec2 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 @@ -166,7 +166,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener updateLastLineChart(scaleMeasurementList); for (MeasurementView measurement : measurementViews) { - measurement.updatePreferences(prefs); measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement); } } @@ -221,8 +220,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener continue; } - measurementView.updatePreferences(prefs); - Stack valuesStack = new Stack(); scaleMeasurementLastDays = new ArrayList<>(); @@ -283,7 +280,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener continue; } - measurementView.updatePreferences(prefs); measurementView.loadFrom(lastScaleMeasurement, null); if (measurementView.getValue() != 0) { diff --git a/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java index f8f234c1..21b1c849 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/fragments/TableFragment.java @@ -219,7 +219,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { ArrayList visibleMeasurements = new ArrayList<>(); for (MeasurementView measurement : measurementViews) { - measurement.updatePreferences(prefs); if (measurement.isVisible()) { ImageView headerIcon = new ImageView(tableView.getContext()); diff --git a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java index 5123a988..47172537 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/views/MeasurementView.java @@ -22,6 +22,7 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; import android.text.SpannableStringBuilder; import android.util.TypedValue; @@ -107,6 +108,12 @@ public abstract class MeasurementView extends TableLayout { measurementViews.add(new TimeMeasurementView(context)); } + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + for (MeasurementView measurement : measurementViews) { + measurement.updatePreferences(prefs); + } + return measurementViews; }