check the selected day repetition at planing next event notification
This commit is contained in:
parent
2c19f0bcb5
commit
f78b838231
1 changed files with 17 additions and 2 deletions
|
@ -56,8 +56,13 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
|||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||
reminderSeconds.forEach {
|
||||
var startTS = event.startTS - it
|
||||
if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
|
||||
while (startTS < now || event.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(startTS + it).toInt())) {
|
||||
if (event.repeatInterval == DAY) {
|
||||
while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) {
|
||||
startTS += event.repeatInterval
|
||||
}
|
||||
nextTS = Math.min(nextTS, startTS)
|
||||
} else if (event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
|
||||
while (startTS < now || isOccurrenceIgnored(event, startTS, it)) {
|
||||
startTS += event.repeatInterval
|
||||
}
|
||||
nextTS = Math.min(nextTS, startTS)
|
||||
|
@ -77,6 +82,16 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
|||
scheduleEventIn(nextTS, event)
|
||||
}
|
||||
|
||||
private fun isOccurrenceIgnored(event: Event, startTS: Int, reminderSeconds: Int): Boolean {
|
||||
return event.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(startTS + reminderSeconds).toInt())
|
||||
}
|
||||
|
||||
private fun isWrongDay(event: Event, startTS: Int, reminderSeconds: Int): Boolean {
|
||||
val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
return event.repeatRule and power == 0
|
||||
}
|
||||
|
||||
private fun getNewTS(ts: Int, isMonthly: Boolean): Int {
|
||||
var dateTime = Formatter.getDateTimeFromTS(ts)
|
||||
while (dateTime.isBeforeNow) {
|
||||
|
|
Loading…
Reference in a new issue