From 2b06e9e63ece216cfe6c09511e1ed26ff2197280 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 6 Nov 2017 17:12:33 +0100 Subject: [PATCH] Notification bugfixes --- app/src/main/AndroidManifest.xml | 4 +++ .../DismissNotificationService.java | 4 +++ .../receivers/KeepAliveReceiver.java | 26 +++++++++++++------ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index be3c0e5d80..d57639a3fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -140,6 +140,10 @@ android:name=".Services.AlarmSoundService" android:enabled="true" android:exported="true" /> + + pump.getPumpDescription().basalStep; boolean alarmTimeoutExpired = lastConnection.getTime() + pumpUnreachableThreshold() < System.currentTimeMillis(); - boolean nextAlarmOccurrenceReached = nextPumpDisconnectedAlarm < System.currentTimeMillis(); + boolean nextAlarmOccurrenceReached = SP.getLong("nextPumpDisconnectedAlarm", 0l) < System.currentTimeMillis(); - SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext()); 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() + pumpUnreachableThreshold(); + SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold()); + SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold()); MainApp.bus().post(new EventNewNotification(n)); } else if (SP.getBoolean("syncprofiletopump", false) && !pump.isThisProfileSet(profile)) { Thread t = new Thread(new Runnable() { @@ -137,4 +135,16 @@ public class KeepAliveReceiver extends BroadcastReceiver { AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(sender); } + + static void initAlarmTimes() { + //shortens alarm times in case of setting changes or future data + long nextMissedReadingsAlarm = SP.getLong("nextMissedReadingsAlarm", 0l); + nextMissedReadingsAlarm = Math.min(System.currentTimeMillis() + missedReadingsThreshold(), nextMissedReadingsAlarm); + SP.putLong("nextMissedReadingsAlarm", nextMissedReadingsAlarm); + + long nextPumpDisconnectedAlarm = SP.getLong("nextPumpDisconnectedAlarm", 0l); + nextPumpDisconnectedAlarm = Math.min(System.currentTimeMillis() + missedReadingsThreshold(), nextPumpDisconnectedAlarm); + SP.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm); + } + } \ No newline at end of file