Check if event exists before creating a new one

This commit is contained in:
Naveen 2022-08-01 03:42:26 +05:30
parent ba6bd19a46
commit ceb815b9ea

View file

@ -13,11 +13,11 @@ import com.simplemobiletools.calendar.pro.extensions.*
import com.simplemobiletools.calendar.pro.models.* import com.simplemobiletools.calendar.pro.models.*
import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV import com.simplemobiletools.calendar.pro.objects.States.isUpdatingCalDAV
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormat
import java.util.* import java.util.*
import kotlin.collections.ArrayList
@SuppressLint("MissingPermission") @SuppressLint("MissingPermission")
class CalDAVHelper(val context: Context) { class CalDAVHelper(val context: Context) {
@ -238,6 +238,10 @@ class CalDAVHelper(val context: Context) {
val parentEvent = context.eventsDB.getEventWithImportId(parentImportId) val parentEvent = context.eventsDB.getEventWithImportId(parentImportId)
val originalDayCode = Formatter.getDayCodeFromTS(originalInstanceTime / 1000L) val originalDayCode = Formatter.getDayCodeFromTS(originalInstanceTime / 1000L)
if (parentEvent != null && !parentEvent.repetitionExceptions.contains(originalDayCode)) { if (parentEvent != null && !parentEvent.repetitionExceptions.contains(originalDayCode)) {
val storedEventId = context.eventsDB.getEventIdWithImportId(importId)
if (storedEventId != null) {
event.id = storedEventId
}
event.parentId = parentEvent.id!! event.parentId = parentEvent.id!!
parentEvent.addRepetitionException(originalDayCode) parentEvent.addRepetitionException(originalDayCode)
eventsHelper.insertEvent(parentEvent, false, false) eventsHelper.insertEvent(parentEvent, false, false)