From ff152f54c22feae43c303adc573631e9bdd8fc62 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 20:31:27 +0100 Subject: [PATCH 1/8] Remove unused imports --- .../java/com/health/openscale/DatabaseMigrationTest.java | 1 - .../health/openscale/core/bluetooth/BluetoothExingtechY1.java | 2 -- .../com/health/openscale/core/bluetooth/BluetoothMiScale2.java | 1 - .../java/com/health/openscale/gui/fragments/GraphFragment.java | 1 - .../openscale/gui/preferences/MeasurementPreferences.java | 1 - .../com/health/openscale/gui/preferences/UsersPreferences.java | 2 -- 6 files changed, 8 deletions(-) diff --git a/android_app/app/src/androidTest/java/com/health/openscale/DatabaseMigrationTest.java b/android_app/app/src/androidTest/java/com/health/openscale/DatabaseMigrationTest.java index 562c14fc..001de449 100644 --- a/android_app/app/src/androidTest/java/com/health/openscale/DatabaseMigrationTest.java +++ b/android_app/app/src/androidTest/java/com/health/openscale/DatabaseMigrationTest.java @@ -17,7 +17,6 @@ package com.health.openscale; import android.arch.persistence.db.SupportSQLiteDatabase; -import android.arch.persistence.db.SupportSQLiteOpenHelper; import android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory; import android.arch.persistence.room.testing.MigrationTestHelper; import android.content.ContentValues; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java index 4b858f2a..32956ee3 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothExingtechY1.java @@ -19,8 +19,6 @@ package com.health.openscale.core.bluetooth; import android.bluetooth.BluetoothGatt; import android.bluetooth.BluetoothGattCharacteristic; import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleMeasurement; diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java index b0d6afde..abfe052f 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothMiScale2.java @@ -26,7 +26,6 @@ import android.util.Log; import com.health.openscale.core.OpenScale; import com.health.openscale.core.datatypes.ScaleMeasurement; import com.health.openscale.core.datatypes.ScaleUser; -import com.health.openscale.core.utils.Converters; import java.text.ParseException; import java.text.SimpleDateFormat; 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 98f2d935..88614fff 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 @@ -181,7 +181,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { @Override public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { case R.id.enableMonth: if (item.isChecked()) { diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/MeasurementPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/MeasurementPreferences.java index fe195dd4..a59e3254 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/MeasurementPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/MeasurementPreferences.java @@ -26,7 +26,6 @@ import android.preference.MultiSelectListPreference; import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceGroup; -import android.preference.PreferenceManager; import android.preference.SwitchPreference; import android.widget.Toast; diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/UsersPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/UsersPreferences.java index 0b37fbdf..2459ff32 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/UsersPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/UsersPreferences.java @@ -16,11 +16,9 @@ package com.health.openscale.gui.preferences; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; -import android.preference.PreferenceManager; import com.health.openscale.R; import com.health.openscale.core.OpenScale; From 29b0960b9e8b0b53ee5f5334166c0897ca464bb0 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 20:32:19 +0100 Subject: [PATCH 2/8] Specify where, if at all, in the list that date/time should be --- .../gui/activities/DataEntryActivity.java | 3 ++- .../openscale/gui/fragments/GraphFragment.java | 3 ++- .../openscale/gui/fragments/OverviewFragment.java | 13 ++----------- .../openscale/gui/fragments/TableFragment.java | 3 ++- .../openscale/gui/views/MeasurementView.java | 14 +++++++++++--- 5 files changed, 19 insertions(+), 17 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 7ca1bd65..4385dcfe 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 @@ -94,7 +94,8 @@ public class DataEntryActivity extends AppCompatActivity { tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry); - dataEntryMeasurements = MeasurementView.getMeasurementList(context); + dataEntryMeasurements = MeasurementView.getMeasurementList( + context, MeasurementView.DateTimeOrder.LAST); txtDataNr = (TextView) findViewById(R.id.txtDataNr); btnLeft = (Button) findViewById(R.id.btnLeft); 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 88614fff..56c29826 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 @@ -174,7 +174,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener { } }); - measurementViews = MeasurementView.getMeasurementList(getContext()); + measurementViews = MeasurementView.getMeasurementList( + getContext(), MeasurementView.DateTimeOrder.NONE); popup = new PopupMenu(getContext(), optionMenu); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { 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 3060c1d2..7689e84d 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 @@ -38,10 +38,8 @@ import com.health.openscale.core.datatypes.ScaleMeasurement; import com.health.openscale.core.datatypes.ScaleUser; import com.health.openscale.core.utils.Converters; import com.health.openscale.core.utils.DateTimeHelpers; -import com.health.openscale.gui.views.DateMeasurementView; import com.health.openscale.gui.views.FloatMeasurementView; import com.health.openscale.gui.views.MeasurementView; -import com.health.openscale.gui.views.TimeMeasurementView; import java.text.DateFormat; import java.util.ArrayList; @@ -120,13 +118,10 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener()); pieChartLast.setChartRotationEnabled(false); - measurementViews = MeasurementView.getMeasurementList(getContext()); + measurementViews = MeasurementView.getMeasurementList( + getContext(), MeasurementView.DateTimeOrder.NONE); for (MeasurementView measurement : measurementViews) { - if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) { - continue; - } - tableOverviewLayout.addView(measurement); } @@ -171,10 +166,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener updateLastLineChart(scaleMeasurementList); for (MeasurementView measurement : measurementViews) { - if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) { - continue; - } - measurement.updatePreferences(prefs); measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement); } 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 b53fa6a8..f8f234c1 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 @@ -112,7 +112,8 @@ public class TableFragment extends Fragment implements FragmentUpdateListener { selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY); } - measurementViews = MeasurementView.getMeasurementList(getContext()); + measurementViews = MeasurementView.getMeasurementList( + getContext(), MeasurementView.DateTimeOrder.FIRST); for (MeasurementView measurement : measurementViews) { measurement.setUpdateViews(false); 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 7d4c7e2a..5123a988 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 @@ -80,11 +80,15 @@ public abstract class MeasurementView extends TableLayout { iconView.setImageDrawable(icon); } - public static final List getMeasurementList(Context context) { + public enum DateTimeOrder { FIRST, LAST, NONE } + + public static final List getMeasurementList(Context context, DateTimeOrder order) { final List measurementViews = new ArrayList<>(); - measurementViews.add(new DateMeasurementView(context)); - measurementViews.add(new TimeMeasurementView(context)); + if (order == DateTimeOrder.FIRST) { + 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)); @@ -98,6 +102,10 @@ public abstract class MeasurementView extends TableLayout { measurementViews.add(new WHRMeasurementView(context)); measurementViews.add(new BMRMeasurementView(context)); measurementViews.add(new CommentMeasurementView(context)); + if (order == DateTimeOrder.LAST) { + measurementViews.add(new DateMeasurementView(context)); + measurementViews.add(new TimeMeasurementView(context)); + } return measurementViews; } From 53738b713b9202f66cd21907f588cd42132a1d65 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 20:58:51 +0100 Subject: [PATCH 3/8] Set edit mode before loading values Add mode needs to be set before the value is loaded, otherwise "auto" will not be properly shown. --- .../gui/activities/DataEntryActivity.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 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 4385dcfe..7142c0e0 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 @@ -72,6 +72,10 @@ public class DataEntryActivity extends AppCompatActivity { private Context context; + private boolean isAddActivity() { + return !getIntent().hasExtra(EXTRA_ID); + } + @Override protected void onCreate(Bundle savedInstanceState) { String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light"); @@ -117,12 +121,19 @@ public class DataEntryActivity extends AppCompatActivity { } }); + final MeasurementView.MeasurementViewMode mode = isAddActivity() + ? MeasurementView.MeasurementViewMode.ADD + : MeasurementView.MeasurementViewMode.VIEW; + for (MeasurementView measurement : dataEntryMeasurements) { + measurement.setEditMode(mode); + } + updateOnView(); onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - final boolean expand = getIntent().hasExtra(EXTRA_ID) - ? prefs.getBoolean(PREF_EXPAND, true) : false; + final boolean expand = isAddActivity() + ? false : prefs.getBoolean(PREF_EXPAND, true); for (MeasurementView measurement : dataEntryMeasurements) { tableLayoutDataEntry.addView(measurement); @@ -183,11 +194,11 @@ public class DataEntryActivity extends AppCompatActivity { deleteButton = menu.findItem(R.id.deleteButton); // Hide/show icons as appropriate for the view mode - if (getIntent().hasExtra(EXTRA_ID)) { - setViewMode(MeasurementView.MeasurementViewMode.VIEW); + if (isAddActivity()) { + setViewMode(MeasurementView.MeasurementViewMode.ADD); } else { - setViewMode(MeasurementView.MeasurementViewMode.ADD); + setViewMode(MeasurementView.MeasurementViewMode.VIEW); } return super.onCreateOptionsMenu(menu); From 66087b74b78f202d0158db8407e80d2dabb40122 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 20:59:48 +0100 Subject: [PATCH 4/8] Hide top date/time bar when adding new measurement --- .../health/openscale/gui/activities/DataEntryActivity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 7142c0e0..e45dfae6 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 @@ -31,6 +31,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.TableLayout; import android.widget.TextView; import android.widget.Toast; @@ -328,6 +329,7 @@ public class DataEntryActivity extends AppCompatActivity { expandButton.setVisible(true); deleteButton.setVisible(true); + ((LinearLayout)txtDataNr.getParent()).setVisibility(View.VISIBLE); btnLeft.setVisibility(View.VISIBLE); btnRight.setVisibility(View.VISIBLE); btnLeft.setEnabled(previousMeasurement != null); @@ -341,6 +343,7 @@ public class DataEntryActivity extends AppCompatActivity { expandButton.setVisible(true); deleteButton.setVisible(true); + ((LinearLayout)txtDataNr.getParent()).setVisibility(View.VISIBLE); btnLeft.setVisibility(View.VISIBLE); btnRight.setVisibility(View.VISIBLE); btnLeft.setEnabled(false); @@ -352,8 +355,7 @@ public class DataEntryActivity extends AppCompatActivity { expandButton.setVisible(false); deleteButton.setVisible(false); - btnLeft.setVisibility(View.GONE); - btnRight.setVisibility(View.GONE); + ((LinearLayout)txtDataNr.getParent()).setVisibility(View.GONE); break; } From 47edce86b781948ea7adc16206c4c79618193d87 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 21:04:05 +0100 Subject: [PATCH 5/8] Close drawer when opening settings and help --- .../src/main/java/com/health/openscale/gui/MainActivity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java index f0ca3561..367dabf8 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java @@ -280,9 +280,11 @@ public class MainActivity extends AppCompatActivity { Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra(SettingsActivity.EXTRA_TINT_COLOR, navDrawer.getItemTextColor().getDefaultColor()); startActivity(settingsIntent); + drawerLayout.closeDrawers(); return; case R.id.nav_help: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/oliexdev/openScale/wiki"))); + drawerLayout.closeDrawers(); return; default: fragmentClass = OverviewFragment.class; From ecc416e9b8878c3f04cbb70e03c68cbd948f32f0 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 21:06:55 +0100 Subject: [PATCH 6/8] Reset checked state in disableShiftMode Fixes #194. --- .../src/main/java/com/health/openscale/gui/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java index 367dabf8..2c5b5d31 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java @@ -513,7 +513,7 @@ public class MainActivity extends AppCompatActivity { item.setPadding(0, 20, 0, 0); // set once again checked value, so view will be updated //noinspection RestrictedApi - //item.setChecked(item.getItemData().isChecked()); + item.setChecked(item.getItemData().isChecked()); } } catch (NoSuchFieldException e) { Log.e("BNVHelper", "Unable to get shift mode field", e); From bd6f255335988efb4deea3e5e8cc6f6bfcab3edc Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 22:53:07 +0100 Subject: [PATCH 7/8] Recreate activity when perferences are changed --- .../health/openscale/gui/MainActivity.java | 39 +++++++++++++++++-- .../gui/activities/SettingsActivity.java | 26 ++++++++++++- .../gui/preferences/GeneralPreferences.java | 10 ----- .../app/src/main/res/values-cs/strings.xml | 3 +- .../app/src/main/res/values-de/strings.xml | 1 - .../app/src/main/res/values-es/strings.xml | 1 - .../app/src/main/res/values-sv/strings.xml | 1 - .../app/src/main/res/values/strings.xml | 1 - 8 files changed, 61 insertions(+), 21 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java index 2c5b5d31..b3579b30 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/MainActivity.java @@ -64,7 +64,8 @@ import java.lang.reflect.Field; import cat.ereza.customactivityoncrash.config.CaocConfig; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends AppCompatActivity + implements SharedPreferences.OnSharedPreferenceChangeListener{ private static boolean firstAppStart = true; private static boolean valueOfCountModified = false; private static int bluetoothStatusIcon = R.drawable.ic_bluetooth_disabled; @@ -79,7 +80,9 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + + String app_theme = prefs.getString("app_theme", "Light"); if (app_theme.equals("Dark")) { setTheme(R.style.AppTheme_Dark); @@ -137,8 +140,6 @@ public class MainActivity extends AppCompatActivity { // Setup drawer view setupDrawerContent(navDrawer); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - selectDrawerItem(prefs.getInt("lastFragmentId", R.id.nav_overview)); navBottomDrawer.setSelectedItemId(prefs.getInt("lastFragmentId", R.id.nav_overview)); @@ -182,6 +183,35 @@ public class MainActivity extends AppCompatActivity { } } + private void registerOnSharedPreferenceChangeListener() { + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); + } + + private void unregisterOnSharedPreferenceChangeListener() { + PreferenceManager.getDefaultSharedPreferences(this) + .unregisterOnSharedPreferenceChangeListener(this); + } + + @Override + public void onResume() { + super.onResume(); + // Stop listening when returning from settings + unregisterOnSharedPreferenceChangeListener(); + } + + @Override + public void onDestroy() { + // Clean up when shutting down + unregisterOnSharedPreferenceChangeListener(); + super.onDestroy(); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { + recreate(); + } + private void positiveFeedbackDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); @@ -277,6 +307,7 @@ public class MainActivity extends AppCompatActivity { prefs.edit().putInt("lastFragmentId", menuItemId).commit(); break; case R.id.nav_settings: + registerOnSharedPreferenceChangeListener(); Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra(SettingsActivity.EXTRA_TINT_COLOR, navDrawer.getItemTextColor().getDefaultColor()); startActivity(settingsIntent); diff --git a/android_app/app/src/main/java/com/health/openscale/gui/activities/SettingsActivity.java b/android_app/app/src/main/java/com/health/openscale/gui/activities/SettingsActivity.java index 43d7a05b..623311d4 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/activities/SettingsActivity.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/activities/SettingsActivity.java @@ -16,6 +16,7 @@ package com.health.openscale.gui.activities; import android.app.Fragment; +import android.content.SharedPreferences; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.os.Bundle; @@ -30,7 +31,8 @@ import com.health.openscale.gui.utils.PermissionHelper; import java.util.ArrayList; import java.util.List; -public class SettingsActivity extends PreferenceActivity { +public class SettingsActivity extends PreferenceActivity + implements SharedPreferences.OnSharedPreferenceChangeListener { public static String EXTRA_TINT_COLOR = "tintColor"; private static List fragments = new ArrayList(); private Fragment currentFragment; @@ -46,6 +48,28 @@ public class SettingsActivity extends PreferenceActivity { super.onCreate(savedInstanceState); } + @Override + public void onResume() { + super.onResume(); + PreferenceManager.getDefaultSharedPreferences(this) + .registerOnSharedPreferenceChangeListener(this); + + } + + @Override + public void onPause() { + PreferenceManager.getDefaultSharedPreferences(this) + .unregisterOnSharedPreferenceChangeListener(this); + super.onPause(); + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences preferences, String key) { + if (key.equals("app_theme")) { + recreate(); + } + } + @Override public void onBuildHeaders(List
target) { loadHeadersFromResource(R.xml.header_preferences, target); diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/GeneralPreferences.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/GeneralPreferences.java index 6ca949fd..1875f4a3 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/GeneralPreferences.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/GeneralPreferences.java @@ -44,16 +44,6 @@ public class GeneralPreferences extends PreferenceFragment implements SharedPref appThemeList = (ListPreference)findPreference(PREFERENCE_KEY_APP_THEME); - appThemeList.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object o) { - Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.info_app_restart_required), Toast.LENGTH_LONG).show(); - - return true; - } - }); - - initSummary(getPreferenceScreen()); } diff --git a/android_app/app/src/main/res/values-cs/strings.xml b/android_app/app/src/main/res/values-cs/strings.xml index 089a6c72..10f612cf 100644 --- a/android_app/app/src/main/res/values-cs/strings.xml +++ b/android_app/app/src/main/res/values-cs/strings.xml @@ -40,7 +40,7 @@ %d den %d dny %d dnů - + Uplynulých 7 dnů Uplynulých 30 dnů Rozdíl hmotnosti @@ -118,7 +118,6 @@ automaticky Téma vzhledu - Aby se změny projevily, je třeba aplikaci restartovat Připomínání Dny v týdnu diff --git a/android_app/app/src/main/res/values-de/strings.xml b/android_app/app/src/main/res/values-de/strings.xml index 6e2cc4bd..96f2c5e4 100644 --- a/android_app/app/src/main/res/values-de/strings.xml +++ b/android_app/app/src/main/res/values-de/strings.xml @@ -180,7 +180,6 @@ Fehlerinformationen Allgmein Theme - Um die Änderungen zu übernehmen, ist ein App Neustart erforderlich Teilen Suche beendet nach Bluetooth Waagen Hilfe diff --git a/android_app/app/src/main/res/values-es/strings.xml b/android_app/app/src/main/res/values-es/strings.xml index 53fedb48..a9726fdc 100644 --- a/android_app/app/src/main/res/values-es/strings.xml +++ b/android_app/app/src/main/res/values-es/strings.xml @@ -197,7 +197,6 @@ Finalizada la búsqueda de básculas Bluetooth Tema - Para aplicar los cambios se requiere un reinicio de la aplicación Ayuda diff --git a/android_app/app/src/main/res/values-sv/strings.xml b/android_app/app/src/main/res/values-sv/strings.xml index abf05fe9..43cc0b18 100644 --- a/android_app/app/src/main/res/values-sv/strings.xml +++ b/android_app/app/src/main/res/values-sv/strings.xml @@ -164,7 +164,6 @@ Allmänt Fel: namnet måste vara minst 3 tecken Tema - En app-omstart krävs för att applicera ändringarna Uppskattar du openScale? Vad sägs om ett betyg på GooglePlay eller på GitHub? Skulle du ha något emot att ge oss lite återkoppling? diff --git a/android_app/app/src/main/res/values/strings.xml b/android_app/app/src/main/res/values/strings.xml index 4b2e84b1..f8b51019 100644 --- a/android_app/app/src/main/res/values/strings.xml +++ b/android_app/app/src/main/res/values/strings.xml @@ -155,7 +155,6 @@ auto Theme - To apply changes an app restart is required Reminder Weekdays From 18559bb57a606de618d499588cc21b3e724fedb0 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 23:00:57 +0100 Subject: [PATCH 8/8] 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; }