From e295c8a2dc93c006aab735bcb497c9779d774fcd Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sat, 5 Aug 2017 18:09:19 +0200 Subject: [PATCH] target range change confirm dialog --- .../nightscout/androidaps/MainActivity.java | 25 +++++++++++++++++++ .../main/java/info/nightscout/utils/SP.java | 14 +++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java index c4b93657d3..528cbd21bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java @@ -36,6 +36,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import info.nightscout.androidaps.Services.AlarmSoundService; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; @@ -79,6 +80,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe Manifest.permission.WRITE_EXTERNAL_STORAGE}, CASE_STORAGE); } askForBatteryOptimizationPermission(); + checkUpgradeToProfileTarget(); if (Config.logFunctionCalls) log.debug("onCreate"); @@ -154,6 +156,29 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe } } + private void checkUpgradeToProfileTarget() { // TODO: can be removed in the future + boolean oldKeyExists = SP.contains("openapsma_min_bg"); + if (oldKeyExists) { + Profile profile = MainApp.getConfigBuilder().getProfile(); + String oldRange = SP.getDouble("openapsma_min_bg", 0d) + " - " + SP.getDouble("openapsma_max_bg", 0d); + String newRange = ""; + if (profile != null) { + newRange = profile.getTargetLow() + " - " + profile.getTargetHigh(); + } + String message = "Target range is changed in current version.\n\nIt's not taken from preferences but from profile.\n\n!!! REVIEW YOUR SETTINGS !!!"; + message += "\n\nOld settings: " + oldRange; + message += "\nProfile settings: " + newRange; + OKDialog.show(this, "Target range change", message, new Runnable() { + @Override + public void run() { + SP.remove("openapsma_min_bg"); + SP.remove("openapsma_max_bg"); + SP.remove("openapsma_target_bg"); + } + }); + } + } + //check for sms permission if enable in prefernces @Subscribe public void onStatusEvent(final EventPreferenceChange ev) { diff --git a/app/src/main/java/info/nightscout/utils/SP.java b/app/src/main/java/info/nightscout/utils/SP.java index acb727d864..36ab3b05e7 100644 --- a/app/src/main/java/info/nightscout/utils/SP.java +++ b/app/src/main/java/info/nightscout/utils/SP.java @@ -88,12 +88,6 @@ public class SP { editor.apply(); } - static public void removeBoolean(int resourceID) { - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.remove(MainApp.sResources.getString(resourceID)); - editor.apply(); - } - static public void putLong(String key, long value) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putLong(key, value); @@ -130,9 +124,15 @@ public class SP { editor.apply(); } - static public void removeString(int resourceID) { + static public void remove(int resourceID) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.remove(MainApp.sResources.getString(resourceID)); editor.apply(); } + + static public void remove(String key) { + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.remove(key); + editor.apply(); + } }