From ec40b5954c8c9c9df79fb7a357890d62df166f8b Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 14 Nov 2018 19:08:23 +0100 Subject: [PATCH] require Context at EventsHelper constructor --- .../calendar/pro/activities/EventActivity.kt | 12 +++---- .../calendar/pro/activities/MainActivity.kt | 16 +++++----- .../activities/ManageEventTypesActivity.kt | 4 +-- .../pro/activities/SettingsActivity.kt | 12 +++---- .../pro/dialogs/EditEventTypeDialog.kt | 4 +-- .../pro/dialogs/ExportEventsDialog.kt | 2 +- .../pro/dialogs/FilterEventTypesDialog.kt | 2 +- .../pro/dialogs/ImportEventsDialog.kt | 2 +- .../pro/dialogs/SelectEventCalendarDialog.kt | 2 +- .../pro/dialogs/SelectEventTypeDialog.kt | 2 +- .../calendar/pro/fragments/WeekFragment.kt | 2 +- .../calendar/pro/helpers/CalDAVHandler.kt | 8 ++--- .../calendar/pro/helpers/DBHelper.kt | 4 +-- .../calendar/pro/helpers/EventsHelper.kt | 32 +++++++++---------- .../calendar/pro/helpers/IcsExporter.kt | 2 +- .../calendar/pro/helpers/IcsImporter.kt | 12 +++---- .../pro/receivers/NotificationReceiver.kt | 2 +- 17 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index aa630728b..da94ab4d0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -648,7 +648,7 @@ class EventActivity : SimpleActivity() { event_caldav_calendar_email.text = currentCalendar.accountName Thread { - val calendarColor = EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, currentCalendar.id)?.color + val calendarColor = EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color ?: currentCalendar.color runOnUiThread { @@ -732,7 +732,7 @@ class EventActivity : SimpleActivity() { val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) { mEventTypeId } else { - EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId + EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId } val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) { @@ -785,7 +785,7 @@ class EventActivity : SimpleActivity() { private fun storeEvent(wasRepeatable: Boolean) { if (mEvent.id == 0L || mEvent.id == null) { - EventsHelper().insertEvent(applicationContext, this, mEvent, true) { + EventsHelper(applicationContext).insertEvent(this, mEvent, true) { if (DateTime.now().isAfter(mEventStartDateTime.millis)) { if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) { notifyEvent(mEvent) @@ -800,7 +800,7 @@ class EventActivity : SimpleActivity() { showEditRepeatingEventDialog() } } else { - EventsHelper().updateEvent(applicationContext, this, mEvent, true) { + EventsHelper(applicationContext).updateEvent(this, mEvent, true) { finish() } } @@ -811,7 +811,7 @@ class EventActivity : SimpleActivity() { EditRepeatingEventDialog(this) { if (it) { Thread { - EventsHelper().updateEvent(applicationContext, this, mEvent, true) { + EventsHelper(applicationContext).updateEvent(this, mEvent, true) { finish() } }.start() @@ -826,7 +826,7 @@ class EventActivity : SimpleActivity() { repeatLimit = 0 } - EventsHelper().insertEvent(applicationContext, this, mEvent, true) { + EventsHelper(applicationContext).insertEvent(this, mEvent, true) { finish() } }.start() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index a6046d0a7..41dc310ef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -112,7 +112,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { updateViewPager() } - EventsHelper().getEventTypes(this) { + EventsHelper(applicationContext).getEventTypes(this) { val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty() if (newShouldFilterBeVisible != mShouldFilterBeVisible) { mShouldFilterBeVisible = newShouldFilterBeVisible @@ -402,10 +402,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { toast(R.string.importing) Thread { val holidays = getString(R.string.holidays) - var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, holidays) + var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(holidays) if (eventTypeId == -1L) { val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color)) - eventTypeId = EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType) + eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType) } val result = IcsImporter(this).importEvents(it as String, eventTypeId, 0, false) @@ -505,7 +505,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { eventType = eventTypeId, source = source, lastUpdated = lastUpdated) if (!importIDs.contains(contactId)) { - EventsHelper().insertEvent(applicationContext, null, event, false) { + EventsHelper(applicationContext).insertEvent(null, event, false) { eventsAdded++ } } @@ -528,20 +528,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { private fun getBirthdaysEventTypeId(): Long { val birthdays = getString(R.string.birthdays) - var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, birthdays) + var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(birthdays) if (eventTypeId == -1L) { val eventType = EventType(null, birthdays, resources.getColor(R.color.default_birthdays_color)) - eventTypeId = EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType) + eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType) } return eventTypeId } private fun getAnniversariesEventTypeId(): Long { val anniversaries = getString(R.string.anniversaries) - var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, anniversaries) + var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(anniversaries) if (eventTypeId == -1L) { val eventType = EventType(null, anniversaries, resources.getColor(R.color.default_anniversaries_color)) - eventTypeId = EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType) + eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType) } return eventTypeId } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/ManageEventTypesActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/ManageEventTypesActivity.kt index b13acf2a3..d73655d27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/ManageEventTypesActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/ManageEventTypesActivity.kt @@ -30,7 +30,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener { } private fun getEventTypes() { - EventsHelper().getEventTypes(this) { + EventsHelper(applicationContext).getEventTypes(this) { val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) { showEventTypeDialog(it as EventType) } @@ -60,7 +60,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener { } Thread { - EventsHelper().deleteEventTypes(applicationContext, eventTypes, deleteEvents) + EventsHelper(applicationContext).deleteEventTypes(eventTypes, deleteEvents) }.start() return true } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt index 4b7678417..d2551410a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt @@ -89,11 +89,11 @@ class SettingsActivity : SimpleActivity() { private fun checkPrimaryColor() { if (config.primaryColor != mStoredPrimaryColor) { Thread { - val eventTypes = EventsHelper().getEventTypesSync(this) + val eventTypes = EventsHelper(applicationContext).getEventTypesSync() if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) { val eventType = eventTypes.first { it.caldavCalendarId == 0 } eventType.color = config.primaryColor - EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType) + EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType) } }.start() } @@ -208,13 +208,13 @@ class SettingsActivity : SimpleActivity() { Thread { if (newCalendarIds.isNotEmpty()) { - val existingEventTypeNames = EventsHelper().getEventTypesSync(applicationContext).map { it.getDisplayTitle().toLowerCase() } as ArrayList + val existingEventTypeNames = EventsHelper(applicationContext).getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList getSyncedCalDAVCalendars().forEach { val calendarTitle = it.getFullTitle() if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) { val eventType = EventType(null, it.displayName, it.color, it.id, it.displayName, it.accountName) existingEventTypeNames.add(calendarTitle.toLowerCase()) - EventsHelper().insertOrUpdateEventType(this, eventType) + EventsHelper(applicationContext).insertOrUpdateEventType(this, eventType) } } CalDAVHandler(applicationContext).refreshCalendars(this) {} @@ -223,8 +223,8 @@ class SettingsActivity : SimpleActivity() { val removedCalendarIds = oldCalendarIds.filter { !newCalendarIds.contains(it) } removedCalendarIds.forEach { CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong()) - EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, it)?.apply { - EventsHelper().deleteEventTypes(applicationContext, arrayListOf(this), true) + EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(it)?.apply { + EventsHelper(applicationContext).deleteEventTypes(arrayListOf(this), true) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/EditEventTypeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/EditEventTypeDialog.kt index 61bc871a7..5f8ad5286 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/EditEventTypeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/EditEventTypeDialog.kt @@ -58,7 +58,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu } private fun eventTypeConfirmed(title: String, dialog: AlertDialog) { - val eventIdWithTitle = EventsHelper().getEventTypeIdWithTitle(activity, title) + val eventIdWithTitle = EventsHelper(activity).getEventTypeIdWithTitle(title) var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L if (!isEventTypeTitleTaken) { isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L @@ -77,7 +77,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu eventType!!.caldavDisplayName = title } - eventType!!.id = EventsHelper().insertOrUpdateEventTypeSync(activity, eventType!!) + eventType!!.id = EventsHelper(activity).insertOrUpdateEventTypeSync(eventType!!) if (eventType!!.id != -1L) { activity.runOnUiThread { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt index f8390b12a..5cc8c8a14 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ExportEventsDialog.kt @@ -19,7 +19,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal export_events_folder.text = activity.humanizePath(path) export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}") - EventsHelper().getEventTypes(activity) { + EventsHelper(activity).getEventTypes(activity) { val eventTypes = HashSet() it.mapTo(eventTypes) { it.id.toString() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/FilterEventTypesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/FilterEventTypesDialog.kt index c94bbd9aa..9912a21a6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/FilterEventTypesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/FilterEventTypesDialog.kt @@ -14,7 +14,7 @@ class FilterEventTypesDialog(val activity: SimpleActivity, val callback: () -> U private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null) init { - EventsHelper().getEventTypes(activity) { + EventsHelper(activity).getEventTypes(activity) { val displayEventTypes = activity.config.displayEventTypes view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt index e92fb5336..2a362eb36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/ImportEventsDialog.kt @@ -34,7 +34,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal private fun initDialog() { val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId) currEventTypeId = if (isLastCaldavCalendarOK) { - val lastUsedCalDAVCalendar = EventsHelper().getEventTypeWithCalDAVCalendarId(activity, config.lastUsedCaldavCalendarId) + val lastUsedCalDAVCalendar = EventsHelper(activity).getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId) if (lastUsedCalDAVCalendar != null) { currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId lastUsedCalDAVCalendar.id!! diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/SelectEventCalendarDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/SelectEventCalendarDialog.kt index b5e18a471..827f4e744 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/SelectEventCalendarDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/SelectEventCalendarDialog.kt @@ -28,7 +28,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List Unit) { val calDAVCalendars = getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs) for (calendar in calDAVCalendars) { - val localEventType = EventsHelper().getEventTypeWithCalDAVCalendarId(context, calendar.id) ?: continue + val localEventType = EventsHelper(context).getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue localEventType.apply { title = calendar.displayName caldavDisplayName = calendar.displayName caldavEmail = calendar.accountName - EventsHelper().insertOrUpdateEventTypeSync(context, this) + EventsHelper(context).insertOrUpdateEventTypeSync(this) } CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity) @@ -226,7 +226,7 @@ class CalDAVHandler(val context: Context) { if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) { event.id = originalEventId - EventsHelper().updateEvent(context, null, event, false) + EventsHelper(context).updateEvent(null, event, false) } } else { // if the event is an exception from another events repeat rule, find the original parent event @@ -241,7 +241,7 @@ class CalDAVHandler(val context: Context) { if (title.isNotEmpty()) { importIdsMap[event.importId] = event - EventsHelper().insertEvent(context, null, event, false) + EventsHelper(context).insertEvent(null, event, false) } } } while (cursor.moveToNext()) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt index 31460ffb4..84cb2669e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/DBHelper.kt @@ -72,7 +72,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } - EventsHelper().insertEvent(context, null, childEvent, false) { + EventsHelper(context).insertEvent(null, childEvent, false) { val childEventId = it val eventRepetitionException = EventRepetitionException(null, Formatter.getDayCodeFromTS(occurrenceTS), parentEventId) callback(eventRepetitionException) @@ -302,7 +302,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont events = events .asSequence() .distinct() - .filterNot { EventsHelper().getEventRepetitionIgnoredOccurrences(context, it).contains(Formatter.getDayCodeFromTS(it.startTS)) } + .filterNot { EventsHelper(context).getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) } .toMutableList() as ArrayList callback(events) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt index 2ba51bed3..66787a9c1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/EventsHelper.kt @@ -8,7 +8,7 @@ import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.calendar.pro.models.EventType import java.util.* -class EventsHelper { +class EventsHelper(val context: Context) { fun getEventTypes(activity: Activity, callback: (notes: ArrayList) -> Unit) { Thread { val eventTypes = activity.eventTypesDB.getEventTypes().toMutableList() as ArrayList @@ -18,18 +18,18 @@ class EventsHelper { }.start() } - fun getEventTypesSync(context: Context) = context.eventTypesDB.getEventTypes().toMutableList() as ArrayList + fun getEventTypesSync() = context.eventTypesDB.getEventTypes().toMutableList() as ArrayList fun insertOrUpdateEventType(activity: Activity, eventType: EventType, callback: ((newEventTypeId: Long) -> Unit)? = null) { Thread { - val eventTypeId = insertOrUpdateEventTypeSync(activity, eventType) + val eventTypeId = insertOrUpdateEventTypeSync(eventType) activity.runOnUiThread { callback?.invoke(eventTypeId) } }.start() } - fun insertOrUpdateEventTypeSync(context: Context, eventType: EventType): Long { + fun insertOrUpdateEventTypeSync(eventType: EventType): Long { if (eventType.id != null && eventType.id!! > 0 && eventType.caldavCalendarId != 0) { CalDAVHandler(context).updateCalDAVCalendar(eventType) } @@ -39,11 +39,11 @@ class EventsHelper { return newId } - fun getEventTypeIdWithTitle(context: Context, title: String) = context.eventTypesDB.getEventTypeIdWithTitle(title) ?: -1L + fun getEventTypeIdWithTitle(title: String) = context.eventTypesDB.getEventTypeIdWithTitle(title) ?: -1L - fun getEventTypeWithCalDAVCalendarId(context: Context, calendarId: Int) = context.eventTypesDB.getEventTypeWithCalDAVCalendarId(calendarId) + fun getEventTypeWithCalDAVCalendarId(calendarId: Int) = context.eventTypesDB.getEventTypeWithCalDAVCalendarId(calendarId) - fun deleteEventTypes(context: Context, eventTypes: ArrayList, deleteEvents: Boolean) { + fun deleteEventTypes(eventTypes: ArrayList, deleteEvents: Boolean) { val typesToDelete = eventTypes.asSequence().filter { it.caldavCalendarId == 0 && it.id != DBHelper.REGULAR_EVENT_TYPE_ID }.toMutableList() val deleteIds = typesToDelete.map { it.id }.toMutableList() val deletedSet = deleteIds.map { it.toString() }.toHashSet() @@ -64,7 +64,7 @@ class EventsHelper { context.eventTypesDB.deleteEventTypes(typesToDelete) } - fun getEventRepetitionIgnoredOccurrences(context: Context, event: Event): ArrayList { + fun getEventRepetitionIgnoredOccurrences(event: Event): ArrayList { return if (event.id == null || event.repeatInterval == 0) { ArrayList() } else { @@ -72,7 +72,7 @@ class EventsHelper { } } - fun insertEvent(context: Context, activity: SimpleActivity? = null, event: Event, addToCalDAV: Boolean, callback: ((id: Long) -> Unit)? = null) { + fun insertEvent(activity: SimpleActivity? = null, event: Event, addToCalDAV: Boolean, callback: ((id: Long) -> Unit)? = null) { if (event.startTS > event.endTS) { callback?.invoke(0) return @@ -95,31 +95,31 @@ class EventsHelper { callback?.invoke(event.id!!) } - fun insertEvents(activity: Activity, events: ArrayList, addToCalDAV: Boolean) { + fun insertEvents(events: ArrayList, addToCalDAV: Boolean) { try { for (event in events) { if (event.startTS > event.endTS) { continue } - val id = activity.eventsDB.insertOrUpdate(event) + val id = context.eventsDB.insertOrUpdate(event) event.id = id if (event.repeatInterval != 0 && event.parentId == 0L) { - activity.eventRepetitionsDB.insertOrUpdate(event.getEventRepetition()) + context.eventRepetitionsDB.insertOrUpdate(event.getEventRepetition()) } //context.scheduleNextEventReminder(event, this) - if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && activity.config.caldavSync) { - CalDAVHandler(activity).insertCalDAVEvent(event) + if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && context.config.caldavSync) { + CalDAVHandler(context).insertCalDAVEvent(event) } } } finally { - activity.updateWidgets() + context.updateWidgets() } } - fun updateEvent(context: Context, activity: Activity? = null, event: Event, updateAtCalDAV: Boolean, callback: (() -> Unit)? = null) { + fun updateEvent(activity: Activity? = null, event: Event, updateAtCalDAV: Boolean, callback: (() -> Unit)? = null) { context.eventsDB.insertOrUpdate(event) if (event.repeatInterval == 0) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt index e01d6ea80..ea354630f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsExporter.kt @@ -92,7 +92,7 @@ class IcsExporter { } private fun fillIgnoredOccurrences(activity: BaseSimpleActivity, event: Event, out: BufferedWriter) { - EventsHelper().getEventRepetitionIgnoredOccurrences(activity, event).forEach { + EventsHelper(activity).getEventRepetitionIgnoredOccurrences(event).forEach { out.writeLn("$EXDATE:$it") } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 14e889fdf..31043efc4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -41,7 +41,7 @@ class IcsImporter(val activity: SimpleActivity) { fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult { try { - val eventTypes = EventsHelper().getEventTypesSync(activity) + val eventTypes = EventsHelper(activity).getEventTypesSync() val existingEvents = activity.dbHelper.getEventsWithImportIds() val eventsToInsert = ArrayList() var prevLine = "" @@ -158,7 +158,7 @@ class IcsImporter(val activity: SimpleActivity) { if (curRepeatExceptions.isEmpty()) { eventsToInsert.add(event) } else { - EventsHelper().insertEvent(activity, activity, event, true) { + EventsHelper(activity).insertEvent(activity, event, true) { for (exceptionTS in curRepeatExceptions) { activity.dbHelper.addEventRepeatException(it, exceptionTS, true) } @@ -167,7 +167,7 @@ class IcsImporter(val activity: SimpleActivity) { } } else { event.id = eventToUpdate.id - EventsHelper().updateEvent(activity, null, event, true) + EventsHelper(activity).updateEvent(null, event, true) } eventsImported++ resetValues() @@ -176,7 +176,7 @@ class IcsImporter(val activity: SimpleActivity) { } } - EventsHelper().insertEvents(activity, eventsToInsert, true) + EventsHelper(activity).insertEvents(eventsToInsert, true) } catch (e: Exception) { activity.showErrorToast(e, Toast.LENGTH_LONG) eventsFailed++ @@ -223,11 +223,11 @@ class IcsImporter(val activity: SimpleActivity) { categories } - val eventId = EventsHelper().getEventTypeIdWithTitle(activity, eventTypeTitle) + val eventId = EventsHelper(activity).getEventTypeIdWithTitle(eventTypeTitle) curEventTypeId = if (eventId == -1L) { val newTypeColor = if (curCategoryColor == -2) activity.resources.getColor(R.color.color_primary) else curCategoryColor val eventType = EventType(null, eventTypeTitle, newTypeColor) - EventsHelper().insertOrUpdateEventTypeSync(activity, eventType) + EventsHelper(activity).insertOrUpdateEventTypeSync(eventType) } else { eventId } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/receivers/NotificationReceiver.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/receivers/NotificationReceiver.kt index 75ca6eaa2..39e0f542c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/receivers/NotificationReceiver.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/receivers/NotificationReceiver.kt @@ -35,7 +35,7 @@ class NotificationReceiver : BroadcastReceiver() { return } - if (!EventsHelper().getEventRepetitionIgnoredOccurrences(context, event).contains(Formatter.getDayCodeFromTS(event.startTS))) { + if (!EventsHelper(context).getEventRepetitionIgnoredOccurrences(event).contains(Formatter.getDayCodeFromTS(event.startTS))) { context.notifyEvent(event) } context.scheduleNextEventReminder(event, context.dbHelper)