working again
This commit is contained in:
parent
2a023232a7
commit
6e14e3df90
2 changed files with 32 additions and 43 deletions
|
@ -20,7 +20,6 @@ import info.nightscout.androidaps.utils.NumberPicker;
|
|||
|
||||
public class InputDelta extends Element {
|
||||
private Comparator.Compare compare = Comparator.Compare.IS_EQUAL;
|
||||
|
||||
final TextWatcher textWatcher = new TextWatcher() {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
@ -53,13 +52,22 @@ public class InputDelta extends Element {
|
|||
return R.string.unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> labels() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (DeltaType d : DeltaType.values()) {
|
||||
list.add(MainApp.gs(d.getStringRes()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
private double value;
|
||||
double minValue;
|
||||
double maxValue;
|
||||
private double step;
|
||||
private DecimalFormat decimalFormat;
|
||||
private int deltaType;
|
||||
private DeltaType deltaType;
|
||||
|
||||
NumberPicker numberPicker;
|
||||
|
||||
|
@ -67,7 +75,7 @@ public class InputDelta extends Element {
|
|||
super();
|
||||
}
|
||||
|
||||
public InputDelta(double value, double minValue, double maxValue, double step, DecimalFormat decimalFormat, int deltaType) {
|
||||
public InputDelta(double value, double minValue, double maxValue, double step, DecimalFormat decimalFormat, DeltaType deltaType) {
|
||||
super();
|
||||
this.value = value;
|
||||
this.minValue = minValue;
|
||||
|
@ -91,7 +99,7 @@ public class InputDelta extends Element {
|
|||
@Override
|
||||
public void addToLayout(LinearLayout root) {
|
||||
Spinner spinner = new Spinner(root.getContext());
|
||||
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_spinner_item, InputDelta.labels());
|
||||
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_spinner_item, DeltaType.labels());
|
||||
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(spinnerArrayAdapter);
|
||||
LinearLayout.LayoutParams spinnerParams = new LinearLayout.LayoutParams(
|
||||
|
@ -103,14 +111,14 @@ public class InputDelta extends Element {
|
|||
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
deltaType = spinner.getSelectedItemPosition();
|
||||
deltaType = DeltaType.values()[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
spinner.setSelection(this.deltaType);
|
||||
spinner.setSelection(this.deltaType.ordinal());
|
||||
// root.addView(spinner);
|
||||
numberPicker = new NumberPicker(root.getContext(), null);
|
||||
numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, textWatcher);
|
||||
|
@ -118,14 +126,12 @@ public class InputDelta extends Element {
|
|||
LinearLayout l = new LinearLayout(root.getContext());
|
||||
l.setOrientation(LinearLayout.VERTICAL);
|
||||
l.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
l.addView(spinner);
|
||||
l.addView(numberPicker);
|
||||
root.addView(l);
|
||||
|
||||
}
|
||||
|
||||
public InputDelta setValue(double value, int type) {
|
||||
public InputDelta setValue(double value, DeltaType type) {
|
||||
this.value = value;
|
||||
this.deltaType = type;
|
||||
if (numberPicker != null)
|
||||
|
@ -137,16 +143,8 @@ public class InputDelta extends Element {
|
|||
return value;
|
||||
}
|
||||
|
||||
public int getDeltaType() {
|
||||
public DeltaType getDeltaType() {
|
||||
return deltaType;
|
||||
}
|
||||
|
||||
public static List<String> labels() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(MainApp.gs(R.string.delta));
|
||||
list.add(MainApp.gs(R.string.short_avgdelta));
|
||||
list.add(MainApp.gs(R.string.long_avgdelta));
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta
|
|||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel;
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta.DeltaType;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
|
@ -36,7 +37,7 @@ public class TriggerDelta extends Trigger {
|
|||
private double step = 1;
|
||||
private DecimalFormat decimalFormat = new DecimalFormat("1");
|
||||
private String units = ProfileFunctions.getInstance().getProfileUnits();
|
||||
private int deltaType = 0; // 0 is delta, 1 is short average delta, 2 is long average delta
|
||||
private DeltaType deltaType;
|
||||
|
||||
private InputDelta value = new InputDelta( (double) minValue,(double) minValue, (double) maxValue, step, decimalFormat, deltaType);
|
||||
private Comparator comparator = new Comparator();
|
||||
|
@ -54,10 +55,13 @@ public class TriggerDelta extends Trigger {
|
|||
}
|
||||
|
||||
public double getValue() {
|
||||
deltaType = value.getDeltaType();
|
||||
return value.getValue();
|
||||
}
|
||||
|
||||
public double getType() { return value.getDeltaType(); }
|
||||
public DeltaType getType() {
|
||||
return value.getDeltaType();
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return this.units;
|
||||
|
@ -79,9 +83,9 @@ public class TriggerDelta extends Trigger {
|
|||
// Setting type of delta
|
||||
double delta;
|
||||
|
||||
if (deltaType == 1)
|
||||
if (deltaType == DeltaType.SHORT_AVERAGE)
|
||||
delta = glucoseStatus.short_avgdelta;
|
||||
else if (deltaType == 2)
|
||||
else if (deltaType == DeltaType.LONG_AVERAGE)
|
||||
delta = glucoseStatus.long_avgdelta;
|
||||
else
|
||||
delta = glucoseStatus.delta;
|
||||
|
@ -127,7 +131,8 @@ public class TriggerDelta extends Trigger {
|
|||
try {
|
||||
JSONObject d = new JSONObject(data);
|
||||
units = JsonHelper.safeGetString(d, "units");
|
||||
deltaType = JsonHelper.safeGetInt(d, "type");
|
||||
int savedDeltaType = JsonHelper.safeGetInt(d, "type");
|
||||
deltaType = DeltaType.valueOf(JsonHelper.safeGetString(d, "type", ""));
|
||||
value.setValue(JsonHelper.safeGetDouble(d, "value"), deltaType);
|
||||
lastRun = JsonHelper.safeGetLong(d, "lastRun");
|
||||
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
|
||||
|
@ -144,7 +149,7 @@ public class TriggerDelta extends Trigger {
|
|||
|
||||
@Override
|
||||
public String friendlyDescription() {
|
||||
return MainApp.gs(R.string.deltacompared, MainApp.gs(comparator.getValue().getStringRes()), getValue(), typeToString(deltaType));
|
||||
return MainApp.gs(R.string.deltacompared, MainApp.gs(comparator.getValue().getStringRes()), getValue(), deltaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,8 +162,8 @@ public class TriggerDelta extends Trigger {
|
|||
return new TriggerDelta(this);
|
||||
}
|
||||
|
||||
TriggerDelta setValue(double requestedValue) {
|
||||
this.value.setValue(requestedValue, deltaType);
|
||||
TriggerDelta setValue(double requestedValue, DeltaType requestedType) {
|
||||
this.value.setValue(requestedValue, requestedType);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -173,12 +178,12 @@ public class TriggerDelta extends Trigger {
|
|||
this.minValue = 0.1d;
|
||||
this.step = 0.1d;
|
||||
this.decimalFormat = new DecimalFormat("0.1");
|
||||
this.deltaType = 0;
|
||||
this.deltaType = DeltaType.DELTA;
|
||||
} else {
|
||||
this.maxValue = 72d;
|
||||
this.minValue = 2d;
|
||||
this.step = 1d;
|
||||
this.deltaType = 0;
|
||||
this.deltaType = DeltaType.DELTA;
|
||||
}
|
||||
value = new InputDelta( (double) minValue,(double) minValue, (double) maxValue, step, decimalFormat, deltaType);
|
||||
}
|
||||
|
@ -196,7 +201,6 @@ public class TriggerDelta extends Trigger {
|
|||
|
||||
@Override
|
||||
public void generateDialog(LinearLayout root, FragmentManager fragmentManager) {
|
||||
|
||||
new LayoutBuilder()
|
||||
.add(new StaticLabel(R.string.deltalabel))
|
||||
.add(comparator)
|
||||
|
@ -204,17 +208,4 @@ public class TriggerDelta extends Trigger {
|
|||
.build(root);
|
||||
}
|
||||
|
||||
public String typeToString( int type ) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
return MainApp.gs(R.string.delta);
|
||||
case 1:
|
||||
return MainApp.gs(R.string.short_avgdelta);
|
||||
case 2:
|
||||
return MainApp.gs(R.string.long_avgdelta);
|
||||
default:
|
||||
return MainApp.gs(R.string.delta);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue