Properly handle repeat limits

Fixes these issues:
 - When choosing `Update/Delete this and all future occurrences`, the selected occurrence is never deleted/updated.
 - When choosing `Update this and all future occurrences`, the event is duplicated on the date of the selection
This commit is contained in:
Naveen 2023-06-24 15:35:23 +05:30
parent d0f88c1099
commit 46e17aa697
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
2 changed files with 19 additions and 4 deletions

View File

@ -225,9 +225,17 @@ class EventsHelper(val context: Context) {
deleteEvents(eventIds, true)
}
fun addEventRepeatLimit(eventId: Long, limitTS: Long) {
val time = Formatter.getDateTimeFromTS(limitTS)
eventsDB.updateEventRepetitionLimit(limitTS - time.hourOfDay, eventId)
fun addEventRepeatLimit(eventId: Long, occurrenceTS: Long) {
val event = eventsDB.getEventWithId(eventId) ?: return
val previousOccurrenceTS = occurrenceTS - event.repeatInterval // always update repeat limit of the occurrence preceding the one being edited
val repeatLimitDateTime = Formatter.getDateTimeFromTS(previousOccurrenceTS).withTimeAtStartOfDay()
val repeatLimitTS = if (event.getIsAllDay()) {
repeatLimitDateTime.seconds()
} else {
repeatLimitDateTime.withTime(23, 59, 59, 0).seconds()
}
eventsDB.updateEventRepetitionLimit(repeatLimitTS, eventId)
context.cancelNotification(eventId)
context.cancelPendingIntent(eventId)
if (config.caldavSync) {

View File

@ -145,7 +145,14 @@ class Parser {
private fun getRepeatLimitString(event: Event) = when {
event.repeatLimit == 0L -> ""
event.repeatLimit < 0 -> ";$COUNT=${-event.repeatLimit}"
else -> ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}"
else -> if (event.getIsAllDay()) {
";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}"
} else {
val dateTime = Formatter.getUTCDateTimeFromTS(event.repeatLimit)
val dayCode = dateTime.toString(Formatter.DAYCODE_PATTERN)
val timeCode = dateTime.toString(Formatter.TIME_PATTERN)
";$UNTIL=${dayCode}T${timeCode}Z"
}
}
private fun getByMonth(event: Event) = when {