From 12a2d789c1771a09026f07f16b2153eb2fba57fb Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 1 Sep 2019 21:27:56 +0200 Subject: [PATCH] convert objectives --- .../objectives/ObjectivesPlugin.java | 20 +++++++++++++++++++ .../objectives/objectives/Objective.java | 14 ++++++------- .../objectives/objectives/Objective0.java | 2 +- .../objectives/objectives/Objective1.java | 2 +- .../objectives/objectives/Objective2.java | 2 +- .../objectives/objectives/Objective3.java | 2 +- .../objectives/objectives/Objective4.java | 2 +- .../objectives/objectives/Objective5.java | 2 +- .../objectives/objectives/Objective6.java | 2 +- .../objectives/objectives/Objective7.java | 2 +- .../objectives/objectives/Objective8.java | 2 +- 11 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java index f7f566ec3d..42fd12b822 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.java @@ -70,6 +70,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface .shortName(R.string.objectives_shortname) .description(R.string.description_objectives) ); + convertSP(); setupObjectives(); loadProgress(); } @@ -80,6 +81,25 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface return pump == null || pump.getPumpDescription().isTempBasalCapable; } + // convert 2.3 SP version + private void convertSP() { + doConvertSP(0, "config"); + doConvertSP(1, "openloop"); + doConvertSP(2, "maxbasal"); + doConvertSP(3, "maxiobzero"); + doConvertSP(4, "maxiob"); + doConvertSP(5, "autosens"); + doConvertSP(6, "ama"); + doConvertSP(7, "smb"); + } + + private void doConvertSP(int number, String name) { + if (!SP.contains("Objectives_" + name + "_started")) { + SP.putLong("Objectives_" + name + "_started", SP.getLong("Objectives" + number + "accomplished", 0L)); + SP.putLong("Objectives_" + name + "_accomplished", SP.getLong("Objectives" + number + "accomplished", 0L)); + } + } + private void setupObjectives() { objectives.add(new Objective0()); objectives.add(new Objective1()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java index b39301d766..70179a82bc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective.java @@ -12,7 +12,7 @@ import info.nightscout.androidaps.utils.T; public abstract class Objective { - private int number; + String spName; @StringRes private int objective; @StringRes @@ -21,12 +21,12 @@ public abstract class Objective { private long accomplishedOn; private List tasks = new ArrayList<>(); - public Objective(int number, @StringRes int objective, @StringRes int gate) { - this.number = number; + public Objective(String spName, @StringRes int objective, @StringRes int gate) { + this.spName = spName; this.objective = objective; this.gate = gate; - startedOn = SP.getLong("Objectives" + number + "started", 0L); - accomplishedOn = SP.getLong("Objectives" + number + "accomplished", 0L); + startedOn = SP.getLong("Objectives_" + spName + "_started", 0L); + accomplishedOn = SP.getLong("Objectives_" + spName + "_accomplished", 0L); setupTasks(tasks); for (Task task : tasks) task.objective = this; } @@ -65,12 +65,12 @@ public abstract class Objective { public void setStartedOn(long startedOn) { this.startedOn = startedOn; - SP.putLong("Objectives" + number + "started", startedOn); + SP.putLong("Objectives_" + spName + "_started", startedOn); } public void setAccomplishedOn(long accomplishedOn) { this.accomplishedOn = accomplishedOn; - SP.putLong("Objectives" + number + "accomplished", accomplishedOn); + SP.putLong("Objectives_" + spName + "_accomplished", accomplishedOn); } public long getAccomplishedOn() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.java index f59079f0c0..607635a32b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective0.java @@ -19,7 +19,7 @@ import info.nightscout.androidaps.utils.SP; public class Objective0 extends Objective { public Objective0() { - super(ObjectivesPlugin.FIRST_OBJECTIVE, R.string.objectives_0_objective, R.string.objectives_0_gate); + super("config", R.string.objectives_0_objective, R.string.objectives_0_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java index a6fd4cca52..22ff17331e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective1.java @@ -12,7 +12,7 @@ public class Objective1 extends Objective { public Objective1() { - super(ObjectivesPlugin.USAGE_OBJECTIVE, R.string.objectives_usage_objective, R.string.objectives_usage_gate); + super("usage", R.string.objectives_usage_objective, R.string.objectives_usage_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java index 3ced0e6e91..646d8ea458 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java @@ -12,7 +12,7 @@ public class Objective2 extends Objective { public final int MANUAL_ENACTS_NEEDED = 20; public Objective2() { - super(ObjectivesPlugin.OPENLOOP_OBJECTIVE, R.string.objectives_openloop_objective, R.string.objectives_openloop_gate); + super("openloop", R.string.objectives_openloop_objective, R.string.objectives_openloop_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java index b75450e772..4439f70d60 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective3.java @@ -6,6 +6,6 @@ import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugi public class Objective3 extends Objective { public Objective3() { - super(ObjectivesPlugin.MAXBASAL_OBJECTIVE, R.string.objectives_maxbasal_objective, R.string.objectives_maxbasal_gate); + super("maxbasal", R.string.objectives_maxbasal_objective, R.string.objectives_maxbasal_gate); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java index 0576b7f3c1..a5f3c8790e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective4.java @@ -11,7 +11,7 @@ import info.nightscout.androidaps.utils.T; public class Objective4 extends Objective { public Objective4() { - super(ObjectivesPlugin.MAXIOB_ZERO_CL_OBJECTIVE, R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate); + super("maxiobzero", R.string.objectives_maxiobzero_objective, R.string.objectives_maxiobzero_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java index 005b9a28e4..9a6474a2fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective5.java @@ -10,7 +10,7 @@ import info.nightscout.androidaps.utils.T; public class Objective5 extends Objective { public Objective5() { - super(ObjectivesPlugin.MAXIOB_OBJECTIVE, R.string.objectives_maxiob_objective, R.string.objectives_maxiob_gate); + super("maxiob", R.string.objectives_maxiob_objective, R.string.objectives_maxiob_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java index 64e9658cc8..bbb016b6dc 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective6.java @@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T; public class Objective6 extends Objective { public Objective6() { - super(ObjectivesPlugin.AUTOSENS_OBJECTIVE, R.string.objectives_autosens_objective, R.string.objectives_autosens_gate); + super("autosens", R.string.objectives_autosens_objective, R.string.objectives_autosens_gate); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java index 7d66bbf6ae..3c68668e4b 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective7.java @@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T; public class Objective7 extends Objective { public Objective7() { - super(ObjectivesPlugin.AMA_OBJECTIVE, R.string.objectives_ama_objective, 0); + super("ama", R.string.objectives_ama_objective, 0); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java index 9e79f6050e..53d1862786 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective8.java @@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T; public class Objective8 extends Objective { public Objective8() { - super(ObjectivesPlugin.SMB_OBJECTIVE, R.string.objectives_smb_objective, R.string.objectives_smb_gate); + super("smb", R.string.objectives_smb_objective, R.string.objectives_smb_gate); } @Override