target range change confirm dialog

This commit is contained in:
Milos Kozak 2017-08-05 18:09:19 +02:00
parent f834b3b7e0
commit e295c8a2dc
2 changed files with 32 additions and 7 deletions

View file

@ -36,6 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Services.AlarmSoundService; import info.nightscout.androidaps.Services.AlarmSoundService;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.events.EventAppExit; import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshGui; 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); Manifest.permission.WRITE_EXTERNAL_STORAGE}, CASE_STORAGE);
} }
askForBatteryOptimizationPermission(); askForBatteryOptimizationPermission();
checkUpgradeToProfileTarget();
if (Config.logFunctionCalls) if (Config.logFunctionCalls)
log.debug("onCreate"); 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 //check for sms permission if enable in prefernces
@Subscribe @Subscribe
public void onStatusEvent(final EventPreferenceChange ev) { public void onStatusEvent(final EventPreferenceChange ev) {

View file

@ -88,12 +88,6 @@ public class SP {
editor.apply(); 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) { static public void putLong(String key, long value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(key, value); editor.putLong(key, value);
@ -130,9 +124,15 @@ public class SP {
editor.apply(); editor.apply();
} }
static public void removeString(int resourceID) { static public void remove(int resourceID) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(MainApp.sResources.getString(resourceID)); editor.remove(MainApp.sResources.getString(resourceID));
editor.apply(); editor.apply();
} }
static public void remove(String key) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(key);
editor.apply();
}
} }