diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java index 986b6a1bbd..950c838ea4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBg.java @@ -80,6 +80,9 @@ public class InputBg extends Element { decimalFormat = new DecimalFormat("0"); } + // make sure that value is in range + textWatcher.afterTextChanged(null); + this.units = units; return this; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java index 242733c16d..2fb307f6a9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBg.java @@ -102,10 +102,10 @@ public class TriggerBg extends Trigger { Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); + bg.setUnits(JsonHelper.safeGetString(d, "units")); bg.setValue(JsonHelper.safeGetDouble(d, "bg")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); - bg.setUnits(JsonHelper.safeGetString(d, "units")); } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java index f4f7c21f7d..e3bbfeb7c8 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.java @@ -18,7 +18,7 @@ public class InputBgTest { @Test public void textWatcherTest() { - InputBg t = new InputBg().setValue(1d).setUnits(Constants.MMOL); + InputBg t = new InputBg().setUnits(Constants.MMOL).setValue(1d); t.textWatcher.beforeTextChanged(null, 0, 0, 0); t.textWatcher.onTextChanged(null, 0, 0, 0); t.textWatcher.afterTextChanged(null); @@ -31,7 +31,7 @@ public class InputBgTest { @Test public void getSetValueTest() { - InputBg i = new InputBg().setValue(5d).setUnits(Constants.MMOL); + InputBg i = new InputBg().setUnits(Constants.MMOL).setValue(5d); Assert.assertEquals(5d, i.getValue(), 0.01d); Assert.assertEquals(2, i.minValue, 0.01d); i = new InputBg().setValue(100d).setUnits(Constants.MGDL);