From eb593a4557255845fcf9e10c42a987def4cc1402 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 28 Nov 2017 16:09:23 +0200 Subject: [PATCH 1/4] Update Notification.java --- .../plugins/Overview/Notification.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java index a857153c73..8e46884b48 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Notification.java @@ -59,8 +59,7 @@ public class Notification { public Date validTo = new Date(0); public NSAlarm nsAlarm = null; - public Integer soundId = null; - + public Integer soundId = null; public Notification() { } @@ -154,8 +153,9 @@ public class Notification { return false; } - static boolean isAlarmForStaleData(){ - if(SP.getLong("snoozedTo", 0L) != 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; @@ -167,15 +167,16 @@ 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); + // bgReadingAgoMin = 20; + boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts(); + //log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin); + //log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L); Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins"); - boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts(); - log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts); - // if no thresshold from Ns get it loccally + //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 + // 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; } From 723cb3349755e0ab68da4de0ec9792ede0f7416c Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 28 Nov 2017 16:15:25 +0200 Subject: [PATCH 2/4] Disabling staledata alarm on new sgv values fromNSClient --- .../plugins/NSClientInternal/services/NSClientService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 d3d17b510b..72e881fce8 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,11 @@ public class NSClientService extends Service { if (sgv.getMills() > latestDateInReceivedData) latestDateInReceivedData = sgv.getMills(); } - BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); + //log.debug("Alarm for stale data active:"+Notification.isAlarmForStaleData()); + if(Notification.isAlarmForStaleData()){ + 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) { From 542cedff9d8e598aff6aa3d80a101072457cf782 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Tue, 28 Nov 2017 16:29:18 +0200 Subject: [PATCH 3/4] check for sgv older than 15 mins --- .../plugins/NSClientInternal/services/NSClientService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 72e881fce8..de41891433 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,8 +632,11 @@ public class NSClientService extends Service { if (sgv.getMills() > latestDateInReceivedData) latestDateInReceivedData = sgv.getMills(); } - //log.debug("Alarm for stale data active:"+Notification.isAlarmForStaleData()); - if(Notification.isAlarmForStaleData()){ + // Was that sgv more than 15 mins ago ? + boolean moreThan15MinAgo = false; + if((System.currentTimeMillis()-latestDateInReceivedData)/(60 * 1000L) < 15L ) + moreThan15MinAgo = true; + if(Notification.isAlarmForStaleData() && moreThan15MinAgo){ MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); } BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta); From c56330cae734d875e68ae44e818efec94ddf1a0f Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 29 Nov 2017 09:21:55 +0200 Subject: [PATCH 4/4] Less than, not moreThan15 --- .../NSClientInternal/services/NSClientService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 de41891433..6216bd924d 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,11 +632,11 @@ public class NSClientService extends Service { if (sgv.getMills() > latestDateInReceivedData) latestDateInReceivedData = sgv.getMills(); } - // Was that sgv more than 15 mins ago ? - boolean moreThan15MinAgo = false; + // Was that sgv more less 15 mins ago ? + boolean lessThan15MinAgo = false; if((System.currentTimeMillis()-latestDateInReceivedData)/(60 * 1000L) < 15L ) - moreThan15MinAgo = true; - if(Notification.isAlarmForStaleData() && moreThan15MinAgo){ + lessThan15MinAgo = true; + if(Notification.isAlarmForStaleData() && lessThan15MinAgo){ MainApp.bus().post(new EventDismissNotification(Notification.NSALARM)); } BroadcastSgvs.handleNewSgv(sgvs, MainApp.instance().getApplicationContext(), isDelta);