diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java index 3e33b9e926..3dcec0920f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesFragment.java @@ -55,7 +55,7 @@ public class ObjectivesFragment extends SubscriberFragment { enableFake.setOnClickListener(v -> updateGUI()); reset.setOnClickListener(v -> { ObjectivesPlugin.getPlugin().reset(); - ObjectivesPlugin.saveProgress(); + ObjectivesPlugin.getPlugin().saveProgress(); recyclerView.getAdapter().notifyDataSetChanged(); scrollToCurrentObjective(); }); @@ -77,7 +77,7 @@ public class ObjectivesFragment extends SubscriberFragment { private void startUpdateTimer() { handler.removeCallbacks(objectiveUpdater); - for (Objective objective : ObjectivesPlugin.getObjectives()) { + for (Objective objective : ObjectivesPlugin.getPlugin().getObjectives()) { if (objective.isStarted() && !objective.isAccomplished()) { long timeTillNextMinute = (System.currentTimeMillis() - objective.getStartedOn().getTime()) % (60 * 1000); handler.postDelayed(objectiveUpdater, timeTillNextMinute); @@ -87,8 +87,8 @@ public class ObjectivesFragment extends SubscriberFragment { } private void scrollToCurrentObjective() { - for (int i = 0; i < ObjectivesPlugin.getObjectives().size(); i++) { - Objective objective = ObjectivesPlugin.getObjectives().get(i); + for (int i = 0; i < ObjectivesPlugin.getPlugin().getObjectives().size(); i++) { + Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(i); if (!objective.isStarted() || !objective.isAccomplished()) { RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) { @Override @@ -118,7 +118,7 @@ public class ObjectivesFragment extends SubscriberFragment { @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { - Objective objective = ObjectivesPlugin.getObjectives().get(position); + Objective objective = ObjectivesPlugin.getPlugin().getObjectives().get(position); holder.title.setText(MainApp.gs(R.string.nth_objective, position + 1)); if (objective.getObjective() != 0) { holder.objective.setVisibility(View.VISIBLE); @@ -132,7 +132,7 @@ public class ObjectivesFragment extends SubscriberFragment { holder.gate.setTextColor(0xFFFFFFFF); holder.verify.setVisibility(View.GONE); holder.progress.setVisibility(View.GONE); - if (position == 0 || ObjectivesPlugin.getObjectives().get(position - 1).isAccomplished()) + if (position == 0 || ObjectivesPlugin.getPlugin().getObjectives().get(position - 1).isAccomplished()) holder.start.setVisibility(View.VISIBLE); else holder.start.setVisibility(View.GONE); } else if (objective.isAccomplished()) { @@ -173,7 +173,7 @@ public class ObjectivesFragment extends SubscriberFragment { @Override public int getItemCount() { - return ObjectivesPlugin.getObjectives().size(); + return ObjectivesPlugin.getPlugin().getObjectives().size(); } public class ViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index 1d3520ebf7..e675adee69 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -37,10 +37,10 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface private static ObjectivesPlugin objectivesPlugin; - public static List objectives = new ArrayList<>(); - public static boolean bgIsAvailableInNS = false; - public static boolean pumpStatusIsAvailableInNS = false; - public static Integer manualEnacts = 0; + public List objectives = new ArrayList<>(); + public boolean bgIsAvailableInNS = false; + public boolean pumpStatusIsAvailableInNS = false; + public Integer manualEnacts = 0; public static ObjectivesPlugin getPlugin() { if (objectivesPlugin == null) { @@ -91,7 +91,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface saveProgress(); } - public static void saveProgress() { + public void saveProgress() { SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS); SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS); SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts)); @@ -112,7 +112,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface log.debug("Objectives loaded"); } - public static List getObjectives() { + public List getObjectives() { return objectives; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java index bba29c5201..5127f64b34 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective.java @@ -9,6 +9,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.utils.SP; +import info.nightscout.utils.T; public abstract class Objective { @@ -128,9 +129,9 @@ public abstract class Objective { } private String getDurationText(long duration) { - int days = (int) Math.floor((double) duration / (24D * 60D * 60D * 1000D)); - int hours = (int) Math.floor((double) duration / (60D * 60D * 1000D)); - int minutes = (int) Math.floor((double) duration / (60D * 1000D)); + int days = (int) Math.floor((double) duration / T.days(1).msecs()); + int hours = (int) Math.floor((double) duration / T.hours(1).msecs()); + int minutes = (int) Math.floor((double) duration / T.mins(1).msecs()); if (days > 0) return MainApp.gq(R.plurals.objective_days, days, days); else if (hours > 0) return MainApp.gq(R.plurals.objective_hours, hours, hours); else return MainApp.gq(R.plurals.objective_minutes, minutes, minutes); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java index e374126b11..d1f4f3ebd7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective1.java @@ -27,7 +27,7 @@ public class Objective1 extends Objective { tasks.add(new Task(R.string.objectives_bgavailableinns) { @Override public boolean isCompleted() { - return ObjectivesPlugin.bgIsAvailableInNS; + return ObjectivesPlugin.getPlugin().bgIsAvailableInNS; } }); tasks.add(new Task(R.string.nsclienthaswritepermission) { @@ -50,7 +50,7 @@ public class Objective1 extends Objective { tasks.add(new Task(R.string.objectives_pumpstatusavailableinns) { @Override public boolean isCompleted() { - return ObjectivesPlugin.pumpStatusIsAvailableInNS; + return ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS; } }); tasks.add(new Task(R.string.hasbgdata) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java index 305f00ec6f..ac5485f953 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective2.java @@ -5,10 +5,11 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; +import info.nightscout.utils.T; public class Objective2 extends Objective { - public static final int MANUAL_ENACTS_NEEDED = 20; + public final int MANUAL_ENACTS_NEEDED = 20; public Objective2() { super(1, R.string.objectives_1_objective, R.string.objectives_1_gate); @@ -16,17 +17,19 @@ public class Objective2 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(7L * 24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(7).msecs())); tasks.add(new Task(R.string.objectives_manualenacts) { @Override public boolean isCompleted() { - return ObjectivesPlugin.manualEnacts >= MANUAL_ENACTS_NEEDED; + return ObjectivesPlugin.getPlugin().manualEnacts >= MANUAL_ENACTS_NEEDED; } @Override public String getProgress() { - if (ObjectivesPlugin.manualEnacts >= MANUAL_ENACTS_NEEDED) return MainApp.gs(R.string.completed_well_done); - else return ObjectivesPlugin.manualEnacts + " / " + MANUAL_ENACTS_NEEDED; + if (ObjectivesPlugin.getPlugin().manualEnacts >= MANUAL_ENACTS_NEEDED) + return MainApp.gs(R.string.completed_well_done); + else + return ObjectivesPlugin.getPlugin().manualEnacts + " / " + MANUAL_ENACTS_NEEDED; } }); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java index 36a98babc1..4cac10e514 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective4.java @@ -5,6 +5,7 @@ import java.util.List; import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; +import info.nightscout.utils.T; public class Objective4 extends Objective { @@ -14,7 +15,7 @@ public class Objective4 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(5L * 24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(5).msecs())); tasks.add(new Task(R.string.closedmodeenabled) { @Override public boolean isCompleted() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java index 563a114e05..8472f26c6c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective5.java @@ -4,6 +4,7 @@ import java.util.List; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; +import info.nightscout.utils.T; public class Objective5 extends Objective { @@ -13,7 +14,7 @@ public class Objective5 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(1).msecs())); tasks.add(new Task(R.string.maxiobset) { @Override public boolean isCompleted() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java index 7106d7522b..7867b28e70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective6.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; import java.util.List; import info.nightscout.androidaps.R; +import info.nightscout.utils.T; public class Objective6 extends Objective { @@ -12,6 +13,6 @@ public class Objective6 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(7L * 24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(7).msecs())); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java index cfd041bf13..670cffe746 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective7.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; import java.util.List; import info.nightscout.androidaps.R; +import info.nightscout.utils.T; public class Objective7 extends Objective { @@ -12,6 +13,6 @@ public class Objective7 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(28L * 24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(28).msecs())); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java index 376d5fb7a2..9ac4f9b6d7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/objectives/Objective8.java @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.ConstraintsObjectives.objectives; import java.util.List; import info.nightscout.androidaps.R; +import info.nightscout.utils.T; public class Objective8 extends Objective { @@ -12,6 +13,6 @@ public class Objective8 extends Objective { @Override protected void setupTasks(List tasks) { - tasks.add(new MinimumDurationTask(28L * 24L * 60L * 60L * 1000L)); + tasks.add(new MinimumDurationTask(T.days(28).msecs())); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 6081845d32..9a2a72746e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -464,8 +464,8 @@ public class LoopPlugin extends PluginBase { NSUpload.uploadDeviceStatus(); ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class); if (objectivesPlugin != null) { - ObjectivesPlugin.manualEnacts++; - ObjectivesPlugin.saveProgress(); + ObjectivesPlugin.getPlugin().manualEnacts++; + ObjectivesPlugin.getPlugin().saveProgress(); } } MainApp.bus().post(new EventAcceptOpenLoopChange()); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index db9727822e..b48319f979 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -108,8 +108,8 @@ public class NSDeviceStatus { setData(devicestatusJson); if (devicestatusJson.has("pump")) { // Objectives 0 - ObjectivesPlugin.pumpStatusIsAvailableInNS = true; - ObjectivesPlugin.saveProgress(); + ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS = true; + ObjectivesPlugin.getPlugin().saveProgress(); } } if (bundle.containsKey("devicestatuses")) { @@ -120,8 +120,8 @@ public class NSDeviceStatus { setData(devicestatusJson); if (devicestatusJson.has("pump")) { // Objectives 0 - ObjectivesPlugin.pumpStatusIsAvailableInNS = true; - ObjectivesPlugin.saveProgress(); + ObjectivesPlugin.getPlugin().pumpStatusIsAvailableInNS = true; + ObjectivesPlugin.getPlugin().saveProgress(); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java index 9f222d935e..7470710d8c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -86,8 +86,8 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac } // Objectives 0 - ObjectivesPlugin.bgIsAvailableInNS = true; - ObjectivesPlugin.saveProgress(); + ObjectivesPlugin.getPlugin().bgIsAvailableInNS = true; + ObjectivesPlugin.getPlugin().saveProgress(); } private void storeSgv(JSONObject sgvJson) {