mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
adding a helper context extension for getting some references
This commit is contained in:
@ -158,9 +158,9 @@ class EventActivity : SimpleActivity() {
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_event, menu)
|
||||
if (wasActivityInitialized) {
|
||||
menu.findItem(R.id.delete).isVisible = mEvent.id != 0L
|
||||
menu.findItem(R.id.share).isVisible = mEvent.id != 0L
|
||||
menu.findItem(R.id.duplicate).isVisible = mEvent.id != 0L
|
||||
menu.findItem(R.id.delete).isVisible = mEvent.id != null
|
||||
menu.findItem(R.id.share).isVisible = mEvent.id != null
|
||||
menu.findItem(R.id.duplicate).isVisible = mEvent.id != null
|
||||
}
|
||||
return true
|
||||
}
|
||||
@ -599,7 +599,7 @@ class EventActivity : SimpleActivity() {
|
||||
event_caldav_calendar_holder.beVisible()
|
||||
event_caldav_calendar_divider.beVisible()
|
||||
|
||||
val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(this).filter {
|
||||
val calendars = calDAVHelper.getCalDAVCalendars(this).filter {
|
||||
it.canWrite() && config.getSyncedCalendarIdsAsList().contains(it.id)
|
||||
}
|
||||
updateCurrentCalendarInfo(if (mEventCalendarId == STORED_LOCALLY_ONLY) null else getCalendarWithId(calendars, getCalendarId()))
|
||||
@ -648,7 +648,7 @@ class EventActivity : SimpleActivity() {
|
||||
event_caldav_calendar_email.text = currentCalendar.accountName
|
||||
|
||||
Thread {
|
||||
val calendarColor = EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color
|
||||
val calendarColor = eventsHelper.getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color
|
||||
?: currentCalendar.color
|
||||
|
||||
runOnUiThread {
|
||||
@ -680,9 +680,9 @@ class EventActivity : SimpleActivity() {
|
||||
DeleteEventDialog(this, arrayListOf(mEvent.id!!), mEvent.repeatInterval > 0) {
|
||||
Thread {
|
||||
when (it) {
|
||||
DELETE_SELECTED_OCCURRENCE -> EventsHelper(applicationContext).addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> EventsHelper(applicationContext).addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||
DELETE_ALL_OCCURRENCES -> EventsHelper(applicationContext).deleteEvent(mEvent.id!!, true)
|
||||
DELETE_SELECTED_OCCURRENCE -> eventsHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> eventsHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||
DELETE_ALL_OCCURRENCES -> eventsHelper.deleteEvent(mEvent.id!!, true)
|
||||
}
|
||||
runOnUiThread {
|
||||
finish()
|
||||
@ -727,12 +727,12 @@ class EventActivity : SimpleActivity() {
|
||||
|
||||
val wasRepeatable = mEvent.repeatInterval > 0
|
||||
val oldSource = mEvent.source
|
||||
val newImportId = if (mEvent.id != 0L) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
|
||||
val newImportId = if (mEvent.id != null) mEvent.importId else UUID.randomUUID().toString().replace("-", "") + System.currentTimeMillis().toString()
|
||||
|
||||
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||
mEventTypeId
|
||||
} else {
|
||||
EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId
|
||||
eventsHelper.getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId
|
||||
}
|
||||
|
||||
val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||
@ -775,8 +775,8 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
// recreate the event if it was moved in a different CalDAV calendar
|
||||
if (mEvent.id != 0L && oldSource != newSource) {
|
||||
EventsHelper(this).deleteEvent(mEvent.id!!, true)
|
||||
if (mEvent.id != null && oldSource != newSource) {
|
||||
eventsHelper.deleteEvent(mEvent.id!!, true)
|
||||
mEvent.id = null
|
||||
}
|
||||
|
||||
@ -784,8 +784,8 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun storeEvent(wasRepeatable: Boolean) {
|
||||
if (mEvent.id == 0L || mEvent.id == null) {
|
||||
EventsHelper(applicationContext).insertEvent(this, mEvent, true) {
|
||||
if (mEvent.id == null || mEvent.id == null) {
|
||||
eventsHelper.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(applicationContext).updateEvent(this, mEvent, true) {
|
||||
eventsHelper.updateEvent(this, mEvent, true) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
@ -811,13 +811,13 @@ class EventActivity : SimpleActivity() {
|
||||
EditRepeatingEventDialog(this) {
|
||||
if (it) {
|
||||
Thread {
|
||||
EventsHelper(applicationContext).updateEvent(this, mEvent, true) {
|
||||
eventsHelper.updateEvent(this, mEvent, true) {
|
||||
finish()
|
||||
}
|
||||
}.start()
|
||||
} else {
|
||||
Thread {
|
||||
EventsHelper(applicationContext).addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
eventsHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
mEvent.apply {
|
||||
parentId = id!!.toLong()
|
||||
id = null
|
||||
@ -826,7 +826,7 @@ class EventActivity : SimpleActivity() {
|
||||
repeatLimit = 0
|
||||
}
|
||||
|
||||
EventsHelper(applicationContext).insertEvent(this, mEvent, true) {
|
||||
eventsHelper.insertEvent(this, mEvent, true) {
|
||||
finish()
|
||||
}
|
||||
}.start()
|
||||
|
@ -112,7 +112,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
updateViewPager()
|
||||
}
|
||||
|
||||
EventsHelper(applicationContext).getEventTypes(this) {
|
||||
eventsHelper.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(applicationContext).getEventTypeIdWithTitle(holidays)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(holidays)
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color))
|
||||
eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||
eventTypeId = eventsHelper.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(applicationContext).insertEvent(null, event, false) {
|
||||
eventsHelper.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(applicationContext).getEventTypeIdWithTitle(birthdays)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(birthdays)
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(null, birthdays, resources.getColor(R.color.default_birthdays_color))
|
||||
eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||
eventTypeId = eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
}
|
||||
return eventTypeId
|
||||
}
|
||||
|
||||
private fun getAnniversariesEventTypeId(): Long {
|
||||
val anniversaries = getString(R.string.anniversaries)
|
||||
var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(anniversaries)
|
||||
var eventTypeId = eventsHelper.getEventTypeIdWithTitle(anniversaries)
|
||||
if (eventTypeId == -1L) {
|
||||
val eventType = EventType(null, anniversaries, resources.getColor(R.color.default_anniversaries_color))
|
||||
eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||
eventTypeId = eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
}
|
||||
return eventTypeId
|
||||
}
|
||||
@ -738,7 +738,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||
mLatestSearchQuery = text
|
||||
search_placeholder_2.beGoneIf(text.length >= 2)
|
||||
if (text.length >= 2) {
|
||||
EventsHelper(applicationContext).getEventsWithSearchQuery(text, this) { searchedText, events ->
|
||||
eventsHelper.getEventsWithSearchQuery(text, this) { searchedText, events ->
|
||||
if (searchedText == mLatestSearchQuery) {
|
||||
search_results_list.beVisibleIf(events.isNotEmpty())
|
||||
search_placeholder.beVisibleIf(events.isEmpty())
|
||||
|
@ -6,7 +6,7 @@ import android.view.MenuItem
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.adapters.ManageEventTypesAdapter
|
||||
import com.simplemobiletools.calendar.pro.dialogs.EditEventTypeDialog
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
@ -30,7 +30,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||
}
|
||||
|
||||
private fun getEventTypes() {
|
||||
EventsHelper(applicationContext).getEventTypes(this) {
|
||||
eventsHelper.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(applicationContext).deleteEventTypes(eventTypes, deleteEvents)
|
||||
eventsHelper.deleteEventTypes(eventTypes, deleteEvents)
|
||||
}.start()
|
||||
return true
|
||||
}
|
||||
|
@ -6,10 +6,7 @@ import android.media.AudioManager
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.dialogs.SelectCalendarsDialog
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.getSyncedCalDAVCalendars
|
||||
import com.simplemobiletools.calendar.pro.extensions.updateWidgets
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
@ -92,11 +89,11 @@ class SettingsActivity : SimpleActivity() {
|
||||
private fun checkPrimaryColor() {
|
||||
if (config.primaryColor != mStoredPrimaryColor) {
|
||||
Thread {
|
||||
val eventTypes = EventsHelper(applicationContext).getEventTypesSync()
|
||||
val eventTypes = eventsHelper.getEventTypesSync()
|
||||
if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) {
|
||||
val eventType = eventTypes.first { it.caldavCalendarId == 0 }
|
||||
eventType.color = config.primaryColor
|
||||
EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||
eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
@ -185,7 +182,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
|
||||
Thread {
|
||||
config.getSyncedCalendarIdsAsList().forEach {
|
||||
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
|
||||
calDAVHelper.deleteCalDAVCalendarEvents(it.toLong())
|
||||
}
|
||||
eventTypesDB.deleteEventTypesWithCalendarId(config.getSyncedCalendarIdsAsList())
|
||||
}.start()
|
||||
@ -211,23 +208,23 @@ class SettingsActivity : SimpleActivity() {
|
||||
|
||||
Thread {
|
||||
if (newCalendarIds.isNotEmpty()) {
|
||||
val existingEventTypeNames = EventsHelper(applicationContext).getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||
val existingEventTypeNames = eventsHelper.getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||
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(applicationContext).insertOrUpdateEventType(this, eventType)
|
||||
eventsHelper.insertOrUpdateEventType(this, eventType)
|
||||
}
|
||||
}
|
||||
CalDAVHandler(applicationContext).refreshCalendars(this) {}
|
||||
calDAVHelper.refreshCalendars(this) {}
|
||||
}
|
||||
|
||||
val removedCalendarIds = oldCalendarIds.filter { !newCalendarIds.contains(it) }
|
||||
removedCalendarIds.forEach {
|
||||
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
|
||||
EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(it)?.apply {
|
||||
EventsHelper(applicationContext).deleteEventTypes(arrayListOf(this), true)
|
||||
calDAVHelper.deleteCalDAVCalendarEvents(it.toLong())
|
||||
eventsHelper.getEventTypeWithCalDAVCalendarId(it)?.apply {
|
||||
eventsHelper.deleteEventTypes(arrayListOf(this), true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -250,9 +247,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
private fun setupDeleteAllEvents() {
|
||||
settings_delete_all_events_holder.setOnClickListener {
|
||||
ConfirmationDialog(this, messageId = R.string.delete_all_events_confirmation) {
|
||||
Thread {
|
||||
EventsHelper(applicationContext).deleteAllEvents()
|
||||
}.start()
|
||||
eventsHelper.deleteAllEvents()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,13 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.dialogs.DeleteEventDialog
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting
|
||||
import com.simplemobiletools.calendar.pro.extensions.shareEvents
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.pro.helpers.ITEM_EVENT
|
||||
import com.simplemobiletools.calendar.pro.helpers.ITEM_EVENT_SIMPLE
|
||||
import com.simplemobiletools.calendar.pro.helpers.LOW_ALPHA
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
|
||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||
@ -140,7 +144,7 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
||||
|
||||
Thread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.mapNotNull { it.id }.toMutableList()
|
||||
EventsHelper(activity).deleteEvents(nonRepeatingEventIDs, true)
|
||||
activity.eventsHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.mapNotNull { it.id }.toList()
|
||||
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
||||
|
@ -7,6 +7,7 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.dialogs.DeleteEventDialog
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.handleEventDeleting
|
||||
import com.simplemobiletools.calendar.pro.extensions.shareEvents
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
@ -207,7 +208,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
|
||||
|
||||
Thread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.mapNotNull { it.id }.toMutableList()
|
||||
EventsHelper(activity).deleteEvents(nonRepeatingEventIDs, true)
|
||||
activity.eventsHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
val repeatingEventIDs = eventsToDelete.filter { it.isRepeatable }.map { it.id }
|
||||
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
||||
|
@ -6,7 +6,7 @@ import android.view.ViewGroup
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
||||
import com.simplemobiletools.calendar.pro.interfaces.DeleteEventTypesListener
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
@ -73,7 +73,7 @@ class ManageEventTypesAdapter(activity: SimpleActivity, val eventTypes: ArrayLis
|
||||
private fun askConfirmDelete() {
|
||||
val eventTypes = eventTypes.filter { selectedKeys.contains(it.id?.toInt()) }.map { it.id } as ArrayList<Long>
|
||||
|
||||
EventsHelper(activity).doEventTypesContainEvents(eventTypes) {
|
||||
activity.eventsHelper.doEventTypesContainEvents(eventTypes) {
|
||||
activity.runOnUiThread {
|
||||
if (it) {
|
||||
val MOVE_EVENTS = 0
|
||||
|
@ -5,7 +5,7 @@ import android.widget.ImageView
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
@ -58,7 +58,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
||||
}
|
||||
|
||||
private fun eventTypeConfirmed(title: String, dialog: AlertDialog) {
|
||||
val eventIdWithTitle = EventsHelper(activity).getEventTypeIdWithTitle(title)
|
||||
val eventIdWithTitle = activity.eventsHelper.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(activity).insertOrUpdateEventTypeSync(eventType!!)
|
||||
eventType!!.id = activity.eventsHelper.insertOrUpdateEventTypeSync(eventType!!)
|
||||
|
||||
if (eventType!!.id != -1L) {
|
||||
activity.runOnUiThread {
|
||||
|
@ -6,7 +6,7 @@ import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import kotlinx.android.synthetic.main.dialog_export_events.view.*
|
||||
import java.io.File
|
||||
@ -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(activity).getEventTypes(activity) {
|
||||
activity.eventsHelper.getEventTypes(activity) {
|
||||
val eventTypes = HashSet<String>()
|
||||
it.mapTo(eventTypes) { it.id.toString() }
|
||||
|
||||
|
@ -5,7 +5,7 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.adapters.FilterEventTypeAdapter
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import kotlinx.android.synthetic.main.dialog_filter_event_types.view.*
|
||||
|
||||
@ -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(activity).getEventTypes(activity) {
|
||||
activity.eventsHelper.getEventTypes(activity) {
|
||||
val displayEventTypes = activity.config.displayEventTypes
|
||||
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
||||
|
||||
|
@ -6,7 +6,7 @@ import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.IcsImporter
|
||||
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.REGULAR_EVENT_TYPE_ID
|
||||
@ -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(activity).getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)
|
||||
val lastUsedCalDAVCalendar = activity.eventsHelper.getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)
|
||||
if (lastUsedCalDAVCalendar != null) {
|
||||
currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId
|
||||
lastUsedCalDAVCalendar.id!!
|
||||
|
@ -7,8 +7,8 @@ import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.calDAVHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.CalDAVHandler
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import kotlinx.android.synthetic.main.calendar_item_account.view.*
|
||||
import kotlinx.android.synthetic.main.calendar_item_calendar.view.*
|
||||
@ -21,7 +21,7 @@ class SelectCalendarsDialog(val activity: SimpleActivity, val callback: () -> Un
|
||||
|
||||
init {
|
||||
val ids = activity.config.getSyncedCalendarIdsAsList()
|
||||
val calendars = CalDAVHandler(activity.applicationContext).getCalDAVCalendars(activity)
|
||||
val calendars = activity.calDAVHelper.getCalDAVCalendars(activity)
|
||||
val sorted = calendars.sortedWith(compareBy({ it.accountName }, { it.displayName }))
|
||||
sorted.forEach {
|
||||
if (prevAccount != it.accountName) {
|
||||
|
@ -8,7 +8,7 @@ import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.STORED_LOCALLY_ONLY
|
||||
import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
@ -28,7 +28,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
||||
|
||||
Thread {
|
||||
calendars.forEach {
|
||||
val localEventType = EventsHelper(activity).getEventTypeWithCalDAVCalendarId(it.id)
|
||||
val localEventType = activity.eventsHelper.getEventTypeWithCalDAVCalendarId(it.id)
|
||||
if (localEventType != null) {
|
||||
it.color = localEventType.color
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.calDAVHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.CalDAVHandler
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
@ -19,7 +19,7 @@ class SelectEventTypeColorDialog(val activity: Activity, val eventType: EventTyp
|
||||
private val dialog: AlertDialog?
|
||||
private val radioGroup: RadioGroup
|
||||
private var wasInit = false
|
||||
private val colors = CalDAVHandler(activity.applicationContext).getAvailableCalDAVCalendarColors(eventType)
|
||||
private val colors = activity.calDAVHelper.getAvailableCalDAVCalendarColors(eventType)
|
||||
|
||||
init {
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_event_type_color, null) as ViewGroup
|
||||
|
@ -7,7 +7,7 @@ import android.widget.RadioGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.setFillWithStroke
|
||||
@ -31,7 +31,7 @@ class SelectEventTypeDialog(val activity: Activity, val currEventType: Long, val
|
||||
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
||||
radioGroup = view.dialog_radio_group
|
||||
|
||||
EventsHelper(activity).getEventTypes(activity) {
|
||||
activity.eventsHelper.getEventTypes(activity) {
|
||||
eventTypes = it
|
||||
activity.runOnUiThread {
|
||||
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
||||
|
@ -47,15 +47,12 @@ import org.joda.time.LocalDate
|
||||
import java.util.*
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
|
||||
val Context.eventsDB: EventsDao get() = EventsDatabase.getInstance(applicationContext).EventsDao()
|
||||
|
||||
val Context.eventTypesDB: EventTypesDao get() = EventsDatabase.getInstance(applicationContext).EventTypesDao()
|
||||
|
||||
val Context.eventRepetitionsDB: EventRepetitionsDao get() = EventsDatabase.getInstance(applicationContext).EventRepetitionsDao()
|
||||
|
||||
val Context.eventRepetitionExceptionsDB: EventRepetitionExceptionsDao get() = EventsDatabase.getInstance(applicationContext).EventRepetitionExceptionsDao()
|
||||
|
||||
val Context.eventsHelper: EventsHelper get() = EventsHelper(this)
|
||||
val Context.calDAVHelper: CalDAVHelper get() = CalDAVHelper(this)
|
||||
val Context.dbHelper: DBHelper get() = DBHelper.newInstance(applicationContext)
|
||||
|
||||
fun Context.updateWidgets() {
|
||||
@ -311,12 +308,12 @@ fun Context.getNewEventTimestampFromCode(dayCode: String): Int {
|
||||
return newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
|
||||
}
|
||||
|
||||
fun Context.getSyncedCalDAVCalendars() = CalDAVHandler(applicationContext).getCalDAVCalendars(null, config.caldavSyncedCalendarIDs)
|
||||
fun Context.getSyncedCalDAVCalendars() = calDAVHelper.getCalDAVCalendars(null, config.caldavSyncedCalendarIDs)
|
||||
|
||||
fun Context.recheckCalDAVCalendars(callback: () -> Unit) {
|
||||
if (config.caldavSync) {
|
||||
Thread {
|
||||
CalDAVHandler(applicationContext).refreshCalendars(null, callback)
|
||||
calDAVHelper.refreshCalendars(null, callback)
|
||||
updateWidgets()
|
||||
}.start()
|
||||
}
|
||||
@ -350,7 +347,7 @@ fun Context.syncCalDAVCalendars(activity: SimpleActivity?, calDAVSyncObserver: C
|
||||
fun Context.refreshCalDAVCalendars(activity: SimpleActivity?, ids: String) {
|
||||
val uri = CalendarContract.Calendars.CONTENT_URI
|
||||
val accounts = HashSet<Account>()
|
||||
val calendars = CalDAVHandler(applicationContext).getCalDAVCalendars(activity, ids)
|
||||
val calendars = calDAVHelper.getCalDAVCalendars(activity, ids)
|
||||
calendars.forEach {
|
||||
accounts.add(Account(it.accountName, it.accountType))
|
||||
}
|
||||
@ -448,16 +445,16 @@ fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Int>, act
|
||||
when (action) {
|
||||
DELETE_SELECTED_OCCURRENCE -> {
|
||||
eventIds.forEachIndexed { index, value ->
|
||||
EventsHelper(this).addEventRepeatException(value, timestamps[index], true)
|
||||
eventsHelper.addEventRepeatException(value, timestamps[index], true)
|
||||
}
|
||||
}
|
||||
DELETE_FUTURE_OCCURRENCES -> {
|
||||
eventIds.forEachIndexed { index, value ->
|
||||
EventsHelper(this).addEventRepeatLimit(value, timestamps[index])
|
||||
eventsHelper.addEventRepeatLimit(value, timestamps[index])
|
||||
}
|
||||
}
|
||||
DELETE_ALL_OCCURRENCES -> {
|
||||
EventsHelper(this).deleteEvents(eventIds.toMutableList(), true)
|
||||
eventsHelper.deleteEvents(eventIds.toMutableList(), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import androidx.fragment.app.Fragment
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.EventActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.extensions.seconds
|
||||
import com.simplemobiletools.calendar.pro.helpers.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
@ -66,7 +67,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
EventsHelper(activity!!).getEventTypes(activity!!) {
|
||||
context!!.eventsHelper.getEventTypes(activity!!) {
|
||||
it.map { eventTypeColors.put(it.id!!, it.color) }
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,7 @@ import android.provider.CalendarContract
|
||||
import android.provider.CalendarContract.Reminders
|
||||
import android.util.SparseIntArray
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.config
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.refreshCalDAVCalendars
|
||||
import com.simplemobiletools.calendar.pro.extensions.scheduleCalDAVSync
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.models.CalDAVCalendar
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
@ -22,19 +19,21 @@ import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class CalDAVHandler(val context: Context) {
|
||||
class CalDAVHelper(val context: Context) {
|
||||
private val eventsHelper = context.eventsHelper
|
||||
|
||||
fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) {
|
||||
val calDAVCalendars = getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs)
|
||||
for (calendar in calDAVCalendars) {
|
||||
val localEventType = EventsHelper(context).getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue
|
||||
val localEventType = eventsHelper.getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue
|
||||
localEventType.apply {
|
||||
title = calendar.displayName
|
||||
caldavDisplayName = calendar.displayName
|
||||
caldavEmail = calendar.accountName
|
||||
EventsHelper(context).insertOrUpdateEventTypeSync(this)
|
||||
eventsHelper.insertOrUpdateEventTypeSync(this)
|
||||
}
|
||||
|
||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity)
|
||||
fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity)
|
||||
}
|
||||
context.scheduleCalDAVSync(true)
|
||||
callback()
|
||||
@ -226,7 +225,7 @@ class CalDAVHandler(val context: Context) {
|
||||
|
||||
if (existingEvent.hashCode() != event.hashCode() && title.isNotEmpty()) {
|
||||
event.id = originalEventId
|
||||
EventsHelper(context).updateEvent(null, event, false)
|
||||
eventsHelper.updateEvent(null, event, false)
|
||||
}
|
||||
} else {
|
||||
// if the event is an exception from another events repeat rule, find the original parent event
|
||||
@ -235,13 +234,13 @@ class CalDAVHandler(val context: Context) {
|
||||
val parentEventId = context.eventsDB.getEventIdWithImportId(parentImportId)
|
||||
if (parentEventId != null) {
|
||||
event.parentId = parentEventId
|
||||
EventsHelper(context).addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId)
|
||||
eventsHelper.addEventRepeatException(parentEventId, (originalInstanceTime / 1000).toInt(), false, event.importId)
|
||||
}
|
||||
}
|
||||
|
||||
if (title.isNotEmpty()) {
|
||||
importIdsMap[event.importId] = event
|
||||
EventsHelper(context).insertEvent(null, event, false)
|
||||
eventsHelper.insertEvent(null, event, false)
|
||||
}
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
@ -262,7 +261,7 @@ class CalDAVHandler(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
EventsHelper(context).deleteEvents(eventIdsToDelete.toMutableList(), false)
|
||||
eventsHelper.deleteEvents(eventIdsToDelete.toMutableList(), false)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@ -360,7 +359,7 @@ class CalDAVHandler(val context: Context) {
|
||||
|
||||
fun deleteCalDAVCalendarEvents(calendarId: Long) {
|
||||
val eventIds = context.eventsDB.getCalDAVCalendarEvents("$CALDAV-$calendarId").toMutableList()
|
||||
EventsHelper(context).deleteEvents(eventIds, false)
|
||||
eventsHelper.deleteEvents(eventIds, false)
|
||||
}
|
||||
|
||||
fun deleteCalDAVEvent(event: Event) {
|
@ -92,7 +92,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
events = events
|
||||
.asSequence()
|
||||
.distinct()
|
||||
.filterNot { EventsHelper(context).getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
||||
.filterNot { context.eventsHelper.getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
||||
.toMutableList() as ArrayList<Event>
|
||||
callback(events)
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ class EventsHelper(val context: Context) {
|
||||
|
||||
fun insertOrUpdateEventTypeSync(eventType: EventType): Long {
|
||||
if (eventType.id != null && eventType.id!! > 0 && eventType.caldavCalendarId != 0) {
|
||||
CalDAVHandler(context).updateCalDAVCalendar(eventType)
|
||||
context.calDAVHelper.updateCalDAVCalendar(eventType)
|
||||
}
|
||||
|
||||
val newId = eventTypesDB.insertOrUpdate(eventType)
|
||||
@ -95,7 +95,7 @@ class EventsHelper(val context: Context) {
|
||||
//context.scheduleNextEventReminder(event, this, activity)
|
||||
|
||||
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {
|
||||
CalDAVHandler(context).insertCalDAVEvent(event)
|
||||
context.calDAVHelper.insertCalDAVEvent(event)
|
||||
}
|
||||
|
||||
callback?.invoke(event.id!!)
|
||||
@ -117,7 +117,7 @@ class EventsHelper(val context: Context) {
|
||||
|
||||
//context.scheduleNextEventReminder(event, this)
|
||||
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && config.caldavSync) {
|
||||
CalDAVHandler(context).insertCalDAVEvent(event)
|
||||
context.calDAVHelper.insertCalDAVEvent(event)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
@ -137,14 +137,16 @@ class EventsHelper(val context: Context) {
|
||||
context.updateWidgets()
|
||||
//context.scheduleNextEventReminder(event, this, activity)
|
||||
if (updateAtCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && config.caldavSync) {
|
||||
CalDAVHandler(context).updateCalDAVEvent(event)
|
||||
context.calDAVHelper.updateCalDAVEvent(event)
|
||||
}
|
||||
callback?.invoke()
|
||||
}
|
||||
|
||||
fun deleteAllEvents() {
|
||||
Thread {
|
||||
val eventIds = eventsDB.getEventIds().toMutableList()
|
||||
deleteEvents(eventIds, true)
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun deleteEvent(id: Long, deleteFromCalDAV: Boolean) = deleteEvents(arrayListOf(id), deleteFromCalDAV)
|
||||
@ -159,7 +161,7 @@ class EventsHelper(val context: Context) {
|
||||
|
||||
if (deleteFromCalDAV && config.caldavSync) {
|
||||
eventsWithImportId.forEach {
|
||||
CalDAVHandler(context).deleteCalDAVEvent(it)
|
||||
context.calDAVHelper.deleteCalDAVEvent(it)
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +188,7 @@ class EventsHelper(val context: Context) {
|
||||
if (config.caldavSync) {
|
||||
val event = eventsDB.getEventWithId(eventId)
|
||||
if (event?.getCalDAVCalendarId() != 0) {
|
||||
CalDAVHandler(context).updateCalDAVEvent(event!!)
|
||||
context.calDAVHelper.updateCalDAVEvent(event!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -211,7 +213,7 @@ class EventsHelper(val context: Context) {
|
||||
}
|
||||
|
||||
fun addEventRepeatException(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String? = null) {
|
||||
EventsHelper(context).fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
|
||||
fillExceptionValues(parentEventId, occurrenceTS, addToCalDAV, childImportId) {
|
||||
context.eventRepetitionExceptionsDB.insert(it)
|
||||
|
||||
val parentEvent = eventsDB.getEventWithId(parentEventId)
|
||||
@ -221,7 +223,7 @@ class EventsHelper(val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun fillExceptionValues(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (eventRepetitionException: EventRepetitionException) -> Unit) {
|
||||
private fun fillExceptionValues(parentEventId: Long, occurrenceTS: Int, addToCalDAV: Boolean, childImportId: String?, callback: (eventRepetitionException: EventRepetitionException) -> Unit) {
|
||||
val childEvent = eventsDB.getEventWithId(parentEventId) ?: return
|
||||
|
||||
childEvent.apply {
|
||||
@ -243,7 +245,7 @@ class EventsHelper(val context: Context) {
|
||||
if (addToCalDAV && config.caldavSync) {
|
||||
val parentEvent = eventsDB.getEventWithId(parentEventId)
|
||||
if (parentEvent != null) {
|
||||
val newId = CalDAVHandler(context).insertEventRepeatException(parentEvent, occurrenceTS)
|
||||
val newId = context.calDAVHelper.insertEventRepeatException(parentEvent, occurrenceTS)
|
||||
val newImportId = "${parentEvent.source}-$newId"
|
||||
eventsDB.updateEventImportIdAndSource(newImportId, parentEvent.source, childEventId)
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.pro.helpers
|
||||
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventTypesDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.IcsExporter.ExportResult.*
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
@ -92,7 +93,7 @@ class IcsExporter {
|
||||
}
|
||||
|
||||
private fun fillIgnoredOccurrences(activity: BaseSimpleActivity, event: Event, out: BufferedWriter) {
|
||||
EventsHelper(activity).getEventRepetitionIgnoredOccurrences(event).forEach {
|
||||
activity.eventsHelper.getEventRepetitionIgnoredOccurrences(event).forEach {
|
||||
out.writeLn("$EXDATE:$it")
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.widget.Toast
|
||||
import com.simplemobiletools.calendar.pro.R
|
||||
import com.simplemobiletools.calendar.pro.activities.SimpleActivity
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsDB
|
||||
import com.simplemobiletools.calendar.pro.extensions.eventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.IcsImporter.ImportResult.*
|
||||
import com.simplemobiletools.calendar.pro.models.Event
|
||||
import com.simplemobiletools.calendar.pro.models.EventType
|
||||
@ -35,13 +36,14 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
private var isProperReminderAction = false
|
||||
private var isDescription = false
|
||||
private var curReminderTriggerMinutes = -1
|
||||
private val eventsHelper = activity.eventsHelper
|
||||
|
||||
private var eventsImported = 0
|
||||
private var eventsFailed = 0
|
||||
|
||||
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||
try {
|
||||
val eventTypes = EventsHelper(activity).getEventTypesSync()
|
||||
val eventTypes = eventsHelper.getEventTypesSync()
|
||||
val existingEvents = activity.eventsDB.getEventsWithImportIds().toMutableList() as ArrayList<Event>
|
||||
val eventsToInsert = ArrayList<Event>()
|
||||
var prevLine = ""
|
||||
@ -158,16 +160,16 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
if (curRepeatExceptions.isEmpty()) {
|
||||
eventsToInsert.add(event)
|
||||
} else {
|
||||
EventsHelper(activity).insertEvent(activity, event, true) {
|
||||
eventsHelper.insertEvent(activity, event, true) {
|
||||
for (exceptionTS in curRepeatExceptions) {
|
||||
EventsHelper(activity).addEventRepeatException(it, exceptionTS, true)
|
||||
eventsHelper.addEventRepeatException(it, exceptionTS, true)
|
||||
}
|
||||
existingEvents.add(event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
event.id = eventToUpdate.id
|
||||
EventsHelper(activity).updateEvent(null, event, true)
|
||||
eventsHelper.updateEvent(null, event, true)
|
||||
}
|
||||
eventsImported++
|
||||
resetValues()
|
||||
@ -176,7 +178,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
}
|
||||
}
|
||||
|
||||
EventsHelper(activity).insertEvents(eventsToInsert, true)
|
||||
eventsHelper.insertEvents(eventsToInsert, true)
|
||||
} catch (e: Exception) {
|
||||
activity.showErrorToast(e, Toast.LENGTH_LONG)
|
||||
eventsFailed++
|
||||
@ -223,11 +225,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||
categories
|
||||
}
|
||||
|
||||
val eventId = EventsHelper(activity).getEventTypeIdWithTitle(eventTypeTitle)
|
||||
val eventId = eventsHelper.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(activity).insertOrUpdateEventTypeSync(eventType)
|
||||
eventsHelper.insertOrUpdateEventTypeSync(eventType)
|
||||
} else {
|
||||
eventId
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import android.content.Intent
|
||||
import android.os.PowerManager
|
||||
import com.simplemobiletools.calendar.pro.extensions.*
|
||||
import com.simplemobiletools.calendar.pro.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.pro.helpers.EventsHelper
|
||||
import com.simplemobiletools.calendar.pro.helpers.Formatter
|
||||
|
||||
class NotificationReceiver : BroadcastReceiver() {
|
||||
@ -32,7 +31,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
return
|
||||
}
|
||||
|
||||
if (!EventsHelper(context).getEventRepetitionIgnoredOccurrences(event).contains(Formatter.getDayCodeFromTS(event.startTS))) {
|
||||
if (!context.eventsHelper.getEventRepetitionIgnoredOccurrences(event).contains(Formatter.getDayCodeFromTS(event.startTS))) {
|
||||
context.notifyEvent(event)
|
||||
}
|
||||
context.scheduleNextEventReminder(event, context.dbHelper)
|
||||
|
Reference in New Issue
Block a user