diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java index 2bf2e4fb4f..3aa8acb17e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/services/NSClientService.java @@ -632,7 +632,14 @@ public class NSClientService extends Service { if (sgv.getMills() > latestDateInReceivedData) latestDateInReceivedData = sgv.getMills(); } - BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); + // Was that sgv more less 15 mins ago ? + boolean lessThan15MinAgo = false; + if((System.currentTimeMillis()-latestDateInReceivedData)/(60 * 1000L) < 15L ) + lessThan15MinAgo = true; + if(Notification.isAlarmForStaleData() && lessThan15MinAgo){ + MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); + } + BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); } MainApp.bus().post(new EventNSClientNewLog("LAST", DateUtil.dateAndTimeString(latestDateInReceivedData))); } catch (JSONException e) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java index 160e14c98b..34ba82c27e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/notifications/Notification.java @@ -64,6 +64,8 @@ public class Notification { public NSAlarm nsAlarm = null; public Integer soundId = null; + public Notification() { + } public Notification(int id, Date date, String text, int level, Date validTo) { this.id = id; @@ -175,9 +177,10 @@ public class Notification { return false; } - static boolean isAlarmForStaleData() { - if (SP.getLong("snoozedTo", 0L) != 0L) { - if (System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) { + public static boolean isAlarmForStaleData(){ + long snoozedTo = SP.getLong("snoozedTo", 0L); + if(snoozedTo != 0L){ + if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) { //log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds"); return false; } @@ -188,16 +191,17 @@ public class Notification { long bgReadingAgo = System.currentTimeMillis() - bgReading.date; int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60)); // Added for testing - //bgReadingAgoMin = 20; - log.debug("bgReadingAgoMin value is:" + bgReadingAgoMin); - Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins"); + // bgReadingAgoMin = 20; boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts(); - log.debug("OpenAPS Alerts enabled: " + openAPSEnabledAlerts); - // if no thresshold from Ns get it loccally - if (threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue, 15D); - // No threshold of OpenAPS Alarm so using the one for BG - // Added OpenAPSEnabledAlerts to alarm check - if ((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false)) || (bgReadingAgoMin > threshold && openAPSEnabledAlerts)) { + //log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin); + //log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L); + Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins"); + //log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts); + // if no thresshold from Ns get it loccally + if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D); + // No threshold of OpenAPS Alarm so using the one for BG + // Added OpenAPSEnabledAlerts to alarm check + if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){ return true; } //snoozing for threshold