moved tbr accepting to a new method of the LoopPlugin

This commit is contained in:
Sebastian Lenz 2018-07-26 11:47:39 +02:00
parent 971e258265
commit 79abcdb0d7
5 changed files with 37 additions and 72 deletions

View file

@ -0,0 +1,5 @@
package info.nightscout.androidaps.events;
/** Base class for events to update the UI, mostly a specific tab. */
public class EventAcceptOpenLoopChange extends Event {
}

View file

@ -40,12 +40,14 @@ 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.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.utils.FabricPrivacy;
@ -428,4 +430,27 @@ public class LoopPlugin extends PluginBase {
}
}
public void acceptChangeRequest() {
Profile profile = MainApp.getConfigBuilder().getProfile();
MainApp.getConfigBuilder().applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
lastRun.tbrSetByPump = result;
lastRun.lastEnact = new Date();
lastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
ObjectivesPlugin.manualEnacts++;
ObjectivesPlugin.saveProgress();
}
}
MainApp.bus().post(new EventAcceptOpenLoopChange());
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp"));
}
}

View file

@ -84,7 +84,6 @@ import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
@ -110,7 +109,7 @@ import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
import info.nightscout.androidaps.plugins.Wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange;
import info.nightscout.androidaps.events.EventAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
@ -749,29 +748,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
builder.setPositiveButton(MainApp.gs(R.string.ok), (dialog, id) -> {
hideTempRecommendation();
clearNotification();
MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
ObjectivesPlugin.manualEnacts++;
ObjectivesPlugin.saveProgress();
}
}
scheduleUpdateGUI("onClickAcceptTemp");
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp"));
// dismiss notifications
NotificationManager notificationManager =
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.notificationID);
ActionStringHandler.handleInitiate("cancelChangeRequest");
LoopPlugin.getPlugin().acceptChangeRequest();
});
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
builder.show();
@ -971,8 +948,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
@Subscribe
public void onStatusEvent(final EventWearAcceptOpenLoopChange ev) {
scheduleUpdateGUI("EventWearAcceptOpenLoopChange");
public void onStatusEvent(final EventAcceptOpenLoopChange ev) {
scheduleUpdateGUI("EventAcceptOpenLoopChange");
}
@Subscribe
@ -1015,6 +992,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
NotificationManager notificationManager =
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.notificationID);
ActionStringHandler.handleInitiate("cancelChangeRequest");
}
private void updatePumpStatus(String status) {

View file

@ -1,12 +1,8 @@
package info.nightscout.androidaps.plugins.Wear;
import android.app.NotificationManager;
import android.content.Context;
import android.os.HandlerThread;
import android.support.annotation.NonNull;
import com.crashlytics.android.answers.CustomEvent;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
@ -36,7 +32,6 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.CobInfo;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult;
@ -50,14 +45,11 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.HardLimits;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils;
@ -651,34 +643,7 @@ public class ActionStringHandler {
} else if ("dismissoverviewnotification".equals(act[0])) {
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1])));
} else if ("changeRequest".equals(act[0])) {
// accept change request
final LoopPlugin.LastRun finalLastRun = LoopPlugin.lastRun;
Profile profile = MainApp.getConfigBuilder().getProfile();
MainApp.getConfigBuilder().applyTBRRequest(finalLastRun.constraintsProcessed, profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
finalLastRun.tbrSetByPump = result;
finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date();
NSUpload.uploadDeviceStatus();
ObjectivesPlugin objectivesPlugin = MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
ObjectivesPlugin.manualEnacts++;
ObjectivesPlugin.saveProgress();
}
}
MainApp.bus().post(new EventWearAcceptOpenLoopChange());
}
});
FabricPrivacy.getInstance().logCustom(new CustomEvent("AcceptTemp"));
NotificationManager notificationManager =
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(Constants.notificationID);
LoopPlugin.getPlugin().acceptChangeRequest();
}
lastBolusWizard = null;
}

View file

@ -1,9 +0,0 @@
package info.nightscout.androidaps.plugins.Wear.events;
import info.nightscout.androidaps.events.Event;
/**
* Created by mike on 07.08.2016.
*/
public class EventWearAcceptOpenLoopChange extends Event {
}