Merge branch 'carbs-gen-pr' of https://github.com/MilosKozak/AndroidAPS into carbs-gen-pr

This commit is contained in:
Milos Kozak 2018-04-19 09:35:15 +02:00
commit 6431b9cc25
3 changed files with 23 additions and 15 deletions

View file

@ -166,14 +166,19 @@ public class CommandQueue {
public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { public boolean bolus(DetailedBolusInfo detailedBolusInfo, Callback callback) {
Command.CommandType type = detailedBolusInfo.isSMB ? Command.CommandType.SMB_BOLUS : Command.CommandType.BOLUS; Command.CommandType type = detailedBolusInfo.isSMB ? Command.CommandType.SMB_BOLUS : Command.CommandType.BOLUS;
if (isRunning(type)) { if(type.equals(Command.CommandType.BOLUS) && detailedBolusInfo.carbs > 0 && detailedBolusInfo.insulin == 0){
if (callback != null) type = Command.CommandType.CARBS_ONLY_TREATMENT;
callback.result(executingNowError()).run(); //Carbs only can be added in parallel as they can be "in the future".
return false; } else {
} if (isRunning(type)) {
if (callback != null)
callback.result(executingNowError()).run();
return false;
}
// remove all unfinished boluses // remove all unfinished boluses
removeAll(type); removeAll(type);
}
// apply constraints // apply constraints
detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value(); detailedBolusInfo.insulin = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(detailedBolusInfo.insulin)).value();
@ -183,12 +188,14 @@ public class CommandQueue {
if (detailedBolusInfo.isSMB) { if (detailedBolusInfo.isSMB) {
add(new CommandSMBBolus(detailedBolusInfo, callback)); add(new CommandSMBBolus(detailedBolusInfo, callback));
} else { } else {
add(new CommandBolus(detailedBolusInfo, callback)); add(new CommandBolus(detailedBolusInfo, callback, type));
// Bring up bolus progress dialog (start here, so the dialog is shown when the bolus is requested, if(type.equals(Command.CommandType.BOLUS)) {
// not when the Bolus command is starting. The command closes the dialog upon completion). // Bring up bolus progress dialog (start here, so the dialog is shown when the bolus is requested,
showBolusProgressDialog(detailedBolusInfo.insulin, detailedBolusInfo.context); // not when the Bolus command is starting. The command closes the dialog upon completion).
// Notify Wear about upcoming bolus showBolusProgressDialog(detailedBolusInfo.insulin, detailedBolusInfo.context);
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin)); // Notify Wear about upcoming bolus
MainApp.bus().post(new EventBolusRequested(detailedBolusInfo.insulin));
}
} }
notifyAboutNewCommand(); notifyAboutNewCommand();

View file

@ -12,6 +12,7 @@ public abstract class Command {
public enum CommandType { public enum CommandType {
BOLUS, BOLUS,
SMB_BOLUS, SMB_BOLUS,
CARBS_ONLY_TREATMENT,
TEMPBASAL, TEMPBASAL,
EXTENDEDBOLUS, EXTENDEDBOLUS,
BASALPROFILE, BASALPROFILE,

View file

@ -16,8 +16,8 @@ import info.nightscout.utils.DecimalFormatter;
public class CommandBolus extends Command { public class CommandBolus extends Command {
DetailedBolusInfo detailedBolusInfo; DetailedBolusInfo detailedBolusInfo;
public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback) { public CommandBolus(DetailedBolusInfo detailedBolusInfo, Callback callback, CommandType type) {
commandType = CommandType.BOLUS; commandType = type;
this.detailedBolusInfo = detailedBolusInfo; this.detailedBolusInfo = detailedBolusInfo;
this.callback = callback; this.callback = callback;
} }