properly handle moving an event from 1 caldav calendar to another one

This commit is contained in:
tibbi 2017-08-21 22:16:33 +02:00
parent 7549beb814
commit b6247d55ab
3 changed files with 11 additions and 4 deletions

View File

@ -489,6 +489,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
}
val wasRepeatable = mEvent.repeatInterval > 0
val oldSource = mEvent.source
val newImportId = if (mEvent.id != 0) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendar == 0) mEventTypeId else dbHelper.getEventTypeIdWithCalDAVCalendarId(config.lastUsedCaldavCalendar)
@ -516,6 +517,12 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
source = newSource
}
// recreate the event if it was moved in a different CalDAV calendar
if (mEvent.id != 0 && oldSource != newSource) {
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
mEvent.id = 0
}
storeEvent(wasRepeatable)
}

View File

@ -199,7 +199,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
context.updateWidgets()
context.scheduleReminder(event, this)
if (addToCalDAV) {
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR) {
CalDAVEventsHandler(context).insertCalDAVEvent(event)
}
@ -222,7 +222,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
context.updateWidgets()
context.scheduleReminder(event, this)
if (updateAtCalDAV) {
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR) {
CalDAVEventsHandler(context).updateCalDAVEvent(event)
}
callback()

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.calendar.models
import com.simplemobiletools.calendar.extensions.parseCalendarIdFromSource
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
@ -88,8 +89,7 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
wantedDay = firstProperDay + ((daysCnt - firstProperDay) / 7) * 7
}
val addedProperOrder = properMonth.withDayOfMonth(wantedDay)
return addedProperOrder
return properMonth.withDayOfMonth(wantedDay)
}
fun getIsAllDay() = flags and FLAG_ALL_DAY != 0