Add carbs required to overview. Add notification with option to ignore carbs suggestions for 5, 15 or 30min

This commit is contained in:
Brian Quinion 2020-03-10 18:46:14 +00:00
parent 063d3685e1
commit b1097880f4
7 changed files with 99 additions and 6 deletions

View file

@ -113,6 +113,9 @@
<!-- Receiver keepalive, scheduled every 30 min --> <!-- Receiver keepalive, scheduled every 30 min -->
<receiver android:name=".receivers.KeepAliveReceiver" /> <receiver android:name=".receivers.KeepAliveReceiver" />
<!-- Receive ignore 5m, 15m, 30m requests for carb notifications -->
<receiver android:name=".plugins.aps.loop.CarbSuggestionReceiver"></receiver>
<!-- Auto start --> <!-- Auto start -->
<receiver <receiver
android:name=".receivers.AutoStartReceiver" android:name=".receivers.AutoStartReceiver"

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.dependencyInjection
import dagger.Module import dagger.Module
import dagger.android.ContributesAndroidInjector import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.aps.loop.CarbSuggestionReceiver
import info.nightscout.androidaps.receivers.KeepAliveReceiver import info.nightscout.androidaps.receivers.KeepAliveReceiver
@Module @Module
@ -9,4 +10,6 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver
abstract class ReceiversModule { abstract class ReceiversModule {
@ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver @ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver
@ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): CarbSuggestionReceiver
} }

View file

@ -0,0 +1,20 @@
package info.nightscout.androidaps.plugins.aps.loop;
import android.content.Context;
import android.content.Intent;
import javax.inject.Inject;
import dagger.android.DaggerBroadcastReceiver;
public class CarbSuggestionReceiver extends DaggerBroadcastReceiver {
@Inject LoopPlugin loopPlugin;
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
int duartion = intent.getIntExtra("ignoreDuration", 5);
loopPlugin.disableCarbSuggestions(duartion);
}
}

View file

@ -98,6 +98,8 @@ public class LoopPlugin extends PluginBase {
private boolean isSuperBolus; private boolean isSuperBolus;
private boolean isDisconnected; private boolean isDisconnected;
private long carbsSuggestionsSuspendedUntil = 0;
public class LastRun { public class LastRun {
public APSResult request = null; public APSResult request = null;
public APSResult constraintsProcessed = null; public APSResult constraintsProcessed = null;
@ -407,17 +409,49 @@ public class LoopPlugin extends PluginBase {
if (closedLoopEnabled.value()) { if (closedLoopEnabled.value()) {
if (allowNotification) { if (allowNotification) {
if (resultAfterConstraints.isCarbsRequired()) { if (resultAfterConstraints.isCarbsRequired() && carbsSuggestionsSuspendedUntil < System.currentTimeMillis()) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(MainApp.instance().getApplicationContext(), CHANNEL_ID); Intent intentAction5m = new Intent(context, CarbSuggestionReceiver.class);
intentAction5m.putExtra("ignoreDuration",5);
PendingIntent pendingIntent5m = PendingIntent.getBroadcast(context,1, intentAction5m,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore5m = new
NotificationCompat.Action(R.drawable.ic_notif_aaps, "Ignore 5m", pendingIntent5m);
Intent intentAction15m = new Intent(context, CarbSuggestionReceiver.class);
intentAction15m.putExtra("ignoreDuration",15);
PendingIntent pendingIntent15m = PendingIntent.getBroadcast(context,1, intentAction15m,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore15m = new
NotificationCompat.Action(R.drawable.ic_notif_aaps, "Ignore 15m", pendingIntent15m);
Intent intentAction30m = new Intent(context, CarbSuggestionReceiver.class);
intentAction30m.putExtra("ignoreDuration",30);
PendingIntent pendingIntent30m = PendingIntent.getBroadcast(context,1, intentAction30m,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action actionIgnore30m = new
NotificationCompat.Action(R.drawable.ic_notif_aaps, "Ignore 30m", pendingIntent30m);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ID);
builder.setSmallIcon(R.drawable.notif_icon) builder.setSmallIcon(R.drawable.notif_icon)
.setContentTitle(MainApp.gs(R.string.carbssuggestion)) .setContentTitle(resourceHelper.gs(R.string.carbssuggestion))
.setContentText(resultAfterConstraints.getCarbsRequiredText()) .setContentText(resultAfterConstraints.getCarbsRequiredText())
.setAutoCancel(true) .setAutoCancel(true)
.setPriority(Notification.PRIORITY_MAX) .setPriority(Notification.PRIORITY_MAX)
.setCategory(Notification.CATEGORY_ALARM) .setCategory(Notification.CATEGORY_ALARM)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); .addAction(actionIgnore5m)
presentSuggestion(builder); .addAction(actionIgnore15m)
.addAction(actionIgnore30m)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(Constants.notificationID, builder.build());
rxBus.send(new EventNewOpenLoopNotification());
// Send to Wear
actionStringHandler.get().handleInitiate("changeRequest");
} else { } else {
dismissSuggestion(); dismissSuggestion();
} }
@ -493,6 +527,11 @@ public class LoopPlugin extends PluginBase {
} }
} }
public void disableCarbSuggestions(int duartionMinutes) {
carbsSuggestionsSuspendedUntil = System.currentTimeMillis() + (duartionMinutes*60*1000);
dismissSuggestion();
}
private void presentSuggestion(NotificationCompat.Builder builder) { private void presentSuggestion(NotificationCompat.Builder builder) {
// Creates an explicit intent for an Activity in your app // Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, MainActivity.class); Intent resultIntent = new Intent(context, MainActivity.class);

View file

@ -165,6 +165,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
TextView activeProfileView; TextView activeProfileView;
TextView iobView; TextView iobView;
TextView cobView; TextView cobView;
TextView cobRequiredView;
TextView apsModeView; TextView apsModeView;
TextView tempTargetView; TextView tempTargetView;
TextView pumpStatusView; TextView pumpStatusView;
@ -277,6 +278,8 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
iobView = (TextView) view.findViewById(R.id.overview_iob); iobView = (TextView) view.findViewById(R.id.overview_iob);
cobView = (TextView) view.findViewById(R.id.overview_cob); cobView = (TextView) view.findViewById(R.id.overview_cob);
cobRequiredView = (TextView) view.findViewById(R.id.overview_cob_required);
apsModeView = (TextView) view.findViewById(R.id.overview_apsmode); apsModeView = (TextView) view.findViewById(R.id.overview_apsmode);
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget); tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
@ -1331,6 +1334,17 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
cobView.setText(cobText); cobView.setText(cobText);
} }
if (cobRequiredView != null) {
if (loopPlugin.lastRun != null && loopPlugin.lastRun.constraintsProcessed != null
&& loopPlugin.lastRun.constraintsProcessed.carbsReq > 0) {
cobRequiredView.setVisibility(View.VISIBLE);
String carbsRequiredString = String.format(resourceHelper.gs(R.string.overview_carbs_required), loopPlugin.lastRun.constraintsProcessed.carbsReq, loopPlugin.lastRun.constraintsProcessed.carbsReqWithin);
cobRequiredView.setText(carbsRequiredString);
} else {
cobRequiredView.setVisibility(View.GONE);
}
}
if (statuslightsLayout != null) if (statuslightsLayout != null)
if (sp.getBoolean(R.string.key_show_statuslights, false)) { if (sp.getBoolean(R.string.key_show_statuslights, false)) {
if (sp.getBoolean(R.string.key_show_statuslights_extended, false)) { if (sp.getBoolean(R.string.key_show_statuslights_extended, false)) {

View file

@ -266,6 +266,18 @@
app:layout_constraintBottom_toBottomOf="@+id/overview_cob_label" app:layout_constraintBottom_toBottomOf="@+id/overview_cob_label"
app:layout_constraintStart_toEndOf="@+id/overview_cob_colon" /> app:layout_constraintStart_toEndOf="@+id/overview_cob_colon" />
<TextView
android:id="@+id/overview_cob_required"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:text="@string/cob_required"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@color/cobAlert"
app:layout_constraintBottom_toBottomOf="@+id/overview_cob_label"
app:layout_constraintStart_toEndOf="@+id/overview_cob" />
<!-- right side basal --> <!-- right side basal -->
<TextView <TextView
android:id="@+id/overview_basebasal_label" android:id="@+id/overview_basebasal_label"

View file

@ -1710,5 +1710,7 @@
<string name="loop_smbexecution_time_label">SMB execution time</string> <string name="loop_smbexecution_time_label">SMB execution time</string>
<string name="loop_tbrrequest_time_label">Temp basal request time</string> <string name="loop_tbrrequest_time_label">Temp basal request time</string>
<string name="loop_tbrexecution_time_label">Temp basal execution time</string> <string name="loop_tbrexecution_time_label">Temp basal execution time</string>
<string name="cob_required">(20g needed in 45min)</string>
<string name="overview_carbs_required">(%dg needed in %dmin)</string>
</resources> </resources>