cancel TBR request notification on wearable if accepted or no longer valid
This commit is contained in:
parent
8c49119b15
commit
971e258265
5 changed files with 46 additions and 1 deletions
|
@ -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.ActionStringHandler;
|
||||||
import info.nightscout.androidaps.plugins.Wear.events.EventWearAcceptOpenLoopChange;
|
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;
|
||||||
|
@ -770,6 +771,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
NotificationManager notificationManager =
|
NotificationManager notificationManager =
|
||||||
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) MainApp.instance().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
notificationManager.cancel(Constants.notificationID);
|
notificationManager.cancel(Constants.notificationID);
|
||||||
|
ActionStringHandler.handleInitiate("cancelChangeRequest");
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
builder.setNegativeButton(MainApp.gs(R.string.cancel), null);
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
|
@ -371,6 +371,12 @@ public class ActionStringHandler {
|
||||||
lastSentTimestamp = System.currentTimeMillis();
|
lastSentTimestamp = System.currentTimeMillis();
|
||||||
lastConfirmActionString = rAction;
|
lastConfirmActionString = rAction;
|
||||||
return;
|
return;
|
||||||
|
} else if ("cancelChangeRequest".equals(act[0])) {
|
||||||
|
////////////////////////////////////////////// CANCEL CHANGE REQUEST NOTIFICATION
|
||||||
|
rAction = "cancelChangeRequest";
|
||||||
|
|
||||||
|
WearPlugin.getPlugin().requestNotificationCancel(rAction);
|
||||||
|
return;
|
||||||
} else return;
|
} else return;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,12 @@ public class WearPlugin extends PluginBase {
|
||||||
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
|
ctx.startService(new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_OPEN_SETTINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void requestNotificationCancel(String actionstring) {
|
||||||
|
Intent intent = new Intent(ctx, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_CANCEL_NOTIFICATION);
|
||||||
|
intent.putExtra("actionstring", actionstring);
|
||||||
|
ctx.startService(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventPreferenceChange ev) {
|
public void onStatusEvent(final EventPreferenceChange ev) {
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
public static final String ACTION_SEND_BASALS = WatchUpdaterService.class.getName().concat(".SendBasals");
|
public static final String ACTION_SEND_BASALS = WatchUpdaterService.class.getName().concat(".SendBasals");
|
||||||
public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress");
|
public static final String ACTION_SEND_BOLUSPROGRESS = WatchUpdaterService.class.getName().concat(".BolusProgress");
|
||||||
public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest");
|
public static final String ACTION_SEND_ACTIONCONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ActionConfirmationRequest");
|
||||||
|
|
||||||
public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest");
|
public static final String ACTION_SEND_CHANGECONFIRMATIONREQUEST = WatchUpdaterService.class.getName().concat(".ChangeConfirmationRequest");
|
||||||
|
public static final String ACTION_CANCEL_NOTIFICATION = WatchUpdaterService.class.getName().concat(".CancelNotification");
|
||||||
|
|
||||||
private GoogleApiClient googleApiClient;
|
private GoogleApiClient googleApiClient;
|
||||||
public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
|
public static final String WEARABLE_DATA_PATH = "/nightscout_watch_data";
|
||||||
|
@ -80,6 +80,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
|
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
|
||||||
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
||||||
public static final String ACTION_CHANGECONFIRMATION_REQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
|
public static final String ACTION_CHANGECONFIRMATION_REQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
|
||||||
|
public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest";
|
||||||
|
|
||||||
|
|
||||||
boolean wear_integration = false;
|
boolean wear_integration = false;
|
||||||
|
@ -160,6 +161,9 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
String message = intent.getStringExtra("message");
|
String message = intent.getStringExtra("message");
|
||||||
String actionstring = intent.getStringExtra("actionstring");
|
String actionstring = intent.getStringExtra("actionstring");
|
||||||
sendChangeConfirmationRequest(title, message, actionstring);
|
sendChangeConfirmationRequest(title, message, actionstring);
|
||||||
|
} else if (ACTION_CANCEL_NOTIFICATION.equals(action)) {
|
||||||
|
String actionstring = intent.getStringExtra("actionstring");
|
||||||
|
sendCancelNotificationRequest(actionstring);
|
||||||
} else {
|
} else {
|
||||||
sendData();
|
sendData();
|
||||||
}
|
}
|
||||||
|
@ -603,6 +607,23 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendCancelNotificationRequest(String actionstring) {
|
||||||
|
if (googleApiClient.isConnected()) {
|
||||||
|
PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CANCELNOTIFICATION_REQUEST_PATH);
|
||||||
|
//unique content
|
||||||
|
dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());
|
||||||
|
dataMapRequest.getDataMap().putString("cancelNotificationRequest", "cancelNotificationRequest");
|
||||||
|
dataMapRequest.getDataMap().putString("actionstring", actionstring);
|
||||||
|
|
||||||
|
log.debug("Canceling notification on wear: " + actionstring);
|
||||||
|
|
||||||
|
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
|
||||||
|
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
|
||||||
|
} else {
|
||||||
|
Log.e("cancelNotificationRequest", "No connection to wearable available!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void sendStatus() {
|
private void sendStatus() {
|
||||||
|
|
||||||
if (googleApiClient.isConnected()) {
|
if (googleApiClient.isConnected()) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
|
public static final String BOLUS_PROGRESS_PATH = "/nightscout_watch_bolusprogress";
|
||||||
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
public static final String ACTION_CONFIRMATION_REQUEST_PATH = "/nightscout_watch_actionconfirmationrequest";
|
||||||
public static final String NEW_CHANGECONFIRMATIONREQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
|
public static final String NEW_CHANGECONFIRMATIONREQUEST_PATH = "/nightscout_watch_changeconfirmationrequest";
|
||||||
|
public static final String ACTION_CANCELNOTIFICATION_REQUEST_PATH = "/nightscout_watch_cancelnotificationrequest";
|
||||||
|
|
||||||
|
|
||||||
public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
|
public static final int BOLUS_PROGRESS_NOTIF_ID = 001;
|
||||||
|
@ -315,6 +316,9 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
|
String message = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("message");
|
||||||
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
|
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
|
||||||
notifyChangeRequest(title, message, actionstring);
|
notifyChangeRequest(title, message, actionstring);
|
||||||
|
} else if (path.equals(ACTION_CANCELNOTIFICATION_REQUEST_PATH)) {
|
||||||
|
String actionstring = DataMapItem.fromDataItem(event.getDataItem()).getDataMap().getString("actionstring");
|
||||||
|
cancelNotificationRequest(actionstring);
|
||||||
} else {
|
} else {
|
||||||
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
|
||||||
Intent messageIntent = new Intent();
|
Intent messageIntent = new Intent();
|
||||||
|
@ -355,6 +359,12 @@ public class ListenerService extends WearableListenerService implements GoogleAp
|
||||||
mNotificationManager.notify(CHANGE_NOTIF_ID, builder.build());
|
mNotificationManager.notify(CHANGE_NOTIF_ID, builder.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void cancelNotificationRequest(String actionstring) {
|
||||||
|
NotificationManager mNotificationManager =
|
||||||
|
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
mNotificationManager.cancel(CHANGE_NOTIF_ID);
|
||||||
|
}
|
||||||
|
|
||||||
private void showBolusProgress(int progresspercent, String progresstatus) {
|
private void showBolusProgress(int progresspercent, String progresstatus) {
|
||||||
Intent cancelIntent = new Intent(this, ListenerService.class);
|
Intent cancelIntent = new Intent(this, ListenerService.class);
|
||||||
cancelIntent.setAction(ACTION_CANCELBOLUS);
|
cancelIntent.setAction(ACTION_CANCELBOLUS);
|
||||||
|
|
Loading…
Reference in a new issue