Add carbs required to overview. Add notification with option to ignore carbs suggestions for 5, 15 or 30min
This commit is contained in:
parent
063d3685e1
commit
b1097880f4
|
@ -113,6 +113,9 @@
|
|||
<!-- Receiver keepalive, scheduled every 30 min -->
|
||||
<receiver android:name=".receivers.KeepAliveReceiver" />
|
||||
|
||||
<!-- Receive ignore 5m, 15m, 30m requests for carb notifications -->
|
||||
<receiver android:name=".plugins.aps.loop.CarbSuggestionReceiver"></receiver>
|
||||
|
||||
<!-- Auto start -->
|
||||
<receiver
|
||||
android:name=".receivers.AutoStartReceiver"
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.dependencyInjection
|
|||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.plugins.aps.loop.CarbSuggestionReceiver
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver
|
||||
|
||||
@Module
|
||||
|
@ -9,4 +10,6 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver
|
|||
abstract class ReceiversModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesKeepAliveReceiver(): KeepAliveReceiver
|
||||
@ContributesAndroidInjector abstract fun contributesCarbSuggestionReceiver(): CarbSuggestionReceiver
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -98,6 +98,8 @@ public class LoopPlugin extends PluginBase {
|
|||
private boolean isSuperBolus;
|
||||
private boolean isDisconnected;
|
||||
|
||||
private long carbsSuggestionsSuspendedUntil = 0;
|
||||
|
||||
public class LastRun {
|
||||
public APSResult request = null;
|
||||
public APSResult constraintsProcessed = null;
|
||||
|
@ -407,17 +409,49 @@ public class LoopPlugin extends PluginBase {
|
|||
if (closedLoopEnabled.value()) {
|
||||
|
||||
if (allowNotification) {
|
||||
if (resultAfterConstraints.isCarbsRequired()) {
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(MainApp.instance().getApplicationContext(), CHANNEL_ID);
|
||||
if (resultAfterConstraints.isCarbsRequired() && carbsSuggestionsSuspendedUntil < System.currentTimeMillis()) {
|
||||
|
||||
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)
|
||||
.setContentTitle(MainApp.gs(R.string.carbssuggestion))
|
||||
.setContentTitle(resourceHelper.gs(R.string.carbssuggestion))
|
||||
.setContentText(resultAfterConstraints.getCarbsRequiredText())
|
||||
.setAutoCancel(true)
|
||||
.setPriority(Notification.PRIORITY_MAX)
|
||||
.setCategory(Notification.CATEGORY_ALARM)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
|
||||
presentSuggestion(builder);
|
||||
.addAction(actionIgnore5m)
|
||||
.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 {
|
||||
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) {
|
||||
// Creates an explicit intent for an Activity in your app
|
||||
Intent resultIntent = new Intent(context, MainActivity.class);
|
||||
|
|
|
@ -165,6 +165,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
TextView activeProfileView;
|
||||
TextView iobView;
|
||||
TextView cobView;
|
||||
TextView cobRequiredView;
|
||||
TextView apsModeView;
|
||||
TextView tempTargetView;
|
||||
TextView pumpStatusView;
|
||||
|
@ -277,6 +278,8 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
|
||||
iobView = (TextView) view.findViewById(R.id.overview_iob);
|
||||
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);
|
||||
tempTargetView = (TextView) view.findViewById(R.id.overview_temptarget);
|
||||
|
||||
|
@ -1331,6 +1334,17 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
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 (sp.getBoolean(R.string.key_show_statuslights, false)) {
|
||||
if (sp.getBoolean(R.string.key_show_statuslights_extended, false)) {
|
||||
|
|
|
@ -266,6 +266,18 @@
|
|||
app:layout_constraintBottom_toBottomOf="@+id/overview_cob_label"
|
||||
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 -->
|
||||
<TextView
|
||||
android:id="@+id/overview_basebasal_label"
|
||||
|
|
|
@ -1710,5 +1710,7 @@
|
|||
<string name="loop_smbexecution_time_label">SMB execution 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="cob_required">(20g needed in 45min)</string>
|
||||
<string name="overview_carbs_required">(%dg needed in %dmin)</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue