Ensure event type visibility

This commit is contained in:
Naveen 2023-07-01 00:11:55 +05:30
parent c85b7fae80
commit 6f0a9e237e
No known key found for this signature in database
GPG Key ID: 0E155DAD31671DA3
3 changed files with 24 additions and 21 deletions

View File

@ -114,11 +114,7 @@ fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION }
if (validReminders.isEmpty()) {
if (showToasts) {
if (config.displayEventTypes.contains(event.eventType.toString())) {
toast(R.string.saving)
} else {
toast(R.string.saving_filtered_out, Toast.LENGTH_LONG)
}
toast(R.string.saving)
}
return
}
@ -153,13 +149,9 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event, showToasts: Boolean) {
val newNotifTS = notifTS + 1000
if (showToasts) {
if (config.displayEventTypes.contains(event.eventType.toString())) {
val secondsTillNotification = (newNotifTS - System.currentTimeMillis()) / 1000
val msg = String.format(getString(R.string.time_remaining), formatSecondsToTimeString(secondsTillNotification.toInt()))
toast(msg)
} else {
toast(R.string.saving_filtered_out, Toast.LENGTH_LONG)
}
val secondsTillNotification = (newNotifTS - System.currentTimeMillis()) / 1000
val msg = String.format(getString(R.string.time_remaining), formatSecondsToTimeString(secondsTillNotification.toInt()))
toast(msg)
}
val pendingIntent = getNotificationIntent(event)

View File

@ -261,7 +261,7 @@ class CalDAVHelper(val context: Context) {
// add this event to the parent event's list of exceptions
if (!parentEvent.repetitionExceptions.contains(originalDayCode)) {
parentEvent.addRepetitionException(originalDayCode)
eventsHelper.insertEvent(parentEvent, addToCalDAV = false, showToasts = false)
eventsHelper.insertEvent(parentEvent, addToCalDAV = false, showToasts = false, enableEventType = false)
}
// store the event in the local db only if it is an occurrence that has been modified and not deleted
@ -271,7 +271,7 @@ class CalDAVHelper(val context: Context) {
event.id = storedEventId
}
event.parentId = parentEvent.id!!
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false)
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false, enableEventType = false)
} else {
// delete the deleted exception event from local db
val storedEventId = context.eventsDB.getEventIdWithImportId(importId)
@ -321,12 +321,12 @@ class CalDAVHelper(val context: Context) {
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
event.id = originalEventId
eventsHelper.updateEvent(event, updateAtCalDAV = false, showToasts = false)
eventsHelper.updateEvent(event, updateAtCalDAV = false, showToasts = false, enableEventType = false)
}
} else {
if (title.isNotEmpty()) {
importIdsMap[event.importId] = event
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false)
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false, enableEventType = false)
}
}
}

View File

@ -110,7 +110,7 @@ class EventsHelper(val context: Context) {
}
}
fun insertEvent(event: Event, addToCalDAV: Boolean, showToasts: Boolean, callback: ((id: Long) -> Unit)? = null) {
fun insertEvent(event: Event, addToCalDAV: Boolean, showToasts: Boolean, enableEventType: Boolean = true, callback: ((id: Long) -> Unit)? = null) {
if (event.startTS > event.endTS) {
callback?.invoke(0)
return
@ -118,7 +118,7 @@ class EventsHelper(val context: Context) {
maybeUpdateParentExceptions(event)
event.id = eventsDB.insertOrUpdate(event)
ensureEventTypeVisibility(event, enableEventType)
context.updateWidgets()
context.scheduleNextEventReminder(event, showToasts)
@ -129,9 +129,10 @@ class EventsHelper(val context: Context) {
callback?.invoke(event.id!!)
}
fun insertTask(task: Event, showToasts: Boolean, callback: () -> Unit) {
fun insertTask(task: Event, showToasts: Boolean, enableEventType: Boolean = true, callback: () -> Unit) {
maybeUpdateParentExceptions(task)
task.id = eventsDB.insertOrUpdate(task)
ensureEventTypeVisibility(task, enableEventType)
context.updateWidgets()
context.scheduleNextEventReminder(task, showToasts)
callback()
@ -148,6 +149,16 @@ class EventsHelper(val context: Context) {
}
}
private fun ensureEventTypeVisibility(event: Event, enableEventType: Boolean) {
if (enableEventType) {
val eventType = event.eventType.toString()
val displayEventTypes = config.displayEventTypes
if (!displayEventTypes.contains(eventType)) {
config.displayEventTypes = displayEventTypes.plus(eventType)
}
}
}
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
try {
for (event in events) {
@ -168,9 +179,9 @@ class EventsHelper(val context: Context) {
}
}
fun updateEvent(event: Event, updateAtCalDAV: Boolean, showToasts: Boolean, callback: (() -> Unit)? = null) {
fun updateEvent(event: Event, updateAtCalDAV: Boolean, showToasts: Boolean, enableEventType: Boolean = true, callback: (() -> Unit)? = null) {
eventsDB.insertOrUpdate(event)
ensureEventTypeVisibility(event, enableEventType)
context.updateWidgets()
context.scheduleNextEventReminder(event, showToasts)
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {