Merge branch 'dev' into medtronic_andy

This commit is contained in:
Andy Rozman 2019-01-04 22:12:14 +01:00
commit 8698e14076

View file

@ -1,9 +1,5 @@
package info.nightscout.androidaps.plugins.Overview.notifications;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
@ -20,6 +16,7 @@ import info.nightscout.utils.SP;
*/
public class Notification {
public static final int URGENT = 0;
public static final int NORMAL = 1;
public static final int LOW = 2;
@ -80,9 +77,12 @@ 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;
this.date = date;
@ -91,6 +91,7 @@ public class Notification {
this.validTo = validTo;
}
public Notification(int id, String text, int level, int validMinutes) {
this.id = id;
this.date = new Date();
@ -99,6 +100,7 @@ public class Notification {
this.validTo = new Date(System.currentTimeMillis() + validMinutes * 60 * 1000L);
}
public Notification(int id, String text, int level) {
this.id = id;
this.date = new Date();
@ -107,27 +109,32 @@ public class Notification {
this.validTo = new Date(0);
}
public Notification(int id) {
this.id = id;
this.date = new Date();
this.validTo = new Date(0);
}
public Notification text(String text) {
this.text = text;
return this;
}
public Notification level(int level) {
this.level = level;
return this;
}
public Notification sound(int soundId) {
this.soundId = soundId;
return this;
}
public Notification(NSAlarm nsAlarm) {
this.date = new Date();
this.validTo = new Date(0);
@ -143,32 +150,41 @@ public class Notification {
this.id = NSALARM;
this.level = NORMAL;
this.text = nsAlarm.getTile();
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false))
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh()
&& SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData()
&& SP.getBoolean(R.string.key_nsalarm_staledata, false))
this.soundId = R.raw.alarm;
break;
case 2:
this.id = NSURGENTALARM;
this.level = URGENT;
this.text = nsAlarm.getTile();
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false))
if (isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh()
&& SP.getBoolean(R.string.key_nsalarm_urgent_high, false))
this.soundId = R.raw.urgentalarm;
break;
}
}
public boolean isEnabled() {
if (nsAlarm == null)
return true;
if (level == ANNOUNCEMENT)
return true;
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_staledata, false)) {
if (level == NORMAL && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_low, false) || isAlarmForHigh()
&& SP.getBoolean(R.string.key_nsalarm_high, false) || isAlarmForStaleData()
&& SP.getBoolean(R.string.key_nsalarm_staledata, false)) {
return true;
}
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false) || isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false) || isAlarmForStaleData() && SP.getBoolean(R.string.key_nsalarm_urgent_staledata, false))
if (level == URGENT && isAlarmForLow() && SP.getBoolean(R.string.key_nsalarm_urgent_low, false)
|| isAlarmForHigh() && SP.getBoolean(R.string.key_nsalarm_urgent_high, false) || isAlarmForStaleData()
&& SP.getBoolean(R.string.key_nsalarm_urgent_staledata, false))
return true;
return false;
}
boolean isAlarmForLow() {
BgReading bgReading = MainApp.getDbHelper().lastBg();
if (bgReading == null)
@ -181,6 +197,7 @@ public class Notification {
return false;
}
boolean isAlarmForHigh() {
BgReading bgReading = MainApp.getDbHelper().lastBg();
if (bgReading == null)
@ -193,11 +210,13 @@ public class Notification {
return false;
}
public static boolean isAlarmForStaleData(){
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");
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;
}
}
@ -205,24 +224,26 @@ public class Notification {
if (bgReading == null)
return false;
long bgReadingAgo = System.currentTimeMillis() - bgReading.date;
int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60));
int bgReadingAgoMin = (int)(bgReadingAgo / (1000 * 60));
// Added for testing
// bgReadingAgoMin = 20;
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
//log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
//log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L);
// 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)){
// 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
SP.putLong("snoozedTo", (long) (bgReading.date + (threshold * 1000 * 60L)));
//log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
// snoozing for threshold
SP.putLong("snoozedTo", (long)(bgReading.date + (threshold * 1000 * 60L)));
// log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
return false;
}
}