mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fixing some CalDAV event repetition exception related issues
This commit is contained in:
@@ -17,6 +17,8 @@ import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
|
|||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
|
import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
|
||||||
|
import org.joda.time.DateTimeZone
|
||||||
|
import org.joda.time.format.DateTimeFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
@@ -195,8 +197,8 @@ class CalDAVHelper(val context: Context) {
|
|||||||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||||
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
||||||
val description = cursor.getStringValue(CalendarContract.Events.DESCRIPTION) ?: ""
|
val description = cursor.getStringValue(CalendarContract.Events.DESCRIPTION) ?: ""
|
||||||
val startTS = cursor.getLongValue(CalendarContract.Events.DTSTART) / 1000L
|
var startTS = cursor.getLongValue(CalendarContract.Events.DTSTART)
|
||||||
var endTS = cursor.getLongValue(CalendarContract.Events.DTEND) / 1000L
|
var endTS = cursor.getLongValue(CalendarContract.Events.DTEND)
|
||||||
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
val allDay = cursor.getIntValue(CalendarContract.Events.ALL_DAY)
|
||||||
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
val rrule = cursor.getStringValue(CalendarContract.Events.RRULE) ?: ""
|
||||||
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
val location = cursor.getStringValue(CalendarContract.Events.EVENT_LOCATION) ?: ""
|
||||||
@@ -204,6 +206,14 @@ class CalDAVHelper(val context: Context) {
|
|||||||
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
val originalInstanceTime = cursor.getLongValue(CalendarContract.Events.ORIGINAL_INSTANCE_TIME)
|
||||||
val reminders = getCalDAVEventReminders(id)
|
val reminders = getCalDAVEventReminders(id)
|
||||||
|
|
||||||
|
if (startTS.toString().length == 13) {
|
||||||
|
startTS /= 1000L
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endTS.toString().length == 13) {
|
||||||
|
endTS /= 1000L
|
||||||
|
}
|
||||||
|
|
||||||
if (endTS == 0L) {
|
if (endTS == 0L) {
|
||||||
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
|
val duration = cursor.getStringValue(CalendarContract.Events.DURATION) ?: ""
|
||||||
endTS = startTS + Parser().parseDurationSeconds(duration)
|
endTS = startTS + Parser().parseDurationSeconds(duration)
|
||||||
@@ -237,6 +247,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
eventsHelper.insertEvent(parentEvent, false, false)
|
eventsHelper.insertEvent(parentEvent, false, false)
|
||||||
|
|
||||||
event.parentId = parentEvent.id!!
|
event.parentId = parentEvent.id!!
|
||||||
|
event.addRepetitionException(originalDayCode)
|
||||||
eventsHelper.insertEvent(event, false, false)
|
eventsHelper.insertEvent(event, false, false)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -247,7 +258,16 @@ class CalDAVHelper(val context: Context) {
|
|||||||
if (exdate.length > 8) {
|
if (exdate.length > 8) {
|
||||||
val dates = exdate.split(",")
|
val dates = exdate.split(",")
|
||||||
dates.forEach {
|
dates.forEach {
|
||||||
event.repetitionExceptions.add(it.substring(0, 8))
|
if (it.endsWith("Z")) {
|
||||||
|
// convert for example "20190216T230000Z" to "20190217000000" in Slovakia in a weird way
|
||||||
|
val formatter = DateTimeFormat.forPattern("yyyyMMdd'T'HHmmss'Z'")
|
||||||
|
val offset = DateTimeZone.getDefault().getOffset(System.currentTimeMillis())
|
||||||
|
val dt = formatter.parseDateTime(it).plusMillis(offset)
|
||||||
|
val daycode = Formatter.getDayCodeFromDateTime(dt)
|
||||||
|
event.repetitionExceptions.add(daycode)
|
||||||
|
} else {
|
||||||
|
event.repetitionExceptions.add(it.substring(0, 8))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user