Add prefs for local alerts.

This commit is contained in:
Johannes Mockenhaupt 2017-10-30 16:49:21 +01:00
parent bffd1239c0
commit 79d7ec5467
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
3 changed files with 25 additions and 5 deletions

View file

@ -21,12 +21,13 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.utils.SP;
public class KeepAliveReceiver extends BroadcastReceiver {
public static final long STATUS_UPDATE_FREQUENCY = 15 * 60 * 1000L;
@ -53,7 +54,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
private void checkBg() {
BgReading bgReading = DatabaseHelper.lastBg();
if (bgReading != null && bgReading.date + ALARM_FREQUENCY < System.currentTimeMillis()
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_missed_bg_readings_alert), false)
&& bgReading != null && bgReading.date + ALARM_FREQUENCY < System.currentTimeMillis()
&& nextMissedReadingsAlarm < System.currentTimeMillis()) {
Notification n = new Notification(Notification.BG_READINGS_MISSED, MainApp.sResources.getString(R.string.missed_bg_readings), Notification.URGENT);
n.soundId = R.raw.alarm;
@ -75,7 +77,8 @@ public class KeepAliveReceiver extends BroadcastReceiver {
boolean nextAlarmOccurrenceReached = nextPumpDisconnectedAlarm < System.currentTimeMillis();
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
if (isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached) {
if (SP.getBoolean(MainApp.sResources.getString(R.string.key_enable_pump_unreachable_alert), false)
&& isStatusOutdated && alarmTimeoutExpired && nextAlarmOccurrenceReached) {
Notification n = new Notification(Notification.PUMP_UNREACHABLE, MainApp.sResources.getString(R.string.pump_unreachable), Notification.URGENT);
n.soundId = R.raw.alarm;
nextPumpDisconnectedAlarm = System.currentTimeMillis() + ALARM_FREQUENCY;
@ -86,7 +89,7 @@ public class KeepAliveReceiver extends BroadcastReceiver {
public void run() {
pump.setNewBasalProfile(profile);
}
}, "pump-refresh");
}, "pump-update-basal-profile");
t.start();
} else if (isStatusOutdated && !pump.isBusy()) {
Thread t = new Thread(new Runnable() {

View file

@ -777,6 +777,11 @@
<string name="combo_action_idle">Idle</string>
<string name="pump_unreachable">Pump unreachable</string>
<string name="missed_bg_readings">Missed BG readings</string>
<string name="raise_urgent_alarms_as_android_notification">Use system notifications for alerts</string>
<string name="raise_urgent_alarms_as_android_notification" translatable="false">Use system notifications for alerts</string>
<string name="key_enable_pump_unreachable_alert" translatable="false">enable_pump_unreachable_alert</string>
<string name="key_enable_missed_bg_readings_alert" translatable="false">enable_missed_bg_readings</string>
<string name="localalertsettings_title">Local alerts</string>
<string name="enable_missed_bg_readings_alert">Alert if no BGs received in 30 min</string>
<string name="enable_pump_unreachable_alert">Alert if pump unreachable for 30 min</string>
</resources>

View file

@ -71,6 +71,18 @@
android:defaultValue="false"
android:key="short_tabtitles"
android:title="@string/short_tabtitles"/>
</PreferenceCategory>
<PreferenceCategory
android:key="others"
android:title="@string/localalertsettings_title">
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_enable_missed_bg_readings_alert"
android:title="@string/enable_missed_bg_readings_alert"/>
<SwitchPreference
android:defaultValue="false"
android:key="@string/key_enable_pump_unreachable_alert"
android:title="@string/enable_pump_unreachable_alert"/>
<SwitchPreference
android:defaultValue="false"
android:key="raise_urgent_alarms_as_android_notification"