[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.

Revamped & Fixed infinite loop in getNextDate for weekly notifications

+28 -21
+28 -21
lib/models/list.dart
··· 65 65 // Configure BackgroundFetch. 66 66 BackgroundFetch.configure( 67 67 BackgroundFetchConfig( 68 - minimumFetchInterval: 60*8, 68 + minimumFetchInterval: 60 * 8, 69 69 stopOnTerminate: false, 70 70 enableHeadless: true, 71 71 startOnBoot: true, ··· 91 91 if (repeat == 'daily') { 92 92 newDay += repeatEvery; 93 93 } else if (repeat == 'weekly') { 94 - int firstCheckedWeekday = weekdays.indexOf(true); 95 - // i = x days in the future. Starts with tomorrow: 96 - int i = 1; 97 - while (i != 100) { 98 - if (date.weekday + i == 7) { 99 - // ^ done looping through this week 100 - // set to monday next week: 101 - newDay += i; 102 - // skip weeks: 103 - newDay += 7 * repeatEvery - 1; 104 - // set to next checked weekday: 105 - newDay += firstCheckedWeekday; 106 - } else if (weekdays[date.weekday - 1] == true) { 107 - // ^ weekday is checked 108 - newDay += i; 109 - i = 100; 110 - } else { 111 - // ^ weekday is not checked 112 - i++; 113 - } 94 + print('111'); 95 + 96 + // get the zero-based weekday of date 97 + int dateWeekday = date.weekday - 1; 98 + // get the index of the first checked weekday, starting from tomorrow 99 + int nextCheckedWeekdayInThisWeek = weekdays.indexOf(true, dateWeekday + 1); 100 + 101 + // if there is an upcoming checked weekday this week 102 + if (nextCheckedWeekdayInThisWeek >= 0) { 103 + // set newDay to the difference between the next checked weekday and today 104 + newDay += nextCheckedWeekdayInThisWeek - dateWeekday; 105 + } 106 + 107 + // if there is no upcoming checked weekday this week 108 + if (nextCheckedWeekdayInThisWeek == -1) { 109 + // find how many days left till monday next week. If it's currently monday (0), that's 7 days 110 + int daysTillMonday = (7 - dateWeekday); 111 + // set newDay to monday next week 112 + newDay += daysTillMonday; 113 + 114 + // skip weeks. If it's repeated every 2 week, add 7 days to newDay 115 + newDay += (7 * repeatEvery) - 1; 116 + 117 + // set newDay to the next checked weekday 118 + int firstCheckedWeekday = weekdays.indexOf(true); 119 + newDay += firstCheckedWeekday; 114 120 } 121 + 115 122 } else if (repeat == 'monthly') { 116 123 newMonth += repeatEvery; 117 124 } else if (repeat == 'yearly') {