loop mode in setup wizard
This commit is contained in:
parent
04af3eb806
commit
31e050be4a
7 changed files with 29 additions and 8 deletions
|
@ -57,7 +57,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) {
|
||||||
String mode = SP.getString("aps_mode", "open");
|
String mode = SP.getString(R.string.key_aps_mode, "open");
|
||||||
if (!mode.equals("closed"))
|
if (!mode.equals("closed"))
|
||||||
value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this);
|
value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this);
|
||||||
|
|
||||||
|
|
|
@ -365,6 +365,14 @@ public class SWDefinition {
|
||||||
.validator(() -> MainApp.getConfigBuilder().getActiveAPS() != null)
|
.validator(() -> MainApp.getConfigBuilder().getActiveAPS() != null)
|
||||||
.visibility(() -> Config.APS)
|
.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)
|
.add(new SWScreen(R.string.configbuilder_loop)
|
||||||
.skippable(false)
|
.skippable(false)
|
||||||
.add(new SWInfotext()
|
.add(new SWInfotext()
|
||||||
|
|
|
@ -2,9 +2,11 @@ package info.nightscout.androidaps.setupwizard.elements;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
import android.widget.RadioGroup;
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -40,6 +42,14 @@ public class SWRadioButton extends SWItem {
|
||||||
@Override
|
@Override
|
||||||
public void generateDialog(LinearLayout layout) {
|
public void generateDialog(LinearLayout layout) {
|
||||||
Context context = layout.getContext();
|
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
|
// Get if there is already value in SP
|
||||||
String previousValue = SP.getString(preferenceId, "none");
|
String previousValue = SP.getString(preferenceId, "none");
|
||||||
radioGroup = new RadioGroup(context);
|
radioGroup = new RadioGroup(context);
|
||||||
|
@ -62,6 +72,7 @@ public class SWRadioButton extends SWItem {
|
||||||
save(values()[i]);
|
save(values()[i]);
|
||||||
});
|
});
|
||||||
layout.addView(radioGroup);
|
layout.addView(radioGroup);
|
||||||
|
|
||||||
super.generateDialog(layout);
|
super.generateDialog(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1183,6 +1183,8 @@
|
||||||
<string name="as">AS</string>
|
<string name="as">AS</string>
|
||||||
<string name="versionavailable">Version %1$s available</string>
|
<string name="versionavailable">Version %1$s available</string>
|
||||||
<string name="time_offset">Time offset</string>
|
<string name="time_offset">Time offset</string>
|
||||||
|
<string name="key_aps_mode" translatable="false">aps_mode</string>
|
||||||
|
<string name="setupwizard_preferred_aps_mode">Preferred APS mode</string>
|
||||||
|
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:title="@string/apsmode_title"
|
android:title="@string/apsmode_title"
|
||||||
android:key="aps_mode"
|
android:key="@string/key_aps_mode"
|
||||||
android:defaultValue="open"
|
android:defaultValue="open"
|
||||||
android:entries="@array/aps_modeArray"
|
android:entries="@array/aps_modeArray"
|
||||||
android:entryValues="@array/aps_modeValues"/>
|
android:entryValues="@array/aps_modeValues"/>
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isClosedLoopAllowedTest() throws Exception {
|
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);
|
objectivesPlugin.objectives.get(3).setStartedOn(null);
|
||||||
|
|
||||||
Constraint<Boolean> c = constraintChecker.isClosedLoopAllowed();
|
Constraint<Boolean> c = constraintChecker.isClosedLoopAllowed();
|
||||||
|
@ -83,7 +83,7 @@ public class ConstraintsCheckerTest {
|
||||||
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 2); // Safety & Objectives
|
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 2); // Safety & Objectives
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
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();
|
c = constraintChecker.isClosedLoopAllowed();
|
||||||
Assert.assertEquals(true, c.getReasonList().size() == 3); // 2x Safety & Objectives
|
Assert.assertEquals(true, c.getReasonList().size() == 3); // 2x Safety & Objectives
|
||||||
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 3); // 2x Safety & Objectives
|
Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 3); // 2x Safety & Objectives
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class SafetyPluginTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disabledEngineeringModeShouldLimitClosedLoop() throws Exception {
|
public void disabledEngineeringModeShouldLimitClosedLoop() {
|
||||||
when(SP.getString("aps_mode", "open")).thenReturn("closed");
|
when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed");
|
||||||
when(MainApp.isEngineeringModeOrRelease()).thenReturn(false);
|
when(MainApp.isEngineeringModeOrRelease()).thenReturn(false);
|
||||||
|
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
|
@ -58,8 +58,8 @@ public class SafetyPluginTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setOpenLoopInPreferencesShouldLimitClosedLoop() throws Exception {
|
public void setOpenLoopInPreferencesShouldLimitClosedLoop() {
|
||||||
when(SP.getString("aps_mode", "open")).thenReturn("open");
|
when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("open");
|
||||||
|
|
||||||
Constraint<Boolean> c = new Constraint<>(true);
|
Constraint<Boolean> c = new Constraint<>(true);
|
||||||
c = safetyPlugin.isClosedLoopAllowed(c);
|
c = safetyPlugin.isClosedLoopAllowed(c);
|
||||||
|
|
Loading…
Reference in a new issue