mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Properly handle repeating tasks
This commit is contained in:
@@ -1378,14 +1378,7 @@ class EventActivity : SimpleActivity() {
|
||||
ensureBackgroundThread {
|
||||
val eventId = mEvent.id!!
|
||||
val originalEvent = eventsDB.getEventWithId(eventId) ?: return@ensureBackgroundThread
|
||||
val hasFixedRepeatCount = originalEvent.repeatLimit < 0 && mEvent.repeatLimit < 0
|
||||
val repeatLimitUnchanged = originalEvent.repeatLimit == mEvent.repeatLimit
|
||||
if (hasFixedRepeatCount && repeatLimitUnchanged) {
|
||||
val occurrencesSinceStart = (mEventOccurrenceTS - originalEvent.startTS) / originalEvent.repeatInterval
|
||||
val newRepeatLimit = mEvent.repeatLimit + occurrencesSinceStart
|
||||
mEvent.repeatLimit = newRepeatLimit
|
||||
}
|
||||
|
||||
mEvent.maybeAdjustRepeatLimitCount(originalEvent, mEventOccurrenceTS)
|
||||
mEvent.id = null
|
||||
eventsHelper.apply {
|
||||
addEventRepeatLimit(eventId, mEventOccurrenceTS)
|
||||
|
@@ -489,13 +489,15 @@ class TaskActivity : SimpleActivity() {
|
||||
}
|
||||
EDIT_FUTURE_OCCURRENCES -> {
|
||||
ensureBackgroundThread {
|
||||
eventsHelper.addEventRepeatLimit(mTask.id!!, mTaskOccurrenceTS)
|
||||
mTask.apply {
|
||||
id = null
|
||||
}
|
||||
|
||||
eventsHelper.insertTask(mTask, showToasts = true) {
|
||||
finish()
|
||||
val taskId = mTask.id!!
|
||||
val originalTask = eventsDB.getTaskWithId(taskId) ?: return@ensureBackgroundThread
|
||||
mTask.maybeAdjustRepeatLimitCount(originalTask, mTaskOccurrenceTS)
|
||||
mTask.id = null
|
||||
eventsHelper.apply {
|
||||
addEventRepeatLimit(taskId, mTaskOccurrenceTS)
|
||||
insertTask(mTask, showToasts = true) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,3 +29,13 @@ fun Event.toUtcAllDayEvent() {
|
||||
startTS = Formatter.getShiftedUtcTS(startTS)
|
||||
endTS = Formatter.getShiftedUtcTS(endTS)
|
||||
}
|
||||
|
||||
fun Event.maybeAdjustRepeatLimitCount(original: Event, occurrenceTS: Long) {
|
||||
val hasFixedRepeatCount = original.repeatLimit < 0 && repeatLimit < 0
|
||||
val repeatLimitUnchanged = original.repeatLimit == repeatLimit
|
||||
if (hasFixedRepeatCount && repeatLimitUnchanged) {
|
||||
val occurrencesSinceStart = (occurrenceTS - original.startTS) / original.repeatInterval
|
||||
val newRepeatLimit = repeatLimit + occurrencesSinceStart
|
||||
this.repeatLimit = newRepeatLimit
|
||||
}
|
||||
}
|
||||
|
@@ -226,7 +226,7 @@ class EventsHelper(val context: Context) {
|
||||
}
|
||||
|
||||
fun addEventRepeatLimit(eventId: Long, occurrenceTS: Long) {
|
||||
val event = eventsDB.getEventWithId(eventId) ?: return
|
||||
val event = eventsDB.getEventOrTaskWithId(eventId) ?: return
|
||||
val previousOccurrenceTS = occurrenceTS - event.repeatInterval // always update repeat limit of the occurrence preceding the one being edited
|
||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(previousOccurrenceTS).withTimeAtStartOfDay()
|
||||
val repeatLimitTS = if (event.getIsAllDay()) {
|
||||
|
Reference in New Issue
Block a user