Merge pull request #2778 from Tornado-Tim/carbs-watch-fix

Carbs Required Fixes
This commit is contained in:
Milos Kozak 2020-06-26 22:58:30 +02:00 committed by GitHub
commit 77142afd46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View file

@ -108,6 +108,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
private boolean isDisconnected;
private long carbsSuggestionsSuspendedUntil = 0;
private int prevCarbsreq = 0;
@Nullable private LastRun lastRun = null;
@ -396,7 +397,7 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
}
result.percent = (int) (result.rate / profile.getBasal() * 100);
// check rate for constrais
// check rate for constraints
final APSResult resultAfterConstraints = result.newAndClone(injector);
resultAfterConstraints.rateConstraint = new Constraint<>(resultAfterConstraints.rate);
resultAfterConstraints.rate = constraintChecker.applyBasalConstraints(resultAfterConstraints.rateConstraint, profile).value();
@ -414,6 +415,10 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
resultAfterConstraints.smb = 0;
}
if (lastRun != null) {
prevCarbsreq = lastRun.getConstraintsProcessed().carbsReq;
}
if (lastRun == null) lastRun = new LastRun();
lastRun.setRequest(result);
lastRun.setConstraintsProcessed(resultAfterConstraints);
@ -494,12 +499,19 @@ public class LoopPlugin extends PluginBase implements LoopInterface {
mNotificationManager.notify(Constants.notificationID, builder.build());
rxBus.send(new EventNewOpenLoopNotification());
// Send to Wear
actionStringHandler.get().handleInitiate("changeRequest");
//only send to wear if Native notifications are turned off
if (!sp.getBoolean(R.string.key_raise_notifications_as_android_notifications, false)) {
// Send to Wear
actionStringHandler.get().handleInitiate("changeRequest");
}
}
} else {
dismissSuggestion();
//If carbs were required previously, but are no longer needed, dismiss notifications
if ( prevCarbsreq > 0 ) {
dismissSuggestion();
rxBus.send(new EventDismissNotification(Notification.CARBS_REQUIRED));
}
}
}

View file

@ -748,13 +748,16 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
if (config.APS && lastRun?.constraintsProcessed != null) {
if (lastRun.constraintsProcessed!!.carbsReq > 0) {
overview_cob?.text = cobText + " | " + lastRun.constraintsProcessed!!.carbsReq + " " + resourceHelper.gs(R.string.required)
//only display carbsreq when carbs havnt been entered recently
if (treatmentsPlugin.lastCarbTime < lastRun.lastAPSRun){
cobText = cobText + " | " + lastRun.constraintsProcessed!!.carbsReq + " " + resourceHelper.gs(R.string.required)
}
overview_cob?.text = cobText
if (!carbAnimation.isRunning)
carbAnimation.start()
} else {
overview_cob?.text = cobText
if (carbAnimation.isRunning)
carbAnimation.stop()
carbAnimation.stop()
carbAnimation.selectDrawable(0);
}
}