mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Code readability improvement
This commit is contained in:
@ -116,14 +116,7 @@ class EventsHelper(val context: Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val parentEventId = event.parentId
|
maybeUpdateParentExceptions(event)
|
||||||
if (parentEventId != 0L) {
|
|
||||||
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return
|
|
||||||
val startDayCode = Formatter.getDayCodeFromTS(event.startTS)
|
|
||||||
parentEvent.addRepetitionException(startDayCode)
|
|
||||||
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
|
|
||||||
}
|
|
||||||
|
|
||||||
event.id = eventsDB.insertOrUpdate(event)
|
event.id = eventsDB.insertOrUpdate(event)
|
||||||
|
|
||||||
context.updateWidgets()
|
context.updateWidgets()
|
||||||
@ -137,20 +130,24 @@ class EventsHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun insertTask(task: Event, showToasts: Boolean, callback: () -> Unit) {
|
fun insertTask(task: Event, showToasts: Boolean, callback: () -> Unit) {
|
||||||
val parentEventId = task.parentId
|
maybeUpdateParentExceptions(task)
|
||||||
if (parentEventId != 0L) {
|
|
||||||
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return
|
|
||||||
val startDayCode = Formatter.getDayCodeFromTS(task.startTS)
|
|
||||||
parentEvent.addRepetitionException(startDayCode)
|
|
||||||
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
|
|
||||||
}
|
|
||||||
|
|
||||||
task.id = eventsDB.insertOrUpdate(task)
|
task.id = eventsDB.insertOrUpdate(task)
|
||||||
context.updateWidgets()
|
context.updateWidgets()
|
||||||
context.scheduleNextEventReminder(task, showToasts)
|
context.scheduleNextEventReminder(task, showToasts)
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun maybeUpdateParentExceptions(event: Event) {
|
||||||
|
// if the event is an exception from another event, update the parent event's exceptions list
|
||||||
|
val parentEventId = event.parentId
|
||||||
|
if (parentEventId != 0L) {
|
||||||
|
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return
|
||||||
|
val startDayCode = Formatter.getDayCodeFromTS(event.startTS)
|
||||||
|
parentEvent.addRepetitionException(startDayCode)
|
||||||
|
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
||||||
try {
|
try {
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
@ -251,11 +248,9 @@ class EventsHelper(val context: Context) {
|
|||||||
fun deleteRepeatingEventOccurrence(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
|
fun deleteRepeatingEventOccurrence(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
|
||||||
ensureBackgroundThread {
|
ensureBackgroundThread {
|
||||||
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread
|
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread
|
||||||
var repetitionExceptions = parentEvent.repetitionExceptions
|
val occurrenceDayCode = Formatter.getDayCodeFromTS(occurrenceTS)
|
||||||
repetitionExceptions.add(Formatter.getDayCodeFromTS(occurrenceTS))
|
parentEvent.addRepetitionException(occurrenceDayCode)
|
||||||
repetitionExceptions = repetitionExceptions.distinct().toMutableList() as ArrayList<String>
|
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
|
||||||
|
|
||||||
eventsDB.updateEventRepetitionExceptions(repetitionExceptions.toString(), parentEventId)
|
|
||||||
context.scheduleNextEventReminder(parentEvent, false)
|
context.scheduleNextEventReminder(parentEvent, false)
|
||||||
|
|
||||||
if (addToCalDAV && config.caldavSync) {
|
if (addToCalDAV && config.caldavSync) {
|
||||||
|
Reference in New Issue
Block a user