loop mode in setup wizard

This commit is contained in:
Milos Kozak 2018-08-14 17:06:09 +02:00
parent 04af3eb806
commit 31e050be4a
7 changed files with 29 additions and 8 deletions

View file

@ -57,7 +57,7 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@Override
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"))
value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this);

View file

@ -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()

View file

@ -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);
}

View file

@ -1183,6 +1183,8 @@
<string name="as">AS</string>
<string name="versionavailable">Version %1$s available</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">
<item quantity="one">%1$d day</item>

View file

@ -6,7 +6,7 @@
<ListPreference
android:title="@string/apsmode_title"
android:key="aps_mode"
android:key="@string/key_aps_mode"
android:defaultValue="open"
android:entries="@array/aps_modeArray"
android:entryValues="@array/aps_modeValues"/>

View file

@ -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<Boolean> 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

View file

@ -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<Boolean> 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<Boolean> c = new Constraint<>(true);
c = safetyPlugin.isClosedLoopAllowed(c);