mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
properly send created repeatable event exception to the adapter
This commit is contained in:
parent
beb00ecf89
commit
71a6316b29
@ -505,7 +505,7 @@ class EventActivity : SimpleActivity() {
|
||||
if (it) {
|
||||
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
|
||||
} else {
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS)
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
@ -595,7 +595,7 @@ class EventActivity : SimpleActivity() {
|
||||
eventUpdated()
|
||||
}
|
||||
} else {
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS)
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS, true)
|
||||
mEvent.parentId = mEvent.id
|
||||
mEvent.id = 0
|
||||
dbHelper.insert(mEvent, true) {
|
||||
|
@ -163,7 +163,7 @@ class DayFragment : Fragment(), DeleteEventsListener {
|
||||
|
||||
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
parentIds.forEachIndexed { index, value ->
|
||||
context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index])
|
||||
context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index], true)
|
||||
}
|
||||
(activity as DayActivity).recheckEvents()
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ class EventListFragment : Fragment(), DeleteEventsListener {
|
||||
|
||||
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
parentIds.forEachIndexed { index, value ->
|
||||
context!!.dbHelper.addEventRepeatException(value, timestamps[index])
|
||||
context!!.dbHelper.addEventRepeatException(value, timestamps[index], true)
|
||||
}
|
||||
checkEvents()
|
||||
}
|
||||
|
@ -22,15 +22,14 @@ import kotlin.collections.ArrayList
|
||||
|
||||
class CalDAVHandler(val context: Context) {
|
||||
fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) {
|
||||
val dbHelper = context.dbHelper
|
||||
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 {
|
||||
title = calendar.displayName
|
||||
caldavDisplayName = calendar.displayName
|
||||
caldavEmail = calendar.accountName
|
||||
color = calendar.color
|
||||
dbHelper.updateLocalEventType(this)
|
||||
context.dbHelper.updateLocalEventType(this)
|
||||
}
|
||||
|
||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id, activity)
|
||||
@ -264,7 +263,7 @@ class CalDAVHandler(val context: Context) {
|
||||
val parentEventId = context.dbHelper.getEventIdWithImportId(parentImportId)
|
||||
if (parentEventId != 0) {
|
||||
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> {
|
||||
val reminders = ArrayList<Int>()
|
||||
val uri = CalendarContract.Reminders.CONTENT_URI
|
||||
|
@ -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)
|
||||
if (childEvent == null) {
|
||||
callback(ContentValues())
|
||||
@ -337,12 +337,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
}
|
||||
|
||||
insert(childEvent, false) {
|
||||
callback(ContentValues().apply {
|
||||
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)
|
||||
})
|
||||
}
|
||||
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) {
|
||||
fillExceptionValues(parentEventId, occurrenceTS, childImportId) {
|
||||
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
|
||||
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
|
||||
mDb.insert(EXCEPTIONS_TABLE_NAME, null, it)
|
||||
|
||||
val parentEvent = getEventWithId(parentEventId)
|
||||
|
@ -134,7 +134,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
if (eventToUpdate == null) {
|
||||
activity.dbHelper.insert(event, false) {
|
||||
for (exceptionTS in curRepeatExceptions) {
|
||||
activity.dbHelper.addEventRepeatException(it, exceptionTS)
|
||||
activity.dbHelper.addEventRepeatException(it, exceptionTS, false)
|
||||
}
|
||||
existingEvents.add(event)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user