From 2561c3f8b6ae4bb09a1b3fc6d89b47562a1ef53b Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 18 Apr 2018 16:13:02 +0200 Subject: [PATCH] Carbs only treatments in Queue --- .../androidaps/queue/CommandQueue.java | 22 ++++++++++++------- .../androidaps/queue/commands/Command.java | 1 + .../queue/commands/CommandBolus.java | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) 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 fa15ee46d2..b522926560 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/CommandQueue.java @@ -166,14 +166,19 @@ public class CommandQueue { public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { Command.CommandType type = detailedBolusInfo.isSMB ? Command.CommandType.SMB_BOLUS : Command.CommandType.BOLUS; - if (isRunning(type)) { - if (callback != null) - callback.result(executingNowError()).run(); - return false; - } + if(type.equals(Command.CommandType.BOLUS) && detailedBolusInfo.carbs > 0 && detailedBolusInfo.insulin == 0){ + type = Command.CommandType.CARBS_ONLY_TREATMENT; + //Carbs only can be added in parallel as they can be "in the future". + } else { + if (isRunning(type)) { + if (callback != null) + callback.result(executingNowError()).run(); + return false; + } - // remove all unfinished boluses - removeAll(type); + // remove all unfinished boluses + removeAll(type); + } // apply constraints detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); @@ -183,7 +188,8 @@ public class CommandQueue { if (detailedBolusInfo.isSMB) { add(new CommandSMBBolus(detailedBolusInfo, callback)); } else { - add(new CommandBolus(detailedBolusInfo, callback)); + add(new CommandBolus(detailedBolusInfo, callback, type)); + if(type.equals(Command.CommandType.BOLUS)) // Bring up bolus progress dialog (start here, so the dialog is shown when the bolus is requested, // not when the Bolus command is starting. The command closes the dialog upon completion). showBolusProgressDialog(detailedBolusInfo.insulin, detailedBolusInfo.context); diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java index c5b3ada417..b865fac86e 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/Command.java @@ -12,6 +12,7 @@ public abstract class Command { public enum CommandType { BOLUS, SMB_BOLUS, + CARBS_ONLY_TREATMENT, TEMPBASAL, EXTENDEDBOLUS, BASALPROFILE, diff --git a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java index 278fd7681b..cab7d23311 100644 --- a/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/queue/commands/CommandBolus.java @@ -16,8 +16,8 @@ import info.nightscout.utils.DecimalFormatter; public class CommandBolus extends Command { DetailedBolusInfo detailedBolusInfo; - public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { - commandType = CommandType.BOLUS; + public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback, CommandType type) { + commandType = type; this.detailedBolusInfo = detailedBolusInfo; this.callback = callback; }