Skip to content

Commit 1283a13

Browse files
committed
2 parents 493bcb6 + b085c1a commit 1283a13

File tree

3 files changed

+58
-61
lines changed

3 files changed

+58
-61
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/utilitymodels/Notifications.java

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public class Notifications extends IntentService {
6969
//public static boolean bg_vibrate;
7070
// public static boolean bg_lights;
7171
// public static boolean bg_sound;
72+
public static boolean compact_persistent_notification;
7273
public static boolean bg_sound_in_silent;
7374
public static String bg_notification_sound;
7475

@@ -171,6 +172,7 @@ public void ReadPerfs(Context context) {
171172
smart_snoozing = prefs.getBoolean("smart_snoozing", true);
172173
smart_alerting = prefs.getBoolean("smart_alerting", true);
173174
bg_ongoing = prefs.getBoolean("run_service_in_foreground", false);
175+
compact_persistent_notification = Pref.getBooleanDefaultFalse("compact_persistent_notification");
174176
}
175177

176178
/*
@@ -309,7 +311,7 @@ private boolean notificationSetter(Context context) {
309311
final long start = end - (60000 * 60 * 3) - (60000 * 10);
310312
BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context, start, end);
311313
//BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(context);
312-
if (bg_ongoing && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)) {
314+
if (bg_ongoing) {
313315
bgOngoingNotification(bgGraphBuilder);
314316
}
315317
if (prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()) {
@@ -600,42 +602,42 @@ public synchronized Notification createOngoingNotification(BgGraphBuilder bgGrap
600602
}
601603
b.setOngoing(Pref.getBoolean("use_proper_ongoing", true));
602604
try {
603-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
604-
b.setGroup("xDrip ongoing");
605-
}
605+
b.setGroup("xDrip ongoing");
606606
} catch (Exception e) {
607607
//
608608
}
609-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
610-
b.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE);
611-
b.setCategory(NotificationCompat.CATEGORY_STATUS);
612-
}
609+
b.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE);
610+
b.setCategory(NotificationCompat.CATEGORY_STATUS);
613611
if (Pref.getBooleanDefaultFalse("high_priority_notifications")) {
614612
b.setPriority(Notification.PRIORITY_HIGH);
615613
}
616614
final BestGlucose.DisplayGlucose dg = (use_best_glucose) ? BestGlucose.getDisplayGlucose() : null;
617615
final boolean use_color_in_notification = false; // could be preference option
618616
final SpannableString titleString = new SpannableString(lastReading == null ? "BG Reading Unavailable" : (dg != null) ? (dg.spannableString(dg.unitized + " " + dg.delta_arrow,use_color_in_notification))
619617
: (lastReading.displayValue(mContext) + " " + lastReading.slopeArrow()));
620-
b.setContentTitle(titleString)
621-
.setContentText("xDrip Data collection service is running.")
622-
.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
623-
.setUsesChronometer(false);
618+
if (!compact_persistent_notification) {
619+
b.setContentTitle(titleString)
620+
.setContentText("xDrip Data collection service is running.")
621+
.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
622+
.setUsesChronometer(false);
623+
} else {
624+
b.setSmallIcon(R.drawable.ic_action_communication_invert_colors_on)
625+
.setUsesChronometer(false);
626+
}
624627

625628
Bitmap numberIcon = null;
626629

627-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
628-
// in case the graphic crashes the system-ui we wont do it immediately after reboot so the
629-
// user has a chance to disable the feature
630-
if (SystemClock.uptimeMillis() > Constants.MINUTE_IN_MS * 15) {
631-
if (NumberGraphic.numberIconEnabled()) {
632-
if ((dg != null) && (!dg.isStale())) {
633-
final Bitmap icon_bitmap = NumberGraphic.getSmallIconBitmap(dg.unitized);
634-
if (icon_bitmap != null) b.setSmallIcon(Icon.createWithBitmap(icon_bitmap));
635-
636-
}
630+
// in case the graphic crashes the system-ui we wont do it immediately after reboot so the
631+
// user has a chance to disable the feature
632+
if (SystemClock.uptimeMillis() > Constants.MINUTE_IN_MS * 15) {
633+
if (NumberGraphic.numberIconEnabled()) {
634+
if ((dg != null) && (!dg.isStale())) {
635+
final Bitmap icon_bitmap = NumberGraphic.getSmallIconBitmap(dg.unitized);
636+
if (icon_bitmap != null) b.setSmallIcon(Icon.createWithBitmap(icon_bitmap));
637637
}
638+
}
638639

640+
if (!compact_persistent_notification) {
639641
if (NumberGraphic.largeWithArrowEnabled()) {
640642
if ((dg != null) && (!dg.isStale())) {
641643
numberIcon = NumberGraphic.getLargeWithArrowBitmap(dg.unitized, dg.delta_arrow);
@@ -649,26 +651,26 @@ public synchronized Notification createOngoingNotification(BgGraphBuilder bgGrap
649651
}
650652

651653
if (lastReading != null) {
654+
if (!compact_persistent_notification) {
652655

653-
b.setWhen(lastReading.timestamp);
654-
b.setShowWhen(true);
656+
b.setWhen(lastReading.timestamp);
657+
b.setShowWhen(true);
655658

656-
final SpannableString deltaString = new SpannableString("Delta: " + ((dg != null) ? (dg.spannableString(dg.unitized_delta + (dg.from_plugin ? " "+context.getString(R.string.p_in_circle) : "")))
657-
: bgGraphBuilder.unitizedDeltaString(true, true)));
659+
final SpannableString deltaString = new SpannableString("Delta: " + ((dg != null) ? (dg.spannableString(dg.unitized_delta + (dg.from_plugin ? " " + context.getString(R.string.p_in_circle) : "")))
660+
: bgGraphBuilder.unitizedDeltaString(true, true)));
658661

659-
b.setContentText(deltaString);
662+
b.setContentText(deltaString);
660663

661-
notifiationBitmap = new BgSparklineBuilder(mContext)
662-
.setBgGraphBuilder(bgGraphBuilder)
663-
.showHighLine()
664-
.showLowLine()
665-
.setStart(System.currentTimeMillis() - 60000 * 60 * 3)
666-
.showAxes(true)
667-
.setBackgroundColor(getCol(X.color_notification_chart_background))
668-
.setShowFiltered(DexCollectionType.hasFiltered() && Pref.getBooleanDefaultFalse("show_filtered_curve"))
669-
.build();
664+
notifiationBitmap = new BgSparklineBuilder(mContext)
665+
.setBgGraphBuilder(bgGraphBuilder)
666+
.showHighLine()
667+
.showLowLine()
668+
.setStart(System.currentTimeMillis() - 60000 * 60 * 3)
669+
.showAxes(true)
670+
.setBackgroundColor(getCol(X.color_notification_chart_background))
671+
.setShowFiltered(DexCollectionType.hasFiltered() && Pref.getBooleanDefaultFalse("show_filtered_curve"))
672+
.build();
670673

671-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
672674
Notification.DecoratedCustomViewStyle customViewStyle = new Notification.DecoratedCustomViewStyle();
673675

674676
iconBitmap = numberIcon != null ? numberIcon : new BgSparklineBuilder(mContext)
@@ -693,29 +695,12 @@ public synchronized Notification createOngoingNotification(BgGraphBuilder bgGrap
693695
b.setStyle(customViewStyle)
694696
.setCustomContentView(collapsedViews)
695697
.setCustomBigContentView(expandedViews);
696-
} else {
697-
iconBitmap = numberIcon != null ? numberIcon : new BgSparklineBuilder(mContext)
698-
.setHeight(64)
699-
.setWidth(64)
700-
.setStart(System.currentTimeMillis() - 60000 * 60 * 3)
701-
.setBgGraphBuilder(bgGraphBuilder)
702-
.setBackgroundColor(getCol(X.color_notification_chart_background))
703-
.build();
704-
b.setLargeIcon(iconBitmap);
705-
706-
Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle();
707-
bigPictureStyle.bigPicture(notifiationBitmap)
708-
.setSummaryText(deltaString)
709-
.setBigContentTitle(titleString);
710-
b.setStyle(bigPictureStyle);
711698
}
712699
}
713700

714701
b.setContentIntent(resultPendingIntent);
715-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
716-
b.setLocalOnly(true);
717-
b.setOnlyAlertOnce(true);
718-
}
702+
b.setLocalOnly(true);
703+
b.setOnlyAlertOnce(true);
719704
// strips channel ID if disabled
720705
return XdripNotification.build(b);
721706
}

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@
273273
<string name="dexcom_transmitter_id">Dexcom Transmitter ID</string>
274274
<string name="run_collector_in_foreground">Run Collector in foreground</string>
275275
<string name="shows_a_persistent_notification">Shows a persistent notification graph, visible on lock-screen and prevents Android killing the service.</string>
276+
<string name="title_collector_in_foreground">Collector in foreground</string>
277+
<string name="summary_compact_ongoing_notification">Enable to hide the graph in the notification and display only the current glucose value.</string>
278+
<string name="title_compact_ongoing_notification">Compact Persistent Notification</string>
276279
<string name="list_of_receivers">List of receivers</string>
277280
<string name="extra_tags_for_logging">Extra tags for logging</string>
278281
<string name="extra_tags_dialog_message">The tags entered here will be logged into xDrip. Format is tag:level. Level can be v,d,i. For example bgreading:i,DexCollectionService:v. These tags will be logged with low priority to Error and event list.</string>

app/src/main/res/xml/pref_advanced_settings.xml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,11 +1536,20 @@
15361536
android:key="xdrip_other_misc_extra_screen"
15371537
android:summary=""
15381538
android:title="@string/title_Other_misc_options">
1539-
<CheckBoxPreference
1540-
android:defaultValue="true"
1541-
android:key="run_service_in_foreground"
1542-
android:summary="@string/shows_a_persistent_notification"
1543-
android:title="@string/run_collector_in_foreground" />
1539+
<PreferenceScreen
1540+
android:key="collector_in_foreground"
1541+
android:title="@string/title_collector_in_foreground">
1542+
<CheckBoxPreference
1543+
android:defaultValue="true"
1544+
android:key="run_service_in_foreground"
1545+
android:summary="@string/shows_a_persistent_notification"
1546+
android:title="@string/run_collector_in_foreground" />
1547+
<CheckBoxPreference
1548+
android:defaultValue="false"
1549+
android:key="compact_persistent_notification"
1550+
android:summary="@string/summary_compact_ongoing_notification"
1551+
android:title="@string/title_compact_ongoing_notification" />
1552+
</PreferenceScreen>
15441553
<CheckBoxPreference
15451554
android:defaultValue="false"
15461555
android:dependency="engineering_mode"

0 commit comments

Comments
 (0)