[READ-ONLY] Mirror of https://github.com/probablykasper/notifier. Android app for scheduling notifications
android app flutter notifications
0

Configure Feed

Select the types of activity you want to include in your feed.

Minor changes to handling disabling of one-time notifications

Kasper (Jul 10, 2019, 11:27 PM +0200) 21fb03a2 da442458

+19 -20
+19 -20
lib/models/list.dart
··· 49 49 } 50 50 51 51 checkForDisabledNotifications() async { 52 + // Since one-time notifications get disabled after firing, we check constantly to see if any one-time notifications have fired. 52 53 print('[notifier] ListModel checkForDisabledNotifications()'); 53 54 Timer.periodic( 54 55 Duration(milliseconds: 500), 55 56 (timer) { 56 57 bool changedWereMade = false; 57 58 _notificationItems.forEach((id, notificationItem) { 58 - if (notificationItem['willDisable'] == true) { 59 - if (notificationItem['date'] < DateTime.now().millisecondsSinceEpoch) { 60 - notificationItem['status'] = 'disabled'; 61 - notificationItem['willDisable'] = false; 62 - changedWereMade = true; 63 - print( 64 - "[notifier] ListModel checkForDisabledNotifications(): Disabling $id ('${notificationItem['title']}') due to it having fired ", 65 - ); 66 - } 59 + if (notificationItem['willDisable'] == true && 60 + notificationItem['date'] < DateTime.now().millisecondsSinceEpoch) { 61 + notificationItem['status'] = 'disabled'; 62 + notificationItem['willDisable'] = false; 63 + changedWereMade = true; 64 + print( 65 + "[notifier] ListModel checkForDisabledNotifications(): Disabling $id ('${notificationItem['title']}') due to it having fired ", 66 + ); 67 67 } 68 68 }); 69 69 if (changedWereMade) { ··· 215 215 '[notifier] ListModel setNotifications(): ${pendingNotificationItemIds.length} items are currently scheduled: $pendingNotificationItemIds'); 216 216 _notificationItems.forEach((id, notificationItem) { 217 217 int next48h = DateTime.now().add(Duration(hours: 48)).millisecondsSinceEpoch; 218 + 219 + // handle willDisable 220 + if (notificationItem['repeat'] == 'never' && notificationItem['willDisable'] == true) { 221 + // if the notification date is in the past, disable the notification 222 + if (notificationItem['date'] < DateTime.now().millisecondsSinceEpoch) { 223 + notificationItem['status'] = 'disabled'; 224 + notificationItem['willDisable'] = false; 225 + } 226 + } 227 + 218 228 if (!pendingNotificationItemIds.contains(notificationItem['id']) && 219 229 notificationItem['date'] < next48h && 220 230 notificationItem['status'] == 'enabled') { 221 - // if the notification willBeDisabled, don't schedule a new notification 222 - if (notificationItem['repeat'] == 'never' && notificationItem['willDisable'] == true) { 223 - // if the notification date is in the past, disable the notification 224 - if (notificationItem['date'] < DateTime.now().millisecondsSinceEpoch) { 225 - notificationItem['status'] = 'disabled'; 226 - notificationItem['willDisable'] = false; 227 - if (appIsOpen == true) rebuild(); 228 - } 229 - return; 230 - } 231 - 232 231 // date to schedule notification to now 233 232 DateTime date = DateTime.fromMillisecondsSinceEpoch(notificationItem['date']); 234 233 // date to schedule notification to next time