diff --git a/app/src/main/java/info/nightscout/androidaps/MainApp.java b/app/src/main/java/info/nightscout/androidaps/MainApp.java index 92a56bdb41..63a2446051 100644 --- a/app/src/main/java/info/nightscout/androidaps/MainApp.java +++ b/app/src/main/java/info/nightscout/androidaps/MainApp.java @@ -218,11 +218,9 @@ public class MainApp extends Application { pluginsList.add(StatuslinePlugin.initPlugin(this)); pluginsList.add(PersistentNotificationPlugin.getPlugin()); pluginsList.add(NSClientPlugin.getPlugin()); - if (engineeringMode) - pluginsList.add(TidepoolPlugin.INSTANCE); +// if (engineeringMode) pluginsList.add(TidepoolPlugin.INSTANCE); pluginsList.add(MaintenancePlugin.initPlugin(this)); - if (engineeringMode) - pluginsList.add(AutomationPlugin.INSTANCE); + pluginsList.add(AutomationPlugin.INSTANCE); pluginsList.add(ConfigBuilderPlugin.getPlugin()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java index 908d51ab77..c9444acb33 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/loop/LoopPlugin.java @@ -290,7 +290,7 @@ public class LoopPlugin extends PluginBase { Profile profile = ProfileFunctions.getInstance().getProfile(); - if (!ProfileFunctions.getInstance().isProfileValid("Loop")) { + if (profile == null || !ProfileFunctions.getInstance().isProfileValid("Loop")) { if (L.isEnabled(L.APS)) log.debug(MainApp.gs(R.string.noprofileselected)); RxBus.INSTANCE.send(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected))); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java index b4c6fb1f11..ec1cac23d6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/EventListAdapter.java @@ -84,14 +84,13 @@ class EventListAdapter extends RecyclerView.Adapter // enabled event holder.enabled.setOnCheckedChangeListener((buttonView, isChecked) -> { event.setEnabled(isChecked); - notifyDataSetChanged(); RxBus.INSTANCE.send(new EventAutomationDataChanged()); }); // remove event holder.iconTrash.setOnClickListener(v -> { mEventList.remove(event); - notifyDataSetChanged(); + RxBus.INSTANCE.send(new EventAutomationDataChanged()); }); // edit event diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java index 05d06f0b3a..659bb508eb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionStartTempTarget.java @@ -71,7 +71,7 @@ public class ActionStartTempTarget extends Action { int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; new LayoutBuilder() - .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget), MainApp.gs(unitResId), value)) + .add(new LabelWithElement(MainApp.gs(R.string.careportal_temporarytarget) + " [" + MainApp.gs(unitResId) + "]", "", value)) .add(new LabelWithElement(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "", duration)) .build(root); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java index f8464e7ee0..518b00f5b4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDouble.java @@ -25,8 +25,8 @@ public class InputDouble extends Element { }; private double value; - double minValue; - double maxValue; + private double minValue; + private double maxValue; private double step; private DecimalFormat decimalFormat; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java index a35fe4a4ad..aa19896471 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDuration.java @@ -20,6 +20,11 @@ public class InputDuration extends Element { this.value = value; } + public InputDuration(InputDuration another) { + unit = another.unit; + value = another.value; + } + @Override public void addToLayout(LinearLayout root) { NumberPicker numberPicker = new NumberPicker(root.getContext(), null); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java index 8175c496a5..4906e79add 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTarget.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; +import android.text.Editable; +import android.text.TextWatcher; import android.widget.LinearLayout; import java.text.DecimalFormat; @@ -17,6 +19,22 @@ public class InputTempTarget extends Element { private double step; private DecimalFormat decimalFormat; + private final TextWatcher textWatcher = new TextWatcher() { + @Override + public void afterTextChanged(Editable s) { + value = Math.max(minValue, value); + value = Math.min(maxValue, value); + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }; + public InputTempTarget() { super(); setUnits(ProfileFunctions.getInstance().getProfileUnits()); @@ -36,7 +54,7 @@ public class InputTempTarget extends Element { @Override public void addToLayout(LinearLayout root) { NumberPicker numberPicker = new NumberPicker(root.getContext(), null); - numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, null); + numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, null, textWatcher); numberPicker.setOnValueChangedListener(value -> this.value = value); root.addView(numberPicker); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java index 2531d56e6c..145d8c2d2c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/elements/LabelWithElement.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements; import android.graphics.Typeface; import android.view.ViewGroup; import android.widget.LinearLayout; +import android.widget.TableLayout; import android.widget.TextView; import info.nightscout.androidaps.MainApp; @@ -37,6 +38,10 @@ public class LabelWithElement extends Element { textViewPre.setTypeface(textViewPre.getTypeface(), Typeface.BOLD); layout.addView(textViewPre); + TextView spacer = new TextView(root.getContext()); + spacer.setLayoutParams(new TableLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + layout.addView(spacer); + // add element to layout element.addToLayout(layout); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java index e1792d8bd3..0ad9f75ab2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgo.java @@ -11,8 +11,6 @@ import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.text.DecimalFormat; - import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.logging.L; @@ -28,9 +26,7 @@ import info.nightscout.androidaps.utils.T; public class TriggerBolusAgo extends Trigger { private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); - private final double step = 1; - private DecimalFormat decimalFormat = new DecimalFormat("1"); - public InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES); + private InputDuration minutesAgo = new InputDuration(0, InputDuration.TimeUnit.MINUTES); private Comparator comparator = new Comparator(); public TriggerBolusAgo() { @@ -39,7 +35,7 @@ public class TriggerBolusAgo extends Trigger { private TriggerBolusAgo(TriggerBolusAgo triggerBolusAgo) { super(); - minutesAgo = new InputDuration(triggerBolusAgo.minutesAgo.getMinutes(), InputDuration.TimeUnit.MINUTES); + minutesAgo = new InputDuration(triggerBolusAgo.minutesAgo); lastRun = triggerBolusAgo.lastRun; comparator = new Comparator(triggerBolusAgo.comparator); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java index a794851236..4ddeb4299a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOB.java @@ -32,10 +32,8 @@ import info.nightscout.androidaps.utils.T; public class TriggerCOB extends Trigger { private static Logger log = LoggerFactory.getLogger(L.AUTOMATION); private final int minValue = 0; - private final int maxValue = (int) (SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48)); - private final double step = 1; - private DecimalFormat decimalFormat = new DecimalFormat("1"); - private InputDouble value = new InputDouble(0, (double) minValue, (double) maxValue, step, decimalFormat); + private final int maxValue = SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48); + private InputDouble value = new InputDouble(0, (double) minValue, (double) maxValue, 1, new DecimalFormat("1")); private Comparator comparator = new Comparator(); public TriggerCOB() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java index 0b9edf148a..a3939a60b7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDelta.java @@ -51,10 +51,11 @@ public class TriggerDelta extends Trigger { private TriggerDelta(TriggerDelta triggerDelta) { super(); - this.units = ProfileFunctions.getInstance().getProfileUnits(); - initializer(); - value = triggerDelta.value; lastRun = triggerDelta.lastRun; + this.units = triggerDelta.units; + deltaType = triggerDelta.deltaType; + value = new InputDelta(triggerDelta.value); + comparator = new Comparator(triggerDelta.comparator); } public double getValue() { @@ -68,7 +69,7 @@ public class TriggerDelta extends Trigger { if (units.equals(Constants.MMOL)) value = new InputDelta(0, -MMOL_MAX, MMOL_MAX, 0.1d, new DecimalFormat("0.1"), DeltaType.DELTA); else - value = new InputDelta(0, -MGDL_MAX, MGDL_MAX, 0.1d, new DecimalFormat("1"), DeltaType.DELTA); + value = new InputDelta(0, -MGDL_MAX, MGDL_MAX, 1d, new DecimalFormat("1"), DeltaType.DELTA); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java index d2be0ffa1f..4772d29112 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java @@ -51,10 +51,11 @@ public class TriggerLocation extends Trigger { private TriggerLocation(TriggerLocation triggerLocation) { super(); - latitude = new InputDouble(triggerLocation.latitude.getValue(), -90d, +90d, 0.00001d, new DecimalFormat("0.00000")); - longitude = new InputDouble(triggerLocation.longitude.getValue(), -180d, +180d, 0.00001d, new DecimalFormat("0.00000")); - distance = new InputDouble(200d, 0, 100000, 10d, new DecimalFormat("0")); + latitude = new InputDouble(triggerLocation.latitude); + longitude = new InputDouble(triggerLocation.longitude); + distance = new InputDouble(triggerLocation.distance); lastRun = triggerLocation.lastRun; + name = triggerLocation.name; } @Override