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