properly send created repeatable event exception to the adapter

This commit is contained in:
tibbi
2018-01-10 23:44:02 +01:00
parent beb00ecf89
commit 71a6316b29
6 changed files with 40 additions and 14 deletions

View File

@ -505,7 +505,7 @@ class EventActivity : SimpleActivity() {
if (it) { if (it) {
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true) dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
} else { } else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS) dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
} }
finish() finish()
} }
@ -595,7 +595,7 @@ class EventActivity : SimpleActivity() {
eventUpdated() eventUpdated()
} }
} else { } else {
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS) dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
mEvent.parentId = mEvent.id mEvent.parentId = mEvent.id
mEvent.id = 0 mEvent.id = 0
dbHelper.insert(mEvent, true) { dbHelper.insert(mEvent, true) {

View File

@ -163,7 +163,7 @@ class DayFragment : Fragment(), DeleteEventsListener {
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) { override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
parentIds.forEachIndexed { index, value -> parentIds.forEachIndexed { index, value ->
context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index]) context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index], true)
} }
(activity as DayActivity).recheckEvents() (activity as DayActivity).recheckEvents()
} }

View File

@ -123,7 +123,7 @@ class EventListFragment : Fragment(), DeleteEventsListener {
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) { override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
parentIds.forEachIndexed { index, value -> parentIds.forEachIndexed { index, value ->
context!!.dbHelper.addEventRepeatException(value, timestamps[index]) context!!.dbHelper.addEventRepeatException(value, timestamps[index], true)
} }
checkEvents() checkEvents()
} }

View File

@ -22,15 +22,14 @@ import kotlin.collections.ArrayList
class CalDAVHandler(val context: Context) { class CalDAVHandler(val context: Context) {
fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) { fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) {
val dbHelper = context.dbHelper
for (calendar in getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs)) { for (calendar in getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs)) {
val localEventType = dbHelper.getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue val localEventType = context.dbHelper.getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue
localEventType.apply { localEventType.apply {
title = calendar.displayName title = calendar.displayName
caldavDisplayName = calendar.displayName caldavDisplayName = calendar.displayName
caldavEmail = calendar.accountName caldavEmail = calendar.accountName
color = calendar.color color = calendar.color
dbHelper.updateLocalEventType(this) context.dbHelper.updateLocalEventType(this)
} }
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id, activity) CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id, activity)
@ -264,7 +263,7 @@ class CalDAVHandler(val context: Context) {
val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId) val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId)
if (parentEventId != 0) { if (parentEventId != 0) {
event.parentId = parentEventId event.parentId = parentEventId
context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), event.importId) context.dbHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId)
} }
} }
@ -394,6 +393,23 @@ class CalDAVHandler(val context: Context) {
} }
} }
fun insertEventRepeatException(event: Event, occurrenceTS: Int) {
val uri = CalendarContract.Events.CONTENT_URI
val values = fillEventRepeatExceptionValues(event, occurrenceTS)
context.contentResolver.insert(uri, values)
}
private fun fillEventRepeatExceptionValues(event: Event, occurrenceTS: Int): ContentValues {
return ContentValues().apply {
put(CalendarContract.Events.CALENDAR_ID, event.getCalDAVCalendarId())
put(CalendarContract.Events.DTSTART, 0)
put(CalendarContract.Events.DTEND, 0)
put(CalendarContract.Events.ORIGINAL_ID, event.getCalDAVEventId())
put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().toString())
put(CalendarContract.Events.ORIGINAL_INSTANCE_TIME, occurrenceTS * 1000L)
}
}
private fun getCalDAVEventReminders(eventId: Long): List<Int> { private fun getCalDAVEventReminders(eventId: Long): List<Int> {
val reminders = ArrayList<Int>() val reminders = ArrayList<Int>()
val uri = CalendarContract.Reminders.CONTENT_URI val uri = CalendarContract.Reminders.CONTENT_URI

View File

@ -319,7 +319,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
} }
private fun fillExceptionValues(parentEventId: Int, occurrenceTS: Int, childImportId: String?, callback: (values: ContentValues) -> Unit) { private fun fillExceptionValues(parentEventId: Int, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (values: ContentValues) -> Unit) {
val childEvent = getEventWithId(parentEventId) val childEvent = getEventWithId(parentEventId)
if (childEvent == null) { if (childEvent == null) {
callback(ContentValues()) callback(ContentValues())
@ -337,12 +337,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
insert(childEvent, false) { insert(childEvent, false) {
callback(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, it)
}) }
callback(exceptionValues)
Thread {
if (addToCalDAV && context.config.caldavSync) {
val parentEvent = getEventWithId(parentEventId)
if (parentEvent != null) {
CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
}
}
}.start()
} }
} }
@ -496,8 +506,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
} }
} }
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int, childImportId: String? = null) { fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
fillExceptionValues(parentEventId, occurrenceTS, childImportId) { fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it) mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)
val parentEvent = getEventWithId(parentEventId) val parentEvent = getEventWithId(parentEventId)

View File

@ -134,7 +134,7 @@ class IcsImporter(val activity: SimpleActivity) {
if (eventToUpdate == null) { if (eventToUpdate == null) {
activity.dbHelper.insert(event, false) { activity.dbHelper.insert(event, false) {
for (exceptionTS in curRepeatExceptions) { for (exceptionTS in curRepeatExceptions) {
activity.dbHelper.addEventRepeatException(it, exceptionTS) activity.dbHelper.addEventRepeatException(it, exceptionTS, false)
} }
existingEvents.add(event) existingEvents.add(event)
} }