Get Singleton Notification

This commit is contained in:
AdrianLxM 2019-06-30 15:57:04 +02:00 committed by GitHub
parent d42794137f
commit 1282e3ed9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -52,6 +52,7 @@ import info.nightscout.androidaps.utils.DecimalFormatter;
public class PersistentNotificationPlugin extends PluginBase { public class PersistentNotificationPlugin extends PluginBase {
private static PersistentNotificationPlugin plugin; private static PersistentNotificationPlugin plugin;
private Notification notification;
public static PersistentNotificationPlugin getPlugin() { public static PersistentNotificationPlugin getPlugin() {
if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance()); if (plugin == null) plugin = new PersistentNotificationPlugin(MainApp.instance());
@ -122,7 +123,7 @@ public class PersistentNotificationPlugin extends PluginBase {
} }
@Nonnull @Nonnull
public Notification updateNotification() { Notification updateNotification() {
String line1 = null; String line1 = null;
String line2 = null; String line2 = null;
String line3 = null; String line3 = null;
@ -250,6 +251,7 @@ public class PersistentNotificationPlugin extends PluginBase {
android.app.Notification notification = builder.build(); android.app.Notification notification = builder.build();
mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification); mNotificationManager.notify(ONGOING_NOTIFICATION_ID, notification);
this.notification = notification;
return notification; return notification;
} }
@ -269,6 +271,17 @@ public class PersistentNotificationPlugin extends PluginBase {
return deltastring; return deltastring;
} }
/***
* returns the current ongoing notification.
*
* If it does not exist, return a dummy notification. This should only happen if onStart() wasn't called.
*/
public Notification getLastNotification() {
if (notification != null) return notification;
else return new Notification();
}
@Subscribe @Subscribe
public void onStatusEvent(final EventPreferenceChange ev) { public void onStatusEvent(final EventPreferenceChange ev) {