properly display weekly events that occur multiple times a week
This commit is contained in:
parent
0ce8380c12
commit
db6c7e5738
|
@ -56,14 +56,9 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
|||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||
reminderSeconds.forEach {
|
||||
var startTS = event.startTS - it
|
||||
if (event.repeatInterval == DAY) {
|
||||
while (startTS < now || isOccurrenceIgnored(event, startTS, it)) {
|
||||
startTS += event.repeatInterval
|
||||
}
|
||||
nextTS = Math.min(nextTS, startTS)
|
||||
} else if (event.repeatInterval == WEEK) {
|
||||
if (event.repeatInterval == DAY || event.repeatInterval == WEEK) {
|
||||
while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) {
|
||||
startTS += event.repeatInterval
|
||||
startTS += DAY
|
||||
}
|
||||
nextTS = Math.min(nextTS, startTS)
|
||||
} else if (event.repeatInterval == MONTH) {
|
||||
|
@ -87,6 +82,9 @@ private fun isOccurrenceIgnored(event: Event, startTS: Int, reminderSeconds: Int
|
|||
}
|
||||
|
||||
private fun isWrongDay(event: Event, startTS: Int, reminderSeconds: Int): Boolean {
|
||||
if (event.repeatInterval == DAY)
|
||||
return false
|
||||
|
||||
val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
return event.repeatRule and power == 0
|
||||
|
|
|
@ -384,7 +384,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
for (event in events) {
|
||||
while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
|
||||
if (event.startTS >= fromTS) {
|
||||
if (event.repeatInterval == DAY) {
|
||||
if (event.repeatInterval == WEEK) {
|
||||
val dateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
if (event.repeatRule and power != 0) {
|
||||
|
|
|
@ -20,8 +20,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
|||
val currStart = Formatter.getDateTimeFromTS(startTS)
|
||||
val newStart: DateTime
|
||||
newStart = when (repeatInterval) {
|
||||
DAY -> currStart.plusDays(1)
|
||||
WEEK -> currStart.plusWeeks(1)
|
||||
DAY, WEEK -> currStart.plusDays(1) // step through weekly repetition by days too, as it can trigger multiple times a week
|
||||
else -> {
|
||||
if (repeatInterval % YEAR == 0) {
|
||||
currStart.plusYears(repeatInterval / YEAR)
|
||||
|
|
Loading…
Reference in New Issue