Merge branch 'dev' into medtronic_andy
This commit is contained in:
commit
8698e14076
|
@ -1,9 +1,5 @@
|
||||||
|
|
||||||
package info.nightscout.androidaps.plugins.Overview.notifications;
|
package info.nightscout.androidaps.plugins.Overview.notifications;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
@ -20,6 +16,7 @@ import info.nightscout.utils.SP;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Notification {
|
public class Notification {
|
||||||
|
|
||||||
public static final int URGENT = 0;
|
public static final int URGENT = 0;
|
||||||
public static final int NORMAL = 1;
|
public static final int NORMAL = 1;
|
||||||
public static final int LOW = 2;
|
public static final int LOW = 2;
|
||||||
|
@ -80,9 +77,12 @@ public class Notification {
|
||||||
|
|
||||||
public NSAlarm nsAlarm = null;
|
public NSAlarm nsAlarm = null;
|
||||||
public Integer soundId = null;
|
public Integer soundId = null;
|
||||||
|
|
||||||
|
|
||||||
public Notification() {
|
public Notification() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification(int id, Date date, String text, int level, Date validTo) {
|
public Notification(int id, Date date, String text, int level, Date validTo) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
@ -91,6 +91,7 @@ public class Notification {
|
||||||
this.validTo = validTo;
|
this.validTo = validTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification(int id, String text, int level, int validMinutes) {
|
public Notification(int id, String text, int level, int validMinutes) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
|
@ -99,6 +100,7 @@ public class Notification {
|
||||||
this.validTo = new Date(System.currentTimeMillis() + validMinutes * 60 * 1000L);
|
this.validTo = new Date(System.currentTimeMillis() + validMinutes * 60 * 1000L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification(int id, String text, int level) {
|
public Notification(int id, String text, int level) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
|
@ -107,27 +109,32 @@ public class Notification {
|
||||||
this.validTo = new Date(0);
|
this.validTo = new Date(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification(int id) {
|
public Notification(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.validTo = new Date(0);
|
this.validTo = new Date(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification text(String text) {
|
public Notification text(String text) {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification level(int level) {
|
public Notification level(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification sound(int soundId) {
|
public Notification sound(int soundId) {
|
||||||
this.soundId = soundId;
|
this.soundId = soundId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Notification(NSAlarm nsAlarm) {
|
public Notification(NSAlarm nsAlarm) {
|
||||||
this.date = new Date();
|
this.date = new Date();
|
||||||
this.validTo = new Date(0);
|
this.validTo = new Date(0);
|
||||||
|
@ -143,32 +150,41 @@ public class Notification {
|
||||||
this.id = NSALARM;
|
this.id = NSALARM;
|
||||||
this.level = NORMAL;
|
this.level = NORMAL;
|
||||||
this.text = nsAlarm.getTile();
|
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;
|
this.soundId = R.raw.alarm;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
this.id = NSURGENTALARM;
|
this.id = NSURGENTALARM;
|
||||||
this.level = URGENT;
|
this.level = URGENT;
|
||||||
this.text = nsAlarm.getTile();
|
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;
|
this.soundId = R.raw.urgentalarm;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
if (nsAlarm == null)
|
if (nsAlarm == null)
|
||||||
return true;
|
return true;
|
||||||
if (level == ANNOUNCEMENT)
|
if (level == ANNOUNCEMENT)
|
||||||
return true;
|
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;
|
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 true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean isAlarmForLow() {
|
boolean isAlarmForLow() {
|
||||||
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
||||||
if (bgReading == null)
|
if (bgReading == null)
|
||||||
|
@ -181,6 +197,7 @@ public class Notification {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean isAlarmForHigh() {
|
boolean isAlarmForHigh() {
|
||||||
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
BgReading bgReading = MainApp.getDbHelper().lastBg();
|
||||||
if (bgReading == null)
|
if (bgReading == null)
|
||||||
|
@ -193,11 +210,13 @@ public class Notification {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAlarmForStaleData(){
|
|
||||||
|
public static boolean isAlarmForStaleData() {
|
||||||
long snoozedTo = SP.getLong("snoozedTo", 0L);
|
long snoozedTo = SP.getLong("snoozedTo", 0L);
|
||||||
if(snoozedTo != 0L){
|
if (snoozedTo != 0L) {
|
||||||
if(System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
if (System.currentTimeMillis() < SP.getLong("snoozedTo", 0L)) {
|
||||||
//log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo", 0L)-System.currentTimeMillis())/1000+" seconds");
|
// log.debug("Alarm is snoozed for next "+(SP.getLong("snoozedTo",
|
||||||
|
// 0L)-System.currentTimeMillis())/1000+" seconds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,24 +224,26 @@ public class Notification {
|
||||||
if (bgReading == null)
|
if (bgReading == null)
|
||||||
return false;
|
return false;
|
||||||
long bgReadingAgo = System.currentTimeMillis() - bgReading.date;
|
long bgReadingAgo = System.currentTimeMillis() - bgReading.date;
|
||||||
int bgReadingAgoMin = (int) (bgReadingAgo / (1000 * 60));
|
int bgReadingAgoMin = (int)(bgReadingAgo / (1000 * 60));
|
||||||
// Added for testing
|
// Added for testing
|
||||||
// bgReadingAgoMin = 20;
|
// bgReadingAgoMin = 20;
|
||||||
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
|
boolean openAPSEnabledAlerts = NSSettingsStatus.getInstance().openAPSEnabledAlerts();
|
||||||
//log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
|
// log.debug("bgReadingAgoMin value is:"+bgReadingAgoMin);
|
||||||
//log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L);
|
// log.debug("Stale alarm snoozed to: "+(System.currentTimeMillis() - snoozedTo)/60000L);
|
||||||
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
Double threshold = NSSettingsStatus.getInstance().getThreshold("alarmTimeagoWarnMins");
|
||||||
//log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
// log.debug("OpenAPS Alerts enabled: "+openAPSEnabledAlerts);
|
||||||
// if no thresshold from Ns get it loccally
|
// if no thresshold from Ns get it loccally
|
||||||
if(threshold == null) threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue,15D);
|
if (threshold == null)
|
||||||
// No threshold of OpenAPS Alarm so using the one for BG
|
threshold = SP.getDouble(R.string.key_nsalarm_staledatavalue, 15D);
|
||||||
// Added OpenAPSEnabledAlerts to alarm check
|
// No threshold of OpenAPS Alarm so using the one for BG
|
||||||
if((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))||(bgReadingAgoMin > threshold && openAPSEnabledAlerts)){
|
// Added OpenAPSEnabledAlerts to alarm check
|
||||||
|
if ((bgReadingAgoMin > threshold && SP.getBoolean(R.string.key_nsalarm_staledata, false))
|
||||||
|
|| (bgReadingAgoMin > threshold && openAPSEnabledAlerts)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//snoozing for threshold
|
// snoozing for threshold
|
||||||
SP.putLong("snoozedTo", (long) (bgReading.date + (threshold * 1000 * 60L)));
|
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");
|
// log.debug("New bg data is available Alarm is snoozed for next "+threshold*1000*60+" seconds");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue