From 31e050be4a4431aaa38704ec5ca4638f40c2a29f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 14 Aug 2018 17:06:09 +0200 Subject: [PATCH] loop mode in setup wizard --- .../plugins/ConstraintsSafety/SafetyPlugin.java | 2 +- .../androidaps/setupwizard/SWDefinition.java | 8 ++++++++ .../setupwizard/elements/SWRadioButton.java | 11 +++++++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_closedmode.xml | 2 +- .../androidaps/interfaces/ConstraintsCheckerTest.java | 4 ++-- .../plugins/ConstraintsSafety/SafetyPluginTest.java | 8 ++++---- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java index 3d17970edc..f76673197e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPlugin.java @@ -57,7 +57,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface { @Override public Constraint isClosedLoopAllowed(Constraint value) { - String mode = SP.getString("aps_mode", "open"); + String mode = SP.getString(R.string.key_aps_mode, "open"); if (!mode.equals("closed")) value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this); diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java index ca1ef02fda..8f453b8268 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -365,6 +365,14 @@ public class SWDefinition { .validator(() -> MainApp.getConfigBuilder().getActiveAPS() != null) .visibility(() -> Config.APS) ) + .add(new SWScreen(R.string.apsmode_title) + .skippable(false) + .add(new SWRadioButton() + .option(R.array.aps_modeArray, R.array.aps_modeValues) + .preferenceId(R.string.key_aps_mode).label(R.string.apsmode_title) + .comment(R.string.setupwizard_preferred_aps_mode)) + .validator(() -> SP.contains(R.string.key_aps_mode)) + ) .add(new SWScreen(R.string.configbuilder_loop) .skippable(false) .add(new SWInfotext() diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java index 80346c433c..5282068094 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/elements/SWRadioButton.java @@ -2,9 +2,11 @@ package info.nightscout.androidaps.setupwizard.elements; import android.content.Context; import android.view.View; +import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.TextView; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +42,14 @@ public class SWRadioButton extends SWItem { @Override public void generateDialog(LinearLayout layout) { Context context = layout.getContext(); + + TextView pdesc = new TextView(context); + pdesc.setText(getComment()); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + params.setMargins(0, 0, 0, 40); + pdesc.setLayoutParams(params); + layout.addView(pdesc); + // Get if there is already value in SP String previousValue = SP.getString(preferenceId, "none"); radioGroup = new RadioGroup(context); @@ -62,6 +72,7 @@ public class SWRadioButton extends SWItem { save(values()[i]); }); layout.addView(radioGroup); + super.generateDialog(layout); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6a0d322a6..26952b922c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1183,6 +1183,8 @@ AS Version %1$s available Time offset + aps_mode + Preferred APS mode %1$d day diff --git a/app/src/main/res/xml/pref_closedmode.xml b/app/src/main/res/xml/pref_closedmode.xml index d0e3ac25e6..7d33941885 100644 --- a/app/src/main/res/xml/pref_closedmode.xml +++ b/app/src/main/res/xml/pref_closedmode.xml @@ -6,7 +6,7 @@ diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java index 9258f9c308..f79e99e06a 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java @@ -75,7 +75,7 @@ public class ConstraintsCheckerTest { @Test public void isClosedLoopAllowedTest() throws Exception { - when(SP.getString("aps_mode", "open")).thenReturn("closed"); + when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed"); objectivesPlugin.objectives.get(3).setStartedOn(null); Constraint c = constraintChecker.isClosedLoopAllowed(); @@ -83,7 +83,7 @@ public class ConstraintsCheckerTest { Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 2); // Safety & Objectives Assert.assertEquals(Boolean.FALSE, c.value()); - when(SP.getString("aps_mode", "open")).thenReturn("open"); + when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("open"); c = constraintChecker.isClosedLoopAllowed(); Assert.assertEquals(true, c.getReasonList().size() == 3); // 2x Safety & Objectives Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 3); // 2x Safety & Objectives diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java index 77a91046ab..ae350c4fe6 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/ConstraintsSafety/SafetyPluginTest.java @@ -47,8 +47,8 @@ public class SafetyPluginTest { } @Test - public void disabledEngineeringModeShouldLimitClosedLoop() throws Exception { - when(SP.getString("aps_mode", "open")).thenReturn("closed"); + public void disabledEngineeringModeShouldLimitClosedLoop() { + when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed"); when(MainApp.isEngineeringModeOrRelease()).thenReturn(false); Constraint c = new Constraint<>(true); @@ -58,8 +58,8 @@ public class SafetyPluginTest { } @Test - public void setOpenLoopInPreferencesShouldLimitClosedLoop() throws Exception { - when(SP.getString("aps_mode", "open")).thenReturn("open"); + public void setOpenLoopInPreferencesShouldLimitClosedLoop() { + when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("open"); Constraint c = new Constraint<>(true); c = safetyPlugin.isClosedLoopAllowed(c);