more fixed related to repeatable event exceptions

This commit is contained in:
tibbi 2018-01-11 12:04:19 +01:00
parent 71a6316b29
commit 112a044be1
3 changed files with 25 additions and 9 deletions

View File

@ -596,8 +596,14 @@ class EventActivity : SimpleActivity() {
}
} else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
mEvent.parentId = mEvent.id
mEvent.id = 0
mEvent.apply {
parentId = id
id = 0
repeatRule = 0
repeatInterval = 0
repeatLimit = 0
}
dbHelper.insert(mEvent, true) {
toast(R.string.event_updated)
finish()

View File

@ -249,9 +249,15 @@ class CalDAVHandler(val context: Context) {
if (importIdsMap.containsKey(event.importId)) {
val existingEvent = importIdsMap[importId]
val originalEventId = existingEvent!!.id
existingEvent.id = 0
existingEvent.color = 0
existingEvent.ignoreEventOccurrences = ArrayList()
existingEvent.apply {
this.id = 0
color = 0
ignoreEventOccurrences = ArrayList()
lastUpdated = 0L
offset = ""
}
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
event.id = originalEventId
context.dbHelper.update(event, false)
@ -393,10 +399,11 @@ class CalDAVHandler(val context: Context) {
}
}
fun insertEventRepeatException(event: Event, occurrenceTS: Int) {
fun insertEventRepeatException(event: Event, occurrenceTS: Int): Long {
val uri = CalendarContract.Events.CONTENT_URI
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
context.contentResolver.insert(uri, values)
val newUri = context.contentResolver.insert(uri, values)
return java.lang.Long.parseLong(newUri.lastPathSegment)
}
private fun fillEventRepeatExceptionValues(event: Event, occurrenceTS: Int): ContentValues {

View File

@ -337,11 +337,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
}
insert(childEvent, false) {
val childEventId = it
val exceptionValues = ContentValues().apply {
put(COL_PARENT_EVENT_ID, parentEventId)
put(COL_OCCURRENCE_TIMESTAMP, occurrenceTS)
put(COL_OCCURRENCE_DAYCODE, Formatter.getDayCodeFromTS(occurrenceTS))
put(COL_CHILD_EVENT_ID, it)
put(COL_CHILD_EVENT_ID, childEventId)
}
callback(exceptionValues)
@ -349,7 +350,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (addToCalDAV && context.config.caldavSync) {
val parentEvent = getEventWithId(parentEventId)
if (parentEvent != null) {
CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
val newId = CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
val newImportId = "${parentEvent.source}-$newId"
updateEventImportIdAndSource(childEventId, newImportId, parentEvent.source)
}
}
}.start()