check the selected day repetition at planing next event notification
This commit is contained in:
parent
2c19f0bcb5
commit
f78b838231
|
@ -56,8 +56,13 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
||||||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||||
reminderSeconds.forEach {
|
reminderSeconds.forEach {
|
||||||
var startTS = event.startTS - it
|
var startTS = event.startTS - it
|
||||||
if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
|
if (event.repeatInterval == DAY) {
|
||||||
while (startTS < now || event.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(startTS + it).toInt())) {
|
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
|
startTS += event.repeatInterval
|
||||||
}
|
}
|
||||||
nextTS = Math.min(nextTS, startTS)
|
nextTS = Math.min(nextTS, startTS)
|
||||||
|
@ -77,6 +82,16 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
||||||
scheduleEventIn(nextTS, 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 {
|
private fun getNewTS(ts: Int, isMonthly: Boolean): Int {
|
||||||
var dateTime = Formatter.getDateTimeFromTS(ts)
|
var dateTime = Formatter.getDateTimeFromTS(ts)
|
||||||
while (dateTime.isBeforeNow) {
|
while (dateTime.isBeforeNow) {
|
||||||
|
|
Loading…
Reference in New Issue