From 25aa6f859f15f92bd04b934de280f5b6ab60aef6 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sun, 13 May 2018 23:44:12 +0200 Subject: [PATCH 1/2] On bolus cancel request, cancel all boluses. Partially addresses #646. --- .../plugins/Overview/Dialogs/BolusProgressDialog.java | 2 +- .../java/info/nightscout/androidaps/queue/CommandQueue.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java index 8ef6ec2fc6..9974471528 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/BolusProgressDialog.java @@ -112,7 +112,7 @@ public class BolusProgressDialog extends DialogFragment implements View.OnClickL stopPressed = true; stopPressedView.setVisibility(View.VISIBLE); stopButton.setVisibility(View.INVISIBLE); - ConfigBuilderPlugin.getActivePump().stopBolusDelivering(); + ConfigBuilderPlugin.getCommandQueue().cancelAllBoluses(); break; } } diff --git a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java index d2fd2a5e24..cc28eb28a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -213,6 +213,12 @@ public class CommandQueue { return true; } + public synchronized void cancelAllBoluses() { + removeAll(Command.CommandType.BOLUS); + removeAll(Command.CommandType.SMB_BOLUS); + ConfigBuilderPlugin.getActivePump().stopBolusDelivering(); + } + // returns true if command is queued public boolean tempBasalAbsolute(double absoluteRate, int durationInMinutes, boolean enforceNew, Profile profile, Callback callback) { if (!enforceNew && isRunning(Command.CommandType.TEMPBASAL)) { From 561c7fb47045d15d545d66f90a3fdae2b230f10b Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Mon, 14 May 2018 00:38:47 +0200 Subject: [PATCH 2/2] Add test. --- .../androidaps/queue/CommandQueueTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.java b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.java index c4a73ccd04..dd6493fd66 100644 --- a/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.java +++ b/app/src/test/java/info/nightscout/androidaps/queue/CommandQueueTest.java @@ -156,4 +156,24 @@ public class CommandQueueTest extends CommandQueue { public boolean isThisProfileSet(Profile profile) { return false; } + + @Test + public void callingCancelAllBolusesClearsQueue() throws Exception { + prepareMock(0d, 0); + + // add normal and SMB-bolus to queue + Assert.assertEquals(0, size()); + + bolus(new DetailedBolusInfo(), null); + + DetailedBolusInfo smb = new DetailedBolusInfo(); + smb.isSMB = true; + bolus(smb, null); + + Assert.assertEquals(2, size()); + + // cancelling all boluses clear all boluses from the queue + cancelAllBoluses(); + Assert.assertEquals(0, size()); + } }