convert objectives

This commit is contained in:
Milos Kozak 2019-09-01 21:27:56 +02:00
parent 80efc9369c
commit 12a2d789c1
11 changed files with 36 additions and 16 deletions

View file

@ -70,6 +70,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
.shortName(R.string.objectives_shortname) .shortName(R.string.objectives_shortname)
.description(R.string.description_objectives) .description(R.string.description_objectives)
); );
convertSP();
setupObjectives(); setupObjectives();
loadProgress(); loadProgress();
} }
@ -80,6 +81,25 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
return pump == null || pump.getPumpDescription().isTempBasalCapable; 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() { private void setupObjectives() {
objectives.add(new Objective0()); objectives.add(new Objective0());
objectives.add(new Objective1()); objectives.add(new Objective1());

View file

@ -12,7 +12,7 @@ import info.nightscout.androidaps.utils.T;
public abstract class Objective { public abstract class Objective {
private int number; String spName;
@StringRes @StringRes
private int objective; private int objective;
@StringRes @StringRes
@ -21,12 +21,12 @@ public abstract class Objective {
private long accomplishedOn; private long accomplishedOn;
private List<Task> tasks = new ArrayList<>(); private List<Task> tasks = new ArrayList<>();
public Objective(int number, @StringRes int objective, @StringRes int gate) { public Objective(String spName, @StringRes int objective, @StringRes int gate) {
this.number = number; this.spName = spName;
this.objective = objective; this.objective = objective;
this.gate = gate; this.gate = gate;
startedOn = SP.getLong("Objectives" + number + "started", 0L); startedOn = SP.getLong("Objectives_" + spName + "_started", 0L);
accomplishedOn = SP.getLong("Objectives" + number + "accomplished", 0L); accomplishedOn = SP.getLong("Objectives_" + spName + "_accomplished", 0L);
setupTasks(tasks); setupTasks(tasks);
for (Task task : tasks) task.objective = this; for (Task task : tasks) task.objective = this;
} }
@ -65,12 +65,12 @@ public abstract class Objective {
public void setStartedOn(long startedOn) { public void setStartedOn(long startedOn) {
this.startedOn = startedOn; this.startedOn = startedOn;
SP.putLong("Objectives" + number + "started", startedOn); SP.putLong("Objectives_" + spName + "_started", startedOn);
} }
public void setAccomplishedOn(long accomplishedOn) { public void setAccomplishedOn(long accomplishedOn) {
this.accomplishedOn = accomplishedOn; this.accomplishedOn = accomplishedOn;
SP.putLong("Objectives" + number + "accomplished", accomplishedOn); SP.putLong("Objectives_" + spName + "_accomplished", accomplishedOn);
} }
public long getAccomplishedOn() { public long getAccomplishedOn() {

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.utils.SP;
public class Objective0 extends Objective { public class Objective0 extends Objective {
public Objective0() { 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 @Override

View file

@ -12,7 +12,7 @@ public class Objective1 extends Objective {
public Objective1() { 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 @Override

View file

@ -12,7 +12,7 @@ public class Objective2 extends Objective {
public final int MANUAL_ENACTS_NEEDED = 20; public final int MANUAL_ENACTS_NEEDED = 20;
public Objective2() { 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 @Override

View file

@ -6,6 +6,6 @@ import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugi
public class Objective3 extends Objective { public class Objective3 extends Objective {
public Objective3() { 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);
} }
} }

View file

@ -11,7 +11,7 @@ import info.nightscout.androidaps.utils.T;
public class Objective4 extends Objective { public class Objective4 extends Objective {
public Objective4() { 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 @Override

View file

@ -10,7 +10,7 @@ import info.nightscout.androidaps.utils.T;
public class Objective5 extends Objective { public class Objective5 extends Objective {
public Objective5() { 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 @Override

View file

@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T;
public class Objective6 extends Objective { public class Objective6 extends Objective {
public Objective6() { 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 @Override

View file

@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T;
public class Objective7 extends Objective { public class Objective7 extends Objective {
public Objective7() { public Objective7() {
super(ObjectivesPlugin.AMA_OBJECTIVE, R.string.objectives_ama_objective, 0); super("ama", R.string.objectives_ama_objective, 0);
} }
@Override @Override

View file

@ -9,7 +9,7 @@ import info.nightscout.androidaps.utils.T;
public class Objective8 extends Objective { public class Objective8 extends Objective {
public Objective8() { 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 @Override