Fix bolus progress dialog with bolus cancel

This commit is contained in:
TebbeUbben 2019-02-09 23:50:12 +01:00
parent 4146c8a770
commit 7a4d721c29

View file

@ -69,12 +69,7 @@ import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.his
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.StartOfTBREvent;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TotalDailyDoseEvent;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.history.history_events.TubeFilledEvent;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.ActiveBRProfileBlock;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile1Block;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile2Block;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile3Block;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile4Block;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfile5Block;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.BRProfileBlock;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.FactoryMinBolusAmountBlock;
import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock; import info.nightscout.androidaps.plugins.PumpInsightLocal.app_layer.parameter_blocks.MaxBasalAmountBlock;
@ -155,7 +150,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
}; };
private final Object $bolusLock = new Object[0]; private final Object $bolusLock = new Object[0];
private int bolusID = -1; private int bolusID;
private boolean bolusCancelled;
private List<BasalProfileBlock> profileBlocks; private List<BasalProfileBlock> profileBlocks;
private boolean limitsFetched; private boolean limitsFetched;
private double maximumBolusAmount; private double maximumBolusAmount;
@ -269,7 +265,8 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public boolean isConnecting() { public boolean isConnecting() {
if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this)) return false; if (connectionService == null || alertService == null || !connectionService.hasRequestedConnection(this))
return false;
InsightState state = connectionService.getState(); InsightState state = connectionService.getState();
return state == InsightState.CONNECTING return state == InsightState.CONNECTING
|| state == InsightState.APP_CONNECT_MESSAGE || state == InsightState.APP_CONNECT_MESSAGE
@ -517,6 +514,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
bolusMessage.setExtendedAmount(0); bolusMessage.setExtendedAmount(0);
bolusMessage.setImmediateAmount(detailedBolusInfo.insulin); bolusMessage.setImmediateAmount(detailedBolusInfo.insulin);
bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId(); bolusID = connectionService.requestMessage(bolusMessage).await().getBolusId();
bolusCancelled = false;
} }
result.success = true; result.success = true;
result.enacted = true; result.enacted = true;
@ -539,7 +537,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true); TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, true);
while (true) { while (true) {
synchronized ($bolusLock) { synchronized ($bolusLock) {
if (bolusID == -1) break; if (bolusCancelled) break;
} }
OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode(); OperatingMode operatingMode = connectionService.requestMessage(new GetOperatingModeMessage()).await().getOperatingMode();
if (operatingMode != OperatingMode.STARTED) break; if (operatingMode != OperatingMode.STARTED) break;
@ -558,11 +556,17 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount()); bolusingEvent.status = MainApp.gs(R.string.insight_delivered, activeBolus.getInitialAmount() - activeBolus.getRemainingAmount(), activeBolus.getInitialAmount());
if (percentBefore != bolusingEvent.percent) if (percentBefore != bolusingEvent.percent)
MainApp.bus().post(bolusingEvent); MainApp.bus().post(bolusingEvent);
} else if (trials == -1 || trials++ >= 5) { } else {
bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin); synchronized ($bolusLock) {
bolusingEvent.percent = 100; if (bolusCancelled || trials == -1 || trials++ >= 5) {
MainApp.bus().post(bolusingEvent); if (!bolusCancelled) {
break; bolusingEvent.status = MainApp.gs(R.string.insight_delivered, detailedBolusInfo.insulin, detailedBolusInfo.insulin);
bolusingEvent.percent = 100;
MainApp.bus().post(bolusingEvent);
}
break;
}
}
} }
Thread.sleep(200); Thread.sleep(200);
} }
@ -589,21 +593,21 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
@Override @Override
public void stopBolusDelivering() { public void stopBolusDelivering() {
new Thread(() -> { new Thread(() -> {
synchronized ($bolusLock) { try {
try { synchronized ($bolusLock) {
alertService.ignore(AlertType.WARNING_38); alertService.ignore(AlertType.WARNING_38);
CancelBolusMessage cancelBolusMessage = new CancelBolusMessage(); CancelBolusMessage cancelBolusMessage = new CancelBolusMessage();
cancelBolusMessage.setBolusID(bolusID); cancelBolusMessage.setBolusID(bolusID);
connectionService.requestMessage(cancelBolusMessage).await(); connectionService.requestMessage(cancelBolusMessage).await();
bolusID = -1; bolusCancelled = true;
confirmAlert(AlertType.WARNING_38);
} catch (AppLayerErrorException e) {
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
} catch (InsightException e) {
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
} catch (Exception e) {
log.error("Exception while canceling bolus", e);
} }
confirmAlert(AlertType.WARNING_38);
} catch (AppLayerErrorException e) {
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
} catch (InsightException e) {
log.info("Exception while canceling bolus: " + e.getClass().getCanonicalName());
} catch (Exception e) {
log.error("Exception while canceling bolus", e);
} }
}).start(); }).start();
} }