From 337a3d97765cb80b149aa51de8e1969eec459208 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 11 May 2018 08:30:21 +0200 Subject: [PATCH] SW show ObjectivesFragment --- .../ObjectivesFragment.java | 24 ++++++++----------- .../ObjectivesPlugin.java | 4 +++- .../events/EventObjectivesSaved.java | 6 +++++ .../startupwizard/SWDefinition.java | 8 +++++++ .../startupwizard/SetupWizardActivity.java | 8 ++++++- 5 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java 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 1424013440..458351cd62 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 @@ -67,24 +67,20 @@ public class ObjectivesFragment extends SubscriberFragment { holder.startButton.setTag(o); holder.verifyButton.setTag(o); - holder.startButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag(); - o.started = new Date(); + holder.startButton.setOnClickListener(v -> { + ObjectivesPlugin.Objective o1 = (ObjectivesPlugin.Objective) v.getTag(); + o1.started = new Date(); + updateGUI(); + ObjectivesPlugin.saveProgress(); + }); + holder.verifyButton.setOnClickListener(v -> { + ObjectivesPlugin.Objective o12 = (ObjectivesPlugin.Objective) v.getTag(); + if (ObjectivesPlugin.getPlugin().requirementsMet(o12.num).done || enableFake.isChecked()) { + o12.accomplished = new Date(); updateGUI(); ObjectivesPlugin.saveProgress(); } }); - holder.verifyButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag(); - if (ObjectivesPlugin.getPlugin().requirementsMet(o.num).done || enableFake.isChecked()) { - o.accomplished = new Date(); - updateGUI(); - ObjectivesPlugin.saveProgress(); - } - } - }); long prevObjectiveAccomplishedTime = position > 0 ? objectives.get(position - 1).accomplished.getTime() : -1; 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 5a899bebe5..293029b80f 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 @@ -22,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.events.EventObjectivesSaved; import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; @@ -87,7 +88,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface this.started = started; } - boolean isStarted() { + public boolean isStarted() { return started.getTime() > 0; } @@ -233,6 +234,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface editor.apply(); if (Config.logPrefsChange) log.debug("Objectives stored"); + MainApp.bus().post(new EventObjectivesSaved()); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java new file mode 100644 index 0000000000..1822368cf9 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/events/EventObjectivesSaved.java @@ -0,0 +1,6 @@ +package info.nightscout.androidaps.plugins.ConstraintsObjectives.events; + +import info.nightscout.androidaps.events.Event; + +public class EventObjectivesSaved extends Event { +} diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index b6ccc27b2f..ef566d94a1 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -24,6 +24,7 @@ import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialo import info.nightscout.androidaps.plugins.Careportal.OptionsToShow; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragment; import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin; @@ -271,6 +272,13 @@ public class SWDefinition { .validator(() -> ObjectivesPlugin.getPlugin().isEnabled(PluginType.CONSTRAINTS)) .visibility(() -> !ObjectivesPlugin.getPlugin().isFragmentVisible()) ) + .add(new SWScreen(R.string.objectives) + .skippable(false) + .add(new SWFragment(this) + .add(new ObjectivesFragment())) + .validator(() -> ObjectivesPlugin.getPlugin().objectives.get(0).isStarted()) + .visibility(() -> !ObjectivesPlugin.getPlugin().objectives.get(0).isStarted()) + ) ; } diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index a171698666..129159f93a 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -20,6 +20,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventProfileStoreChanged; import info.nightscout.androidaps.events.EventProfileSwitchChange; import info.nightscout.androidaps.events.EventPumpStatusChanged; +import info.nightscout.androidaps.plugins.ConstraintsObjectives.events.EventObjectivesSaved; import info.nightscout.androidaps.plugins.NSClientInternal.events.EventNSClientStatus; import info.nightscout.androidaps.startupwizard.events.EventSWUpdate; import info.nightscout.utils.LocaleHelper; @@ -97,7 +98,12 @@ public class SetupWizardActivity extends AppCompatActivity { } @Subscribe - public void onEventProfileStoreChanged(EventProfileSwitchChange ignored) { + public void onEventProfileSwitchChange(EventProfileSwitchChange ignored) { + updateButtons(); + } + + @Subscribe + public void onEventObjectivesSaved(EventObjectivesSaved ignored) { updateButtons(); }