mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-22 06:27:46 +01:00
simplify repetition exception handling, CalDAV synced too
This commit is contained in:
parent
5b0076302d
commit
3b6f06db8b
@ -680,7 +680,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
|
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
|
||||||
Thread {
|
Thread {
|
||||||
when (it) {
|
when (it) {
|
||||||
DELETE_SELECTED_OCCURRENCE -> eventsHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
DELETE_SELECTED_OCCURRENCE -> eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||||
DELETE_FUTURE_OCCURRENCES -> eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
DELETE_FUTURE_OCCURRENCES -> eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||||
DELETE_ALL_OCCURRENCES -> eventsHelper.deleteEvent(mEvent.id!!, true)
|
DELETE_ALL_OCCURRENCES -> eventsHelper.deleteEvent(mEvent.id!!, true)
|
||||||
}
|
}
|
||||||
@ -817,7 +817,7 @@ class EventActivity : SimpleActivity() {
|
|||||||
}.start()
|
}.start()
|
||||||
} else {
|
} else {
|
||||||
Thread {
|
Thread {
|
||||||
eventsHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
eventsHelper.addEventRepetitionException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||||
mEvent.apply {
|
mEvent.apply {
|
||||||
parentId = id!!.toLong()
|
parentId = id!!.toLong()
|
||||||
id = null
|
id = null
|
||||||
|
@ -440,7 +440,7 @@ fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Long>, ac
|
|||||||
when (action) {
|
when (action) {
|
||||||
DELETE_SELECTED_OCCURRENCE -> {
|
DELETE_SELECTED_OCCURRENCE -> {
|
||||||
eventIds.forEachIndexed { index, value ->
|
eventIds.forEachIndexed { index, value ->
|
||||||
eventsHelper.addEventRepeatException(value, timestamps[index], true)
|
eventsHelper.addEventRepetitionException(value, timestamps[index], true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DELETE_FUTURE_OCCURRENCES -> {
|
DELETE_FUTURE_OCCURRENCES -> {
|
||||||
|
@ -213,6 +213,18 @@ class CalDAVHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchedEventIds.add(importId)
|
fetchedEventIds.add(importId)
|
||||||
|
|
||||||
|
// if the event is an exception from another events repeat rule, find the original parent event
|
||||||
|
if (originalInstanceTime != 0L) {
|
||||||
|
val parentImportId = "$source-$originalId"
|
||||||
|
val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId)
|
||||||
|
if (parentEventId != null) {
|
||||||
|
event.parentId = parentEventId
|
||||||
|
eventsHelper.addEventRepetitionException(parentEventId, originalInstanceTime / 1000L, false)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -221,6 +233,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
this.id = null
|
this.id = null
|
||||||
color = 0
|
color = 0
|
||||||
lastUpdated = 0L
|
lastUpdated = 0L
|
||||||
|
repetitionExceptions = ArrayList()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
|
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
|
||||||
@ -232,16 +245,6 @@ class CalDAVHelper(val context: Context) {
|
|||||||
importIdsMap[event.importId] = event
|
importIdsMap[event.importId] = event
|
||||||
eventsHelper.insertEvent(null, event, false)
|
eventsHelper.insertEvent(null, event, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the event is an exception from another events repeat rule, find the original parent event
|
|
||||||
if (originalInstanceTime != 0L) {
|
|
||||||
val parentImportId = "$source-$originalId"
|
|
||||||
val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId)
|
|
||||||
if (parentEventId != null) {
|
|
||||||
event.parentId = parentEventId
|
|
||||||
eventsHelper.addEventRepeatException(parentEventId, originalInstanceTime / 1000L, false, event.importId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -186,39 +186,18 @@ class EventsHelper(val context: Context) {
|
|||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEventRepeatException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean, childImportId: String? = null) {
|
fun addEventRepetitionException(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
|
||||||
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId)
|
Thread {
|
||||||
}
|
val parentEvent = eventsDB.getEventWithId(parentEventId) ?: return@Thread
|
||||||
|
val parentEventRepetitionExceptions = parentEvent.repetitionExceptions
|
||||||
|
parentEventRepetitionExceptions.add(Formatter.getDayCodeFromTS(occurrenceTS))
|
||||||
|
eventsDB.updateEventRepetitionExceptions(parentEventRepetitionExceptions, parentEventId)
|
||||||
|
context.scheduleNextEventReminder(parentEvent)
|
||||||
|
|
||||||
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean, childImportId: String?) {
|
if (addToCalDAV && config.caldavSync) {
|
||||||
val childEvent = eventsDB.getEventWithId(parentEventId) ?: return
|
context.calDAVHelper.insertEventRepeatException(parentEvent, occurrenceTS)
|
||||||
|
|
||||||
childEvent.apply {
|
|
||||||
id = null
|
|
||||||
parentId = parentEventId
|
|
||||||
startTS = 0
|
|
||||||
endTS = 0
|
|
||||||
if (childImportId != null) {
|
|
||||||
importId = childImportId
|
|
||||||
}
|
}
|
||||||
}
|
}.start()
|
||||||
|
|
||||||
insertEvent(null, childEvent, false) {
|
|
||||||
val childEventId = it
|
|
||||||
Thread {
|
|
||||||
val parentEvent = eventsDB.getEventWithId(parentEventId) ?: return@Thread
|
|
||||||
val parentEventRepetitionExceptions = parentEvent.repetitionExceptions
|
|
||||||
parentEventRepetitionExceptions.add(Formatter.getDayCodeFromTS(occurrenceTS))
|
|
||||||
eventsDB.updateEventRepetitionExceptions(parentEventRepetitionExceptions, parentEventId)
|
|
||||||
context.scheduleNextEventReminder(parentEvent)
|
|
||||||
|
|
||||||
if (addToCalDAV && config.caldavSync) {
|
|
||||||
val newId = context.calDAVHelper.insertEventRepeatException(parentEvent, occurrenceTS)
|
|
||||||
val newImportId = "${parentEvent.source}-$newId"
|
|
||||||
eventsDB.updateEventImportIdAndSource(newImportId, parentEvent.source, childEventId)
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEvents(fromTS: Long, toTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean = true, callback: (events: ArrayList<Event>) -> Unit) {
|
fun getEvents(fromTS: Long, toTS: Long, eventId: Long = -1L, applyTypeFilter: Boolean = true, callback: (events: ArrayList<Event>) -> Unit) {
|
||||||
|
@ -162,7 +162,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||||||
} else {
|
} else {
|
||||||
eventsHelper.insertEvent(activity, event, true) {
|
eventsHelper.insertEvent(activity, event, true) {
|
||||||
for (exceptionTS in curRepeatExceptions) {
|
for (exceptionTS in curRepeatExceptions) {
|
||||||
eventsHelper.addEventRepeatException(it, exceptionTS, true)
|
eventsHelper.addEventRepetitionException(it, exceptionTS, true)
|
||||||
}
|
}
|
||||||
existingEvents.add(event)
|
existingEvents.add(event)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user