From 53738b713b9202f66cd21907f588cd42132a1d65 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Sun, 18 Feb 2018 20:58:51 +0100 Subject: [PATCH] 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);