processing the acceptance of the TBR request from the wearable

This commit is contained in:
Sebastian Lenz 2018-07-25 23:47:59 +02:00
parent e2ef8f2d74
commit 8c49119b15
4 changed files with 68 additions and 1 deletions

View file

@ -109,6 +109,7 @@ import info.nightscout.androidaps.plugins.Source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog; import info.nightscout.androidaps.plugins.Treatments.fragments.ProfileViewerDialog;
import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard; import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
@ -967,6 +968,11 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
scheduleUpdateGUI("EventNewOpenLoopNotification"); scheduleUpdateGUI("EventNewOpenLoopNotification");
} }
@Subscribe
public void onStatusEvent(final EventWearAcceptOpenLoopChange ev) {
scheduleUpdateGUI("EventWearAcceptOpenLoopChange");
}
@Subscribe @Subscribe
public void onStatusEvent(final EventTempTargetChange ev) { public void onStatusEvent(final EventTempTargetChange ev) {
scheduleUpdateGUI("EventTempTargetChange"); scheduleUpdateGUI("EventTempTargetChange");

View file

@ -1,10 +1,12 @@
package info.nightscout.androidaps.plugins.Wear; package info.nightscout.androidaps.plugins.Wear;
import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.os.HandlerThread; import android.os.HandlerThread;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.crashlytics.android.answers.CustomEvent; import com.crashlytics.android.answers.CustomEvent;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -34,6 +36,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog; import info.nightscout.androidaps.plugins.Actions.dialogs.FillDialog;
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog; import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; 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.CobInfo;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.APSResult; import info.nightscout.androidaps.plugins.Loop.APSResult;
@ -47,11 +50,14 @@ import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin; import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator; import info.nightscout.androidaps.plugins.Treatments.CarbsGenerator;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.utils.BolusWizard; import info.nightscout.utils.BolusWizard;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.FabricPrivacy;
import info.nightscout.utils.HardLimits; import info.nightscout.utils.HardLimits;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import info.nightscout.utils.SafeParse; import info.nightscout.utils.SafeParse;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
@ -638,6 +644,35 @@ public class ActionStringHandler {
doECarbs(carbs, starttime, duration); doECarbs(carbs, starttime, duration);
} else if ("dismissoverviewnotification".equals(act[0])) { } else if ("dismissoverviewnotification".equals(act[0])) {
MainApp.bus().post(new EventDismissNotification(SafeParse.stringToInt(act[1]))); 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);
} }
lastBolusWizard = null; lastBolusWizard = null;
} }

View file

@ -0,0 +1,9 @@
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 {
}

View file

@ -61,6 +61,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA"; private static final String ACTION_RESEND = "com.dexdrip.stephenblack.nightwatch.RESEND_DATA";
private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS"; private static final String ACTION_CANCELBOLUS = "com.dexdrip.stephenblack.nightwatch.CANCELBOLUS";
private static final String ACTION_CONFIRMATION = "com.dexdrip.stephenblack.nightwatch.CONFIRMACTION"; private static final String ACTION_CONFIRMATION = "com.dexdrip.stephenblack.nightwatch.CONFIRMACTION";
private static final String ACTION_CONFIRMCHANGE = "com.dexdrip.stephenblack.nightwatch.CONFIRMCHANGE";
private static final String ACTION_INITIATE_ACTION = "com.dexdrip.stephenblack.nightwatch.INITIATE_ACTION"; private static final String ACTION_INITIATE_ACTION = "com.dexdrip.stephenblack.nightwatch.INITIATE_ACTION";
@ -227,6 +228,17 @@ public class ListenerService extends WearableListenerService implements GoogleAp
String actionstring = intent.getStringExtra("actionstring"); String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring); sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_CONFIRMCHANGE.equals(intent.getAction())){
googleApiConnect();
//dismiss notification
NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(ListenerService.this);
notificationManager.cancel(CHANGE_NOTIF_ID);
String actionstring = intent.getStringExtra("actionstring");
sendConfirmActionstring(actionstring);
} else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){ } else if(intent != null && ACTION_INITIATE_ACTION.equals(intent.getAction())){
googleApiConnect(); googleApiConnect();
@ -447,7 +459,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp
public static void confirmAction(Context context, String actionstring) { public static void confirmAction(Context context, String actionstring) {
Intent intent = new Intent(context, ListenerService.class); Intent intent = new Intent(context, ListenerService.class);
intent.putExtra("actionstring", actionstring); intent.putExtra("actionstring", actionstring);
intent.setAction(ACTION_CONFIRMATION);
if (actionstring.equals("changeRequest")) {
intent.setAction(ACTION_CONFIRMCHANGE);
} else {
intent.setAction(ACTION_CONFIRMATION);
}
context.startService(intent); context.startService(intent);
} }