SW show ObjectivesFragment

This commit is contained in:
Milos Kozak 2018-05-11 08:30:21 +02:00
parent 0a51c86afb
commit 337a3d9776
5 changed files with 34 additions and 16 deletions

View file

@ -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;

View file

@ -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());
}
}

View file

@ -0,0 +1,6 @@
package info.nightscout.androidaps.plugins.ConstraintsObjectives.events;
import info.nightscout.androidaps.events.Event;
public class EventObjectivesSaved extends Event {
}

View file

@ -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())
)
;
}

View file

@ -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();
}