Properly handle deleting `Delete the selected occurrence only`
Closes https://github.com/SimpleMobileTools/Simple-Calendar/issues/735 This only happened with all-day recurring events because: - `ORIGINAL_INSTANCE_TIME` was not set to a UTC occurrence timestamp and and all-day events always deal in UTC. - The `DTSTART`, `DTEND` were set to invalid values because of a missing conversion to milliseconds of start, end timestamps
This commit is contained in:
parent
80540f1afe
commit
f475879408
|
@ -480,25 +480,39 @@ class CalDAVHelper(val context: Context) {
|
||||||
refreshCalDAVCalendar(event)
|
refreshCalDAVCalendar(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertEventRepeatException(event: Event, occurrenceTS: Long) {
|
fun insertEventRepeatException(parentEvent: Event, occurrenceTS: Long) {
|
||||||
val uri = Events.CONTENT_URI
|
val uri = Events.CONTENT_URI
|
||||||
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
|
val values = fillEventRepeatExceptionValues(parentEvent, occurrenceTS)
|
||||||
try {
|
try {
|
||||||
context.contentResolver.insert(uri, values)
|
context.contentResolver.insert(uri, values)
|
||||||
refreshCalDAVCalendar(event)
|
refreshCalDAVCalendar(parentEvent)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
context.showErrorToast(e)
|
context.showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillEventRepeatExceptionValues(event: Event, occurrenceTS: Long): ContentValues {
|
private fun fillEventRepeatExceptionValues(parentEvent: Event, occurrenceTS: Long): ContentValues {
|
||||||
|
val isAllDay = parentEvent.getIsAllDay()
|
||||||
|
val startTSMillis = if (isAllDay) {
|
||||||
|
// original instance time must be in UTC since the parent event is an all-day event thus everything is handled in UTC
|
||||||
|
Formatter.getShiftedUtcTS(occurrenceTS) * 1000L
|
||||||
|
} else {
|
||||||
|
occurrenceTS * 1000L
|
||||||
|
}
|
||||||
|
val durationMillis = (parentEvent.endTS - parentEvent.startTS) * 1000L
|
||||||
return ContentValues().apply {
|
return ContentValues().apply {
|
||||||
put(Events.CALENDAR_ID, event.getCalDAVCalendarId())
|
put(Events.CALENDAR_ID, parentEvent.getCalDAVCalendarId())
|
||||||
put(Events.DTSTART, occurrenceTS)
|
put(Events.DTSTART, startTSMillis)
|
||||||
put(Events.DTEND, occurrenceTS + (event.endTS - event.startTS))
|
put(Events.DTEND, startTSMillis + durationMillis)
|
||||||
put(Events.ORIGINAL_ID, event.getCalDAVEventId())
|
put(Events.EVENT_TIMEZONE, parentEvent.getTimeZoneString())
|
||||||
put(Events.EVENT_TIMEZONE, TimeZone.getDefault().id.toString())
|
put(Events.ORIGINAL_ID, parentEvent.getCalDAVEventId())
|
||||||
put(Events.ORIGINAL_INSTANCE_TIME, occurrenceTS * 1000L)
|
put(Events.ORIGINAL_INSTANCE_TIME, startTSMillis)
|
||||||
|
put(Events.STATUS, Events.STATUS_CANCELED)
|
||||||
|
if (isAllDay) {
|
||||||
|
put(Events.ORIGINAL_ALL_DAY, 1)
|
||||||
|
} else {
|
||||||
|
put(Events.ORIGINAL_ALL_DAY, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue