diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java index 1d18cd14b4..9cc553dfd0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java @@ -42,6 +42,13 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface public boolean pumpStatusIsAvailableInNS = false; public Integer manualEnacts = 0; + public static final int FIRST_OBJECTIVE = 0; + public static final int CLOSED_LOOP_OBJECTIVE = 3; + public static final int MAXIOB_ZERO_OBJECTIVE = 3; + public static final int AUTOSENS_OBJECTIVE = 5; + public static final int AMA_OBJECTIVE = 6; + public static final int SMB_OBJECTIVE = 7; + public static ObjectivesPlugin getPlugin() { if (objectivesPlugin == null) { objectivesPlugin = new ObjectivesPlugin(); @@ -121,43 +128,43 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface **/ @Override public Constraint isLoopInvocationAllowed(Constraint value) { - if (!objectives.get(0).isStarted()) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 1), this); + if (!objectives.get(FIRST_OBJECTIVE).isStarted()) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this); return value; } @Override public Constraint isClosedLoopAllowed(Constraint value) { - if (!objectives.get(3).isStarted()) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 4), this); + if (!objectives.get(CLOSED_LOOP_OBJECTIVE).isStarted()) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), CLOSED_LOOP_OBJECTIVE + 1), this); return value; } @Override public Constraint isAutosensModeEnabled(Constraint value) { - if (!objectives.get(5).isStarted()) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6), this); + if (!objectives.get(AUTOSENS_OBJECTIVE).isStarted()) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this); return value; } @Override public Constraint isAMAModeEnabled(Constraint value) { - if (!objectives.get(6).isStarted()) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 7), this); + if (!objectives.get(AMA_OBJECTIVE).isStarted()) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this); return value; } @Override public Constraint isSMBModeEnabled(Constraint value) { - if (!objectives.get(7).isStarted()) - value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 8), this); + if (!objectives.get(SMB_OBJECTIVE).isStarted()) + value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this); return value; } @Override public Constraint applyMaxIOBConstraints(Constraint maxIob) { - if (objectives.get(3).isStarted() && !objectives.get(3).isAccomplished()) - maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), 4), this); + if (objectives.get(MAXIOB_ZERO_OBJECTIVE).isStarted() && !objectives.get(MAXIOB_ZERO_OBJECTIVE).isAccomplished()) + maxIob.set(0d, String.format(MainApp.gs(R.string.objectivenotfinished), MAXIOB_ZERO_OBJECTIVE + 1), this); return maxIob; } 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 cbc0af6491..065f56e803 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.java @@ -425,8 +425,8 @@ public class SWDefinition { .add(new SWBreak()) .add(new SWFragment(this) .add(new ObjectivesFragment())) - .validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted()) - .visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted() && Config.APS); + .validator(() -> ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted()) + .visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).isStarted() && Config.APS); private void SWDefinitionFull() { // List all the screens here 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 edfd30180a..a0e595cd97 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(R.string.key_aps_mode, "open")).thenReturn("closed"); - objectivesPlugin.objectives.get(3).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null); Constraint c = constraintChecker.isClosedLoopAllowed(); Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives @@ -91,7 +91,7 @@ public class ConstraintsCheckerTest { @Test public void isAutosensModeEnabledTest() throws Exception { - objectivesPlugin.objectives.get(5).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null); when(SP.getBoolean(R.string.key_openapsama_useautosens, false)).thenReturn(false); Constraint c = constraintChecker.isAutosensModeEnabled(); @@ -102,7 +102,7 @@ public class ConstraintsCheckerTest { @Test public void isAMAModeEnabledTest() throws Exception { - objectivesPlugin.objectives.get(6).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null); Constraint c = constraintChecker.isAMAModeEnabled(); Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives @@ -130,7 +130,7 @@ public class ConstraintsCheckerTest { @Test public void isSMBModeEnabledTest() throws Exception { - objectivesPlugin.objectives.get(7).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null); when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false); when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true)); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java index 913b8fdda0..a6bbd98122 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java @@ -28,18 +28,18 @@ public class ObjectivesPluginTest { @Test public void notStartedObjectivesShouldLimitLoopInvocation() throws Exception { - objectivesPlugin.objectives.get(0).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(null); Constraint c = new Constraint<>(true); c = objectivesPlugin.isLoopInvocationAllowed(c); Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons()); Assert.assertEquals(Boolean.FALSE, c.value()); - objectivesPlugin.objectives.get(0).setStartedOn(new Date()); + objectivesPlugin.objectives.get(ObjectivesPlugin.FIRST_OBJECTIVE).setStartedOn(new Date()); } @Test public void notStartedObjective4ShouldLimitClosedLoop() throws Exception { - objectivesPlugin.objectives.get(3).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null); Constraint c = new Constraint<>(true); c = objectivesPlugin.isClosedLoopAllowed(c); @@ -49,7 +49,7 @@ public class ObjectivesPluginTest { @Test public void notStartedObjective6ShouldLimitAutosensMode() throws Exception { - objectivesPlugin.objectives.get(5).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.AUTOSENS_OBJECTIVE).setStartedOn(null); Constraint c = new Constraint<>(true); c = objectivesPlugin.isAutosensModeEnabled(c); @@ -59,7 +59,7 @@ public class ObjectivesPluginTest { @Test public void notStartedObjective7ShouldLimitAMAMode() throws Exception { - objectivesPlugin.objectives.get(6).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.AMA_OBJECTIVE).setStartedOn(null); Constraint c = new Constraint<>(true); c = objectivesPlugin.isAMAModeEnabled(c); @@ -69,7 +69,7 @@ public class ObjectivesPluginTest { @Test public void notStartedObjective8ShouldLimitSMBMode() throws Exception { - objectivesPlugin.objectives.get(7).setStartedOn(null); + objectivesPlugin.objectives.get(ObjectivesPlugin.SMB_OBJECTIVE).setStartedOn(null); Constraint c = new Constraint<>(true); c = objectivesPlugin.isSMBModeEnabled(c);