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 { } else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true) dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
mEvent.parentId = mEvent.id mEvent.apply {
mEvent.id = 0 parentId = id
id = 0
repeatRule = 0
repeatInterval = 0
repeatLimit = 0
}
dbHelper.insert(mEvent, true) { dbHelper.insert(mEvent, true) {
toast(R.string.event_updated) toast(R.string.event_updated)
finish() finish()

View file

@ -249,9 +249,15 @@ class CalDAVHandler(val context: Context) {
if (importIdsMap.containsKey(event.importId)) { if (importIdsMap.containsKey(event.importId)) {
val existingEvent = importIdsMap[importId] val existingEvent = importIdsMap[importId]
val originalEventId = existingEvent!!.id val originalEventId = existingEvent!!.id
existingEvent.id = 0
existingEvent.color = 0 existingEvent.apply {
existingEvent.ignoreEventOccurrences = ArrayList() this.id = 0
color = 0
ignoreEventOccurrences = ArrayList()
lastUpdated = 0L
offset = ""
}
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) { if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
event.id = originalEventId event.id = originalEventId
context.dbHelper.update(event, false) 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 uri = CalendarContract.Events.CONTENT_URI
val values = fillEventRepeatExceptionValues(event, occurrenceTS) 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 { 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) { insert(childEvent, false) {
val childEventId = it
val exceptionValues = ContentValues().apply { val exceptionValues = ContentValues().apply {
put(COL_PARENT_EVENT_ID, parentEventId) put(COL_PARENT_EVENT_ID, parentEventId)
put(COL_OCCURRENCE_TIMESTAMP, occurrenceTS) put(COL_OCCURRENCE_TIMESTAMP, occurrenceTS)
put(COL_OCCURRENCE_DAYCODE, Formatter.getDayCodeFromTS(occurrenceTS)) put(COL_OCCURRENCE_DAYCODE, Formatter.getDayCodeFromTS(occurrenceTS))
put(COL_CHILD_EVENT_ID, it) put(COL_CHILD_EVENT_ID, childEventId)
} }
callback(exceptionValues) callback(exceptionValues)
@ -349,7 +350,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (addToCalDAV && context.config.caldavSync) { if (addToCalDAV && context.config.caldavSync) {
val parentEvent = getEventWithId(parentEventId) val parentEvent = getEventWithId(parentEventId)
if (parentEvent != null) { 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() }.start()