nsalarm notifications fix

This commit is contained in:
Milos Kozak 2020-05-23 21:54:01 +02:00
parent 8e49717794
commit 8ae817cdda
5 changed files with 39 additions and 63 deletions

View file

@ -331,7 +331,7 @@ public class NSDeviceStatus {
// test warning level
int level = Levels.INFO;
long now = System.currentTimeMillis();
if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_urgent_staledatavalue, 16) * 60 * 1000L < now)
if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_urgent_staledatavalue, 31) * 60 * 1000L < now)
level = Levels.URGENT;
else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now)
level = Levels.WARN;

View file

@ -842,33 +842,42 @@ public class NSClientService extends DaggerService {
}
private void handleAnnouncement(JSONObject announcement) {
NSAlarm nsAlarm = new NSAlarm(announcement);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, announcement.toString());
boolean defaultVal = config.getNSCLIENT();
if (sp.getBoolean(R.string.key_ns_announcements, defaultVal)) {
NSAlarm nsAlarm = new NSAlarm(announcement);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
rxBus.send(new EventNSClientNewLog("ANNOUNCEMENT", JsonHelper.safeGetString(announcement, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, announcement.toString());
}
}
private void handleAlarm(JSONObject alarm) {
long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L);
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
NSAlarm nsAlarm = new NSAlarm(alarm);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
boolean defaultVal = config.getNSCLIENT();
if (sp.getBoolean(R.string.key_ns_alarms, defaultVal)) {
long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L);
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
NSAlarm nsAlarm = new NSAlarm(alarm);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
}
rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, alarm.toString());
}
rxBus.send(new EventNSClientNewLog("ALARM", JsonHelper.safeGetString(alarm, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, alarm.toString());
}
private void handleUrgentAlarm(JSONObject alarm) {
long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L);
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
NSAlarm nsAlarm = new NSAlarm(alarm);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
boolean defaultVal = config.getNSCLIENT();
if (sp.getBoolean(R.string.key_ns_alarms, defaultVal)) {
long snoozedTo = sp.getLong(R.string.key_snoozedTo, 0L);
if (snoozedTo == 0L || System.currentTimeMillis() > snoozedTo) {
NSAlarm nsAlarm = new NSAlarm(alarm);
Notification notification = new NotificationWithAction(injector, nsAlarm);
rxBus.send(new EventNewNotification(notification));
}
rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, alarm.toString());
}
rxBus.send(new EventNSClientNewLog("URGENTALARM", JsonHelper.safeGetString(alarm, "message", "received")));
aapsLogger.debug(LTag.NSCLIENT, alarm.toString());
}
public void handleNewCal(JSONArray cals, boolean isDelta) {

View file

@ -22,8 +22,6 @@ class NotificationWithAction constructor(
@Inject lateinit var defaultValueHelper: DefaultValueHelper
@Inject lateinit var nsClientPlugin: NSClientPlugin
private var nsAlarm: NSAlarm? = null
init {
injector.androidInjector().inject(this)
}
@ -36,7 +34,6 @@ class NotificationWithAction constructor(
}
constructor (injector: HasAndroidInjector, nsAlarm: NSAlarm) : this(injector) {
this.nsAlarm = nsAlarm
date = System.currentTimeMillis()
when (nsAlarm.level()) {
0 -> {
@ -50,14 +47,14 @@ class NotificationWithAction constructor(
id = NSALARM
level = NORMAL
text = nsAlarm.title()
if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.alarm
soundId = R.raw.alarm
}
2 -> {
id = NSURGENTALARM
level = URGENT
text = nsAlarm.title()
if (nsAlarm.low() && sp.getBoolean(R.string.key_nsalarm_urgent_low, false) || nsAlarm.high() && sp.getBoolean(R.string.key_nsalarm_urgent_high, false) || nsAlarm.timeago() && sp.getBoolean(R.string.key_nsalarm_staledata, false)) soundId = R.raw.urgentalarm
soundId = R.raw.urgentalarm
}
}
buttonText = R.string.snooze

View file

@ -549,20 +549,12 @@
<string name="doprofileswitch">Do Profile Switch</string>
<string name="careportal_pbage_label">Pump battery age</string>
<string name="ns_alarmoptions">Alarm options</string>
<string name="key_nsalarm_urgent_high" translatable="false">nsalarm_urgent_high</string>
<string name="key_nsalarm_high" translatable="false">nsalarm_high</string>
<string name="key_nsalarm_low" translatable="false">nsalarm_low</string>
<string name="key_nsalarm_urgent_low" translatable="false">nsalarm_urgent_low</string>
<string name="key_nsalarm_staledata" translatable="false">nsalarm_staledata</string>
<string name="key_nsalarm_urgent_staledata" translatable="false">nsalarm_urgent_staledata</string>
<string name="key_ns_announcements" translatable="false">ns_announcements</string>
<string name="key_ns_alarms" translatable="false">ns_alarms</string>
<string name="key_nsalarm_staledatavalue" translatable="false">nsalarm_staledatavalue</string>
<string name="key_nsalarm_urgent_staledatavalue" translatable="false">nsalarm_urgent_staledatavalue</string>
<string name="nsalarm_urgenthigh">Urgent high</string>
<string name="nsalarm_high">High</string>
<string name="nsalarm_low">Low</string>
<string name="nsalarm_urgentlow">Urgent low</string>
<string name="nsalarm_staledata">Stale data</string>
<string name="nsalarm_urgentstaledata">Urgent stale data</string>
<string name="ns_alarms">Create notifications from NS alarms</string>
<string name="ns_announcements">Create notifications from NS announcements</string>
<string name="nsalarm_staledatavalue_label">Stale data threshold [min]</string>
<string name="nsalarm_urgent_staledatavalue_label">Urgent stale data threshold [min]</string>
<string name="openapsama_autosens_period">Interval for autosens [h]</string>

View file

@ -42,29 +42,12 @@
android:title="@string/ns_alarmoptions">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_urgent_high"
android:title="@string/nsalarm_urgenthigh" />
android:key="@string/key_ns_alarms"
android:title="@string/ns_alarms" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_high"
android:title="@string/nsalarm_high" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_low"
android:title="@string/nsalarm_low" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_urgent_low"
android:title="@string/nsalarm_urgentlow" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_staledata"
android:title="@string/nsalarm_staledata" />
android:key="@string/key_ns_announcements"
android:title="@string/ns_announcements" />
<info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
android:defaultValue="16"
@ -79,11 +62,6 @@
validate:minNumber="15"
validate:testType="numericRange" />
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_nsalarm_urgent_staledata"
android:title="@string/nsalarm_urgentstaledata" />
<info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
android:defaultValue="31"
android:digits="0123456789"