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 {
|
ensureBackgroundThread {
|
||||||
val eventId = mEvent.id!!
|
val eventId = mEvent.id!!
|
||||||
val originalEvent = eventsDB.getEventWithId(eventId) ?: return@ensureBackgroundThread
|
val originalEvent = eventsDB.getEventWithId(eventId) ?: return@ensureBackgroundThread
|
||||||
val hasFixedRepeatCount = originalEvent.repeatLimit < 0 && mEvent.repeatLimit < 0
|
mEvent.maybeAdjustRepeatLimitCount(originalEvent, mEventOccurrenceTS)
|
||||||
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.id = null
|
mEvent.id = null
|
||||||
eventsHelper.apply {
|
eventsHelper.apply {
|
||||||
addEventRepeatLimit(eventId, mEventOccurrenceTS)
|
addEventRepeatLimit(eventId, mEventOccurrenceTS)
|
||||||
|
@@ -489,13 +489,15 @@ class TaskActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
EDIT_FUTURE_OCCURRENCES -> {
|
EDIT_FUTURE_OCCURRENCES -> {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
eventsHelper.addEventRepeatLimit(mTask.id!!, mTaskOccurrenceTS)
|
val taskId = mTask.id!!
|
||||||
mTask.apply {
|
val originalTask = eventsDB.getTaskWithId(taskId) ?: return@ensureBackgroundThread
|
||||||
id = null
|
mTask.maybeAdjustRepeatLimitCount(originalTask, mTaskOccurrenceTS)
|
||||||
}
|
mTask.id = null
|
||||||
|
eventsHelper.apply {
|
||||||
eventsHelper.insertTask(mTask, showToasts = true) {
|
addEventRepeatLimit(taskId, mTaskOccurrenceTS)
|
||||||
finish()
|
insertTask(mTask, showToasts = true) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,3 +29,13 @@ fun Event.toUtcAllDayEvent() {
|
|||||||
startTS = Formatter.getShiftedUtcTS(startTS)
|
startTS = Formatter.getShiftedUtcTS(startTS)
|
||||||
endTS = Formatter.getShiftedUtcTS(endTS)
|
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) {
|
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 previousOccurrenceTS = occurrenceTS - event.repeatInterval // always update repeat limit of the occurrence preceding the one being edited
|
||||||
val repeatLimitDateTime = Formatter.getDateTimeFromTS(previousOccurrenceTS).withTimeAtStartOfDay()
|
val repeatLimitDateTime = Formatter.getDateTimeFromTS(previousOccurrenceTS).withTimeAtStartOfDay()
|
||||||
val repeatLimitTS = if (event.getIsAllDay()) {
|
val repeatLimitTS = if (event.getIsAllDay()) {
|
||||||
|
Reference in New Issue
Block a user