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 // test warning level
int level = Levels.INFO; int level = Levels.INFO;
long now = System.currentTimeMillis(); 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; level = Levels.URGENT;
else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now) else if (deviceStatusOpenAPSData.clockSuggested != 0 && deviceStatusOpenAPSData.clockSuggested + sp.getInt(R.string.key_nsalarm_staledatavalue, 16) * 60 * 1000L < now)
level = Levels.WARN; level = Levels.WARN;

View file

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

View file

@ -22,8 +22,6 @@ class NotificationWithAction constructor(
@Inject lateinit var defaultValueHelper: DefaultValueHelper @Inject lateinit var defaultValueHelper: DefaultValueHelper
@Inject lateinit var nsClientPlugin: NSClientPlugin @Inject lateinit var nsClientPlugin: NSClientPlugin
private var nsAlarm: NSAlarm? = null
init { init {
injector.androidInjector().inject(this) injector.androidInjector().inject(this)
} }
@ -36,7 +34,6 @@ class NotificationWithAction constructor(
} }
constructor (injector: HasAndroidInjector, nsAlarm: NSAlarm) : this(injector) { constructor (injector: HasAndroidInjector, nsAlarm: NSAlarm) : this(injector) {
this.nsAlarm = nsAlarm
date = System.currentTimeMillis() date = System.currentTimeMillis()
when (nsAlarm.level()) { when (nsAlarm.level()) {
0 -> { 0 -> {
@ -50,14 +47,14 @@ class NotificationWithAction constructor(
id = NSALARM id = NSALARM
level = NORMAL level = NORMAL
text = nsAlarm.title() 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 -> { 2 -> {
id = NSURGENTALARM id = NSURGENTALARM
level = URGENT level = URGENT
text = nsAlarm.title() 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 buttonText = R.string.snooze

View file

@ -549,20 +549,12 @@
<string name="doprofileswitch">Do Profile Switch</string> <string name="doprofileswitch">Do Profile Switch</string>
<string name="careportal_pbage_label">Pump battery age</string> <string name="careportal_pbage_label">Pump battery age</string>
<string name="ns_alarmoptions">Alarm options</string> <string name="ns_alarmoptions">Alarm options</string>
<string name="key_nsalarm_urgent_high" translatable="false">nsalarm_urgent_high</string> <string name="key_ns_announcements" translatable="false">ns_announcements</string>
<string name="key_nsalarm_high" translatable="false">nsalarm_high</string> <string name="key_ns_alarms" translatable="false">ns_alarms</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_nsalarm_staledatavalue" translatable="false">nsalarm_staledatavalue</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="key_nsalarm_urgent_staledatavalue" translatable="false">nsalarm_urgent_staledatavalue</string>
<string name="nsalarm_urgenthigh">Urgent high</string> <string name="ns_alarms">Create notifications from NS alarms</string>
<string name="nsalarm_high">High</string> <string name="ns_announcements">Create notifications from NS announcements</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="nsalarm_staledatavalue_label">Stale data threshold [min]</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="nsalarm_urgent_staledatavalue_label">Urgent stale data threshold [min]</string>
<string name="openapsama_autosens_period">Interval for autosens [h]</string> <string name="openapsama_autosens_period">Interval for autosens [h]</string>

View file

@ -42,29 +42,12 @@
android:title="@string/ns_alarmoptions"> android:title="@string/ns_alarmoptions">
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:key="@string/key_ns_alarms"
android:key="@string/key_nsalarm_urgent_high" android:title="@string/ns_alarms" />
android:title="@string/nsalarm_urgenthigh" />
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:key="@string/key_ns_announcements"
android:key="@string/key_nsalarm_high" android:title="@string/ns_announcements" />
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" />
<info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference <info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
android:defaultValue="16" android:defaultValue="16"
@ -79,11 +62,6 @@
validate:minNumber="15" validate:minNumber="15"
validate:testType="numericRange" /> 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 <info.nightscout.androidaps.utils.textValidator.ValidatingEditTextPreference
android:defaultValue="31" android:defaultValue="31"
android:digits="0123456789" android:digits="0123456789"