From 139455747e1d78fd85845831411c41549903e450 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 4 Sep 2019 21:00:00 +0200 Subject: [PATCH] fix copy constructors in automation plugin --- .../plugins/general/automation/elements/InputDouble.java | 4 ++-- .../general/automation/elements/InputDuration.java | 5 +++++ .../general/automation/elements/InputTempTarget.java | 2 +- .../general/automation/triggers/TriggerBolusAgo.java | 8 ++------ .../plugins/general/automation/triggers/TriggerCOB.java | 6 ++---- .../plugins/general/automation/triggers/TriggerDelta.java | 7 ++++--- .../general/automation/triggers/TriggerLocation.java | 7 ++++--- 7 files changed, 20 insertions(+), 19 deletions(-) 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 509eb05853..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 @@ -19,7 +19,7 @@ public class InputTempTarget extends Element { private double step; private DecimalFormat decimalFormat; - final TextWatcher textWatcher = new TextWatcher() { + private final TextWatcher textWatcher = new TextWatcher() { @Override public void afterTextChanged(Editable s) { value = Math.max(minValue, value); 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 9e47ae0e69..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() { 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