mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
Ensure event type visibility
This commit is contained in:
@@ -114,11 +114,7 @@ fun Context.scheduleNextEventReminder(event: Event, showToasts: Boolean) {
|
|||||||
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION }
|
val validReminders = event.getReminders().filter { it.type == REMINDER_NOTIFICATION }
|
||||||
if (validReminders.isEmpty()) {
|
if (validReminders.isEmpty()) {
|
||||||
if (showToasts) {
|
if (showToasts) {
|
||||||
if (config.displayEventTypes.contains(event.eventType.toString())) {
|
toast(R.string.saving)
|
||||||
toast(R.string.saving)
|
|
||||||
} else {
|
|
||||||
toast(R.string.saving_filtered_out, Toast.LENGTH_LONG)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -153,13 +149,9 @@ fun Context.scheduleEventIn(notifTS: Long, event: Event, showToasts: Boolean) {
|
|||||||
|
|
||||||
val newNotifTS = notifTS + 1000
|
val newNotifTS = notifTS + 1000
|
||||||
if (showToasts) {
|
if (showToasts) {
|
||||||
if (config.displayEventTypes.contains(event.eventType.toString())) {
|
val secondsTillNotification = (newNotifTS - System.currentTimeMillis()) / 1000
|
||||||
val secondsTillNotification = (newNotifTS - System.currentTimeMillis()) / 1000
|
val msg = String.format(getString(R.string.time_remaining), formatSecondsToTimeString(secondsTillNotification.toInt()))
|
||||||
val msg = String.format(getString(R.string.time_remaining), formatSecondsToTimeString(secondsTillNotification.toInt()))
|
toast(msg)
|
||||||
toast(msg)
|
|
||||||
} else {
|
|
||||||
toast(R.string.saving_filtered_out, Toast.LENGTH_LONG)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val pendingIntent = getNotificationIntent(event)
|
val pendingIntent = getNotificationIntent(event)
|
||||||
|
@@ -261,7 +261,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
// add this event to the parent event's list of exceptions
|
// add this event to the parent event's list of exceptions
|
||||||
if (!parentEvent.repetitionExceptions.contains(originalDayCode)) {
|
if (!parentEvent.repetitionExceptions.contains(originalDayCode)) {
|
||||||
parentEvent.addRepetitionException(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
|
// 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.id = storedEventId
|
||||||
}
|
}
|
||||||
event.parentId = parentEvent.id!!
|
event.parentId = parentEvent.id!!
|
||||||
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false)
|
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false, enableEventType = false)
|
||||||
} else {
|
} else {
|
||||||
// delete the deleted exception event from local db
|
// delete the deleted exception event from local db
|
||||||
val storedEventId = context.eventsDB.getEventIdWithImportId(importId)
|
val storedEventId = context.eventsDB.getEventIdWithImportId(importId)
|
||||||
@@ -321,12 +321,12 @@ class CalDAVHelper(val context: Context) {
|
|||||||
|
|
||||||
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
|
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
|
||||||
event.id = originalEventId
|
event.id = originalEventId
|
||||||
eventsHelper.updateEvent(event, updateAtCalDAV = false, showToasts = false)
|
eventsHelper.updateEvent(event, updateAtCalDAV = false, showToasts = false, enableEventType = false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (title.isNotEmpty()) {
|
if (title.isNotEmpty()) {
|
||||||
importIdsMap[event.importId] = event
|
importIdsMap[event.importId] = event
|
||||||
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false)
|
eventsHelper.insertEvent(event, addToCalDAV = false, showToasts = false, enableEventType = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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) {
|
if (event.startTS > event.endTS) {
|
||||||
callback?.invoke(0)
|
callback?.invoke(0)
|
||||||
return
|
return
|
||||||
@@ -118,7 +118,7 @@ class EventsHelper(val context: Context) {
|
|||||||
|
|
||||||
maybeUpdateParentExceptions(event)
|
maybeUpdateParentExceptions(event)
|
||||||
event.id = eventsDB.insertOrUpdate(event)
|
event.id = eventsDB.insertOrUpdate(event)
|
||||||
|
ensureEventTypeVisibility(event, enableEventType)
|
||||||
context.updateWidgets()
|
context.updateWidgets()
|
||||||
context.scheduleNextEventReminder(event, showToasts)
|
context.scheduleNextEventReminder(event, showToasts)
|
||||||
|
|
||||||
@@ -129,9 +129,10 @@ class EventsHelper(val context: Context) {
|
|||||||
callback?.invoke(event.id!!)
|
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)
|
maybeUpdateParentExceptions(task)
|
||||||
task.id = eventsDB.insertOrUpdate(task)
|
task.id = eventsDB.insertOrUpdate(task)
|
||||||
|
ensureEventTypeVisibility(task, enableEventType)
|
||||||
context.updateWidgets()
|
context.updateWidgets()
|
||||||
context.scheduleNextEventReminder(task, showToasts)
|
context.scheduleNextEventReminder(task, showToasts)
|
||||||
callback()
|
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) {
|
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
||||||
try {
|
try {
|
||||||
for (event in events) {
|
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)
|
eventsDB.insertOrUpdate(event)
|
||||||
|
ensureEventTypeVisibility(event, enableEventType)
|
||||||
context.updateWidgets()
|
context.updateWidgets()
|
||||||
context.scheduleNextEventReminder(event, showToasts)
|
context.scheduleNextEventReminder(event, showToasts)
|
||||||
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {
|
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {
|
||||||
|
Reference in New Issue
Block a user