Merge pull request #118 from AAPS-Omnipod/omnipod_eros_dev_upstream_merge

Omnipod notification improvements
This commit is contained in:
Milos Kozak 2020-12-15 09:55:05 +01:00 committed by GitHub
commit 4fa1c06f06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 22 deletions

View file

@ -67,13 +67,17 @@ public class Notification {
public static final int OVER_24H_TIME_CHANGE_REQUESTED = 54; public static final int OVER_24H_TIME_CHANGE_REQUESTED = 54;
public static final int INVALID_VERSION = 55; public static final int INVALID_VERSION = 55;
public static final int PERMISSION_SYSTEM_WINDOW = 56; public static final int PERMISSION_SYSTEM_WINDOW = 56;
public static final int OMNIPOD_PUMP_ALARM = 57;
public static final int TIME_OR_TIMEZONE_CHANGE = 58; public static final int TIME_OR_TIMEZONE_CHANGE = 58;
public static final int OMNIPOD_POD_NOT_ATTACHED = 59; public static final int OMNIPOD_POD_NOT_ATTACHED = 59;
public static final int CARBS_REQUIRED = 60; public static final int CARBS_REQUIRED = 60;
public static final int OMNIPOD_POD_SUSPENDED = 61; public static final int OMNIPOD_POD_SUSPENDED = 61;
public static final int OMNIPOD_POD_ALERTS_UPDATED = 62; public static final int OMNIPOD_POD_ALERTS_UPDATED = 62;
public static final int OMNIPOD_POD_ALERTS = 63; public static final int OMNIPOD_POD_ALERTS = 63;
public static final int OMNIPOD_UNCERTAIN_TBR = 64;
public static final int OMNIPOD_POD_FAULT = 66;
public static final int OMNIPOD_UNCERTAIN_SMB = 67;
public static final int OMNIPOD_UNKNOWN_TBR = 68;
public static final int OMNIPOD_STARTUP_STATUS_REFRESH_FAILED = 69;
public static final int IMPORTANCE_HIGH = 2; public static final int IMPORTANCE_HIGH = 2;

View file

@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction; import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType; import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair; import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
@ -382,12 +383,14 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
} else { } else {
// Not sure what's going on. Notify the user // Not sure what's going on. Notify the user
aapsLogger.error(LTag.PUMP, "Unknown TBR in both Pod state and AAPS"); aapsLogger.error(LTag.PUMP, "Unknown TBR in both Pod state and AAPS");
rxBus.send(new EventNewNotification(new Notification(Notification.OMNIPOD_PUMP_ALARM, resourceHelper.gs(R.string.omnipod_error_tbr_running_but_aaps_not_aware), Notification.NORMAL).sound(R.raw.boluserror))); rxBus.send(new EventNewNotification(new Notification(Notification.OMNIPOD_UNKNOWN_TBR, resourceHelper.gs(R.string.omnipod_error_tbr_running_but_aaps_not_aware), Notification.NORMAL).sound(R.raw.boluserror)));
} }
} else if (!podStateManager.isTempBasalRunning() && tempBasal != null) { } else if (!podStateManager.isTempBasalRunning() && tempBasal != null) {
aapsLogger.warn(LTag.PUMP, "Removing AAPS TBR that actually hadn't succeeded"); aapsLogger.warn(LTag.PUMP, "Removing AAPS TBR that actually hadn't succeeded");
activePlugin.getActiveTreatments().removeTempBasal(tempBasal); activePlugin.getActiveTreatments().removeTempBasal(tempBasal);
} }
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_UNCERTAIN_TBR));
} }
private void handleActivePodAlerts() { private void handleActivePodAlerts() {
@ -1030,7 +1033,7 @@ public class OmnipodPumpPlugin extends PumpPluginBase implements PumpInterface,
} }
if (!success) { if (!success) {
aapsLogger.warn(LTag.PUMP, "Failed to retrieve Pod status on startup"); aapsLogger.warn(LTag.PUMP, "Failed to retrieve Pod status on startup");
rxBus.send(new EventNewNotification(new Notification(Notification.OMNIPOD_PUMP_ALARM, resourceHelper.gs(R.string.omnipod_error_failed_to_refresh_status_on_startup), Notification.NORMAL))); rxBus.send(new EventNewNotification(new Notification(Notification.OMNIPOD_STARTUP_STATUS_REFRESH_FAILED, resourceHelper.gs(R.string.omnipod_error_failed_to_refresh_status_on_startup), Notification.NORMAL)));
} }
} else { } else {
aapsLogger.debug(LTag.PUMP, "Not retrieving Pod status on startup: no Pod running"); aapsLogger.debug(LTag.PUMP, "Not retrieving Pod status on startup: no Pod running");

View file

@ -105,14 +105,14 @@ public abstract class PodStateManager {
/** /**
* @return true if the Pod's activation time has been exceeded * @return true if the Pod's activation time has been exceeded
*/ */
public boolean isPodActivationTimeExceeded() { public final boolean isPodActivationTimeExceeded() {
return isPodInitialized() && getPodProgressStatus() == PodProgressStatus.ACTIVATION_TIME_EXCEEDED; return isPodInitialized() && getPodProgressStatus() == PodProgressStatus.ACTIVATION_TIME_EXCEEDED;
} }
/** /**
* @return true if we have a Pod state and the Pod is dead, meaning it is either in a fault state or activation time has been exceeded or it is deactivated * @return true if we have a Pod state and the Pod is dead, meaning it is either in a fault state or activation time has been exceeded or it is deactivated
*/ */
public boolean isPodDead() { public final boolean isPodDead() {
return isPodInitialized() && getPodProgressStatus().isDead(); return isPodInitialized() && getPodProgressStatus().isDead();
} }
@ -603,6 +603,8 @@ public abstract class PodStateManager {
podState.setLastUpdatedFromResponse(DateTime.now()); podState.setLastUpdatedFromResponse(DateTime.now());
}); });
onUpdatedFromResponse();
} }
protected void onTbrChanged() { protected void onTbrChanged() {
@ -625,6 +627,11 @@ public abstract class PodStateManager {
// Can be overridden in subclasses // Can be overridden in subclasses
} }
protected void onUpdatedFromResponse() {
// Deliberately left empty
// Can be overridden in subclasses
}
private void setAndStore(Runnable runnable) { private void setAndStore(Runnable runnable) {
setSafe(runnable); setSafe(runnable);
storePodState(); storePodState();

View file

@ -222,7 +222,7 @@ public class AapsOmnipodManager {
uploadCareportalEvent(System.currentTimeMillis() - 1000, CareportalEvent.INSULINCHANGE); uploadCareportalEvent(System.currentTimeMillis() - 1000, CareportalEvent.INSULINCHANGE);
uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE); uploadCareportalEvent(System.currentTimeMillis(), CareportalEvent.SITECHANGE);
sendEvent(new EventDismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED)); dismissNotification(Notification.OMNIPOD_POD_NOT_ATTACHED);
cancelSuspendedFakeTbrIfExists(); cancelSuspendedFakeTbrIfExists();
} }
@ -269,6 +269,7 @@ public class AapsOmnipodManager {
} }
addSuccessToHistory(PodHistoryEntryType.GET_POD_STATUS, statusResponse); addSuccessToHistory(PodHistoryEntryType.GET_POD_STATUS, statusResponse);
return new PumpEnactResult(injector).success(true).enacted(false); return new PumpEnactResult(injector).success(true).enacted(false);
} }
@ -284,13 +285,17 @@ public class AapsOmnipodManager {
addSuccessToHistory(PodHistoryEntryType.DEACTIVATE_POD, null); addSuccessToHistory(PodHistoryEntryType.DEACTIVATE_POD, null);
createSuspendedFakeTbrIfNotExists(); createSuspendedFakeTbrIfNotExists();
dismissNotification(Notification.OMNIPOD_POD_FAULT);
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
public PumpEnactResult setBasalProfile(Profile profile, boolean showNotifications) { public PumpEnactResult setBasalProfile(Profile profile, boolean showNotifications) {
if (profile == null) { if (profile == null) {
String note = getStringResource(R.string.omnipod_error_failed_to_set_profile_empty_profile); String note = getStringResource(R.string.omnipod_error_failed_to_set_profile_empty_profile);
showNotification(Notification.FAILED_UDPATE_PROFILE, note, Notification.URGENT, R.raw.boluserror); if (showNotifications) {
showNotification(Notification.FAILED_UDPATE_PROFILE, note, Notification.URGENT, R.raw.boluserror);
}
return new PumpEnactResult(injector).success(false).enacted(false).comment(note); return new PumpEnactResult(injector).success(false).enacted(false).comment(note);
} }
@ -329,16 +334,20 @@ public class AapsOmnipodManager {
return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage); return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage);
} }
if (historyEntryType == PodHistoryEntryType.RESUME_DELIVERY) { if (historyEntryType == PodHistoryEntryType.RESUME_DELIVERY) {
cancelSuspendedFakeTbrIfExists(); cancelSuspendedFakeTbrIfExists();
sendEvent(new EventDismissNotification(Notification.OMNIPOD_POD_SUSPENDED));
} }
addSuccessToHistory(historyEntryType, profile.getBasalValues()); addSuccessToHistory(historyEntryType, profile.getBasalValues());
if (showNotifications) { if (showNotifications) {
showNotification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, null); showNotification(Notification.PROFILE_SET_OK, resourceHelper.gs(R.string.profile_set_ok), Notification.INFO, null);
} }
dismissNotification(Notification.FAILED_UDPATE_PROFILE);
dismissNotification(Notification.OMNIPOD_POD_SUSPENDED);
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@ -349,8 +358,9 @@ public class AapsOmnipodManager {
createSuspendedFakeTbrIfNotExists(); createSuspendedFakeTbrIfNotExists();
dismissNotification(Notification.OMNIPOD_POD_FAULT);
sendEvent(new EventOmnipodPumpValuesChanged()); sendEvent(new EventOmnipodPumpValuesChanged());
rxBus.send(new EventRefreshOverview("Omnipod command: " + OmnipodCommandType.DISCARD_POD, false)); sendEvent(new EventRefreshOverview("Omnipod command: " + OmnipodCommandType.DISCARD_POD, false));
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@ -380,7 +390,7 @@ public class AapsOmnipodManager {
if (OmnipodManager.CommandDeliveryStatus.UNCERTAIN_FAILURE.equals(bolusCommandResult.getCommandDeliveryStatus())) { if (OmnipodManager.CommandDeliveryStatus.UNCERTAIN_FAILURE.equals(bolusCommandResult.getCommandDeliveryStatus())) {
// For safety reasons, we treat this as a bolus that has successfully been delivered, in order to prevent insulin overdose // For safety reasons, we treat this as a bolus that has successfully been delivered, in order to prevent insulin overdose
if (detailedBolusInfo.isSMB) { if (detailedBolusInfo.isSMB) {
showNotification(getStringResource(R.string.omnipod_error_bolus_failed_uncertain_smb, detailedBolusInfo.insulin), Notification.URGENT, isNotificationUncertainSmbSoundEnabled() ? R.raw.boluserror : null); showNotification(Notification.OMNIPOD_UNCERTAIN_SMB, getStringResource(R.string.omnipod_error_bolus_failed_uncertain_smb, detailedBolusInfo.insulin), Notification.URGENT, isNotificationUncertainSmbSoundEnabled() ? R.raw.boluserror : null);
} else { } else {
showErrorDialog(getStringResource(R.string.omnipod_error_bolus_failed_uncertain), isNotificationUncertainBolusSoundEnabled() ? R.raw.boluserror : null); showErrorDialog(getStringResource(R.string.omnipod_error_bolus_failed_uncertain), isNotificationUncertainBolusSoundEnabled() ? R.raw.boluserror : null);
} }
@ -483,7 +493,7 @@ public class AapsOmnipodManager {
String errorMessage = translateException(ex.getCause()); String errorMessage = translateException(ex.getCause());
addFailureToHistory(PodHistoryEntryType.SET_TEMPORARY_BASAL, errorMessage); addFailureToHistory(PodHistoryEntryType.SET_TEMPORARY_BASAL, errorMessage);
showNotification(getStringResource(R.string.omnipod_error_set_temp_basal_failed_old_tbr_might_be_cancelled), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null); showNotification(Notification.OMNIPOD_UNCERTAIN_TBR, getStringResource(R.string.omnipod_error_set_temp_basal_failed_old_tbr_might_be_cancelled), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null);
splitActiveTbr(); // Split any active TBR so when we recover from the uncertain TBR status,we only cancel the part after the cancellation splitActiveTbr(); // Split any active TBR so when we recover from the uncertain TBR status,we only cancel the part after the cancellation
@ -493,7 +503,7 @@ public class AapsOmnipodManager {
long pumpId = addFailureToHistory(PodHistoryEntryType.SET_TEMPORARY_BASAL, errorMessage); long pumpId = addFailureToHistory(PodHistoryEntryType.SET_TEMPORARY_BASAL, errorMessage);
if (!OmnipodManager.isCertainFailure(ex)) { if (!OmnipodManager.isCertainFailure(ex)) {
showNotification(getStringResource(R.string.omnipod_error_set_temp_basal_failed_old_tbr_cancelled_new_might_have_failed), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null); showNotification(Notification.OMNIPOD_UNCERTAIN_TBR, getStringResource(R.string.omnipod_error_set_temp_basal_failed_old_tbr_cancelled_new_might_have_failed), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null);
// Assume that setting the temp basal succeeded here, because in case it didn't succeed, // Assume that setting the temp basal succeeded here, because in case it didn't succeed,
// The next StatusResponse that we receive will allow us to recover from the wrong state // The next StatusResponse that we receive will allow us to recover from the wrong state
@ -523,7 +533,7 @@ public class AapsOmnipodManager {
executeCommand(() -> delegate.cancelTemporaryBasal(isTbrBeepsEnabled())); executeCommand(() -> delegate.cancelTemporaryBasal(isTbrBeepsEnabled()));
} catch (Exception ex) { } catch (Exception ex) {
if (OmnipodManager.isCertainFailure(ex)) { if (OmnipodManager.isCertainFailure(ex)) {
showNotification(getStringResource(R.string.omnipod_error_cancel_temp_basal_failed_uncertain), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null); showNotification(Notification.OMNIPOD_UNCERTAIN_TBR, getStringResource(R.string.omnipod_error_cancel_temp_basal_failed_uncertain), Notification.URGENT, isNotificationUncertainTbrSoundEnabled() ? R.raw.boluserror : null);
} else { } else {
splitActiveTbr(); // Split any active TBR so when we recover from the uncertain TBR status,we only cancel the part after the cancellation splitActiveTbr(); // Split any active TBR so when we recover from the uncertain TBR status,we only cancel the part after the cancellation
} }
@ -580,21 +590,21 @@ public class AapsOmnipodManager {
} catch (CommandFailedAfterChangingDeliveryStatusException ex) { } catch (CommandFailedAfterChangingDeliveryStatusException ex) {
createSuspendedFakeTbrIfNotExists(); createSuspendedFakeTbrIfNotExists();
if (showNotifications) { if (showNotifications) {
showNotification(getStringResource(R.string.omnipod_error_set_time_failed_delivery_suspended), Notification.URGENT, R.raw.boluserror); showNotification(Notification.FAILED_UDPATE_PROFILE, getStringResource(R.string.omnipod_error_set_time_failed_delivery_suspended), Notification.URGENT, R.raw.boluserror);
} }
String errorMessage = translateException(ex.getCause()); String errorMessage = translateException(ex.getCause());
addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage); addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage);
return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage); return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage);
} catch (PrecedingCommandFailedUncertainlyException ex) { } catch (PrecedingCommandFailedUncertainlyException ex) {
if (showNotifications) { if (showNotifications) {
showNotification(getStringResource(R.string.omnipod_error_set_time_failed_delivery_might_be_suspended), Notification.URGENT, R.raw.boluserror); showNotification(Notification.FAILED_UDPATE_PROFILE, getStringResource(R.string.omnipod_error_set_time_failed_delivery_might_be_suspended), Notification.URGENT, R.raw.boluserror);
} }
String errorMessage = translateException(ex.getCause()); String errorMessage = translateException(ex.getCause());
addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage); addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage);
return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage); return new PumpEnactResult(injector).success(false).enacted(false).comment(errorMessage);
} catch (Exception ex) { } catch (Exception ex) {
if (showNotifications) { if (showNotifications) {
showNotification(getStringResource(R.string.omnipod_error_set_time_failed_delivery_might_be_suspended), Notification.URGENT, R.raw.boluserror); showNotification(Notification.FAILED_UDPATE_PROFILE, getStringResource(R.string.omnipod_error_set_time_failed_delivery_might_be_suspended), Notification.URGENT, R.raw.boluserror);
} }
String errorMessage = translateException(ex); String errorMessage = translateException(ex);
addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage); addFailureToHistory(PodHistoryEntryType.SET_TIME, errorMessage);
@ -602,6 +612,10 @@ public class AapsOmnipodManager {
} }
addSuccessToHistory(PodHistoryEntryType.SET_TIME, null); addSuccessToHistory(PodHistoryEntryType.SET_TIME, null);
dismissNotification(Notification.FAILED_UDPATE_PROFILE);
dismissNotification(Notification.OMNIPOD_POD_SUSPENDED);
return new PumpEnactResult(injector).success(true).enacted(true); return new PumpEnactResult(injector).success(true).enacted(true);
} }
@ -937,11 +951,7 @@ public class AapsOmnipodManager {
} }
private void showPodFaultNotification(FaultEventCode faultEventCode, Integer sound) { private void showPodFaultNotification(FaultEventCode faultEventCode, Integer sound) {
showNotification(createPodFaultErrorMessage(faultEventCode), Notification.URGENT, sound); showNotification(Notification.OMNIPOD_POD_FAULT, createPodFaultErrorMessage(faultEventCode), Notification.URGENT, sound);
}
private void showNotification(String message, int urgency, Integer sound) {
showNotification(Notification.OMNIPOD_PUMP_ALARM, message, urgency, sound);
} }
private void showNotification(int id, String message, int urgency, Integer sound) { private void showNotification(int id, String message, int urgency, Integer sound) {
@ -955,6 +965,10 @@ public class AapsOmnipodManager {
sendEvent(new EventNewNotification(notification)); sendEvent(new EventNewNotification(notification));
} }
private void dismissNotification(int id) {
sendEvent(new EventDismissNotification(id));
}
private String getStringResource(int id, Object... args) { private String getStringResource(int id, Object... args) {
return resourceHelper.gs(id, args); return resourceHelper.gs(id, args);
} }

View file

@ -5,6 +5,8 @@ import javax.inject.Singleton;
import info.nightscout.androidaps.logging.AAPSLogger; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper; import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorageKeys; import info.nightscout.androidaps.plugins.pump.omnipod.definition.OmnipodStorageKeys;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager; import info.nightscout.androidaps.plugins.pump.omnipod.driver.manager.PodStateManager;
import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodActiveAlertsChanged; import info.nightscout.androidaps.plugins.pump.omnipod.event.EventOmnipodActiveAlertsChanged;
@ -50,4 +52,8 @@ public class AapsPodStateManager extends PodStateManager {
@Override protected void onFaultEventChanged() { @Override protected void onFaultEventChanged() {
rxBus.send(new EventOmnipodFaultEventChanged()); rxBus.send(new EventOmnipodFaultEventChanged());
} }
@Override protected void onUpdatedFromResponse() {
rxBus.send(new EventDismissNotification(Notification.OMNIPOD_STARTUP_STATUS_REFRESH_FAILED));
}
} }

View file

@ -16,6 +16,8 @@ import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange import info.nightscout.androidaps.plugins.pump.common.events.EventRileyLinkDeviceStatusChange
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice
@ -126,7 +128,8 @@ class OmnipodOverviewFragment : DaggerFragment() {
disablePodActionButtons() disablePodActionButtons()
commandQueue.customCommand(CommandAcknowledgeAlerts(), commandQueue.customCommand(CommandAcknowledgeAlerts(),
DisplayResultDialogCallback(resourceHelper.gs(R.string.omnipod_error_failed_to_acknowledge_alerts), false) DisplayResultDialogCallback(resourceHelper.gs(R.string.omnipod_error_failed_to_acknowledge_alerts), false)
.messageOnSuccess(resourceHelper.gs(R.string.omnipod_confirmation_acknowledged_alerts))) .messageOnSuccess(resourceHelper.gs(R.string.omnipod_confirmation_acknowledged_alerts))
.actionOnSuccess { rxBus.send(EventDismissNotification(Notification.OMNIPOD_POD_ALERTS)) })
} }
omnipod_overview_button_suspend_delivery.setOnClickListener { omnipod_overview_button_suspend_delivery.setOnClickListener {
@ -599,6 +602,7 @@ class OmnipodOverviewFragment : DaggerFragment() {
inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() { inner class DisplayResultDialogCallback(private val errorMessagePrefix: String, private val withSoundOnError: Boolean) : Callback() {
private var messageOnSuccess: String? = null private var messageOnSuccess: String? = null
private var actionOnSuccess: Runnable? = null
override fun run() { override fun run() {
if (result.success) { if (result.success) {
@ -606,6 +610,7 @@ class OmnipodOverviewFragment : DaggerFragment() {
if (messageOnSuccess != null) { if (messageOnSuccess != null) {
displayOkDialog(resourceHelper.gs(R.string.omnipod_confirmation), messageOnSuccess) displayOkDialog(resourceHelper.gs(R.string.omnipod_confirmation), messageOnSuccess)
} }
actionOnSuccess?.run()
} else { } else {
displayErrorDialog(resourceHelper.gs(R.string.omnipod_warning), resourceHelper.gs(R.string.omnipod_two_strings_concatenated_by_colon, errorMessagePrefix, result.comment), withSoundOnError) displayErrorDialog(resourceHelper.gs(R.string.omnipod_warning), resourceHelper.gs(R.string.omnipod_two_strings_concatenated_by_colon, errorMessagePrefix, result.comment), withSoundOnError)
} }
@ -615,6 +620,11 @@ class OmnipodOverviewFragment : DaggerFragment() {
messageOnSuccess = message messageOnSuccess = message
return this return this
} }
fun actionOnSuccess(action: Runnable): DisplayResultDialogCallback {
actionOnSuccess = action
return this
}
} }
} }