Code readability improvement

This commit is contained in:
Naveen 2023-06-15 23:51:10 +05:30
parent 13019e6835
commit dbfa1880b7
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
1 changed files with 16 additions and 21 deletions

View File

@ -116,14 +116,7 @@ class EventsHelper(val context: Context) {
return
}
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)
}
maybeUpdateParentExceptions(event)
event.id = eventsDB.insertOrUpdate(event)
context.updateWidgets()
@ -137,20 +130,24 @@ class EventsHelper(val context: Context) {
}
fun insertTask(task: Event, showToasts: Boolean, callback: () -> Unit) {
val parentEventId = task.parentId
if (parentEventId != 0L) {
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return
val startDayCode = Formatter.getDayCodeFromTS(task.startTS)
parentEvent.addRepetitionException(startDayCode)
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
}
maybeUpdateParentExceptions(task)
task.id = eventsDB.insertOrUpdate(task)
context.updateWidgets()
context.scheduleNextEventReminder(task, showToasts)
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) {
try {
for (event in events) {
@ -251,11 +248,9 @@ class EventsHelper(val context: Context) {
fun deleteRepeatingEventOccurrence(parentEventId: Long, occurrenceTS: Long, addToCalDAV: Boolean) {
ensureBackgroundThread {
val parentEvent = eventsDB.getEventOrTaskWithId(parentEventId) ?: return@ensureBackgroundThread
var repetitionExceptions = parentEvent.repetitionExceptions
repetitionExceptions.add(Formatter.getDayCodeFromTS(occurrenceTS))
repetitionExceptions = repetitionExceptions.distinct().toMutableList() as ArrayList<String>
eventsDB.updateEventRepetitionExceptions(repetitionExceptions.toString(), parentEventId)
val occurrenceDayCode = Formatter.getDayCodeFromTS(occurrenceTS)
parentEvent.addRepetitionException(occurrenceDayCode)
eventsDB.updateEventRepetitionExceptions(parentEvent.repetitionExceptions.toString(), parentEventId)
context.scheduleNextEventReminder(parentEvent, false)
if (addToCalDAV && config.caldavSync) {