require Context at EventsHelper constructor
This commit is contained in:
parent
8cbbc2effe
commit
ec40b5954c
|
@ -648,7 +648,7 @@ class EventActivity : SimpleActivity() {
|
||||||
event_caldav_calendar_email.text = currentCalendar.accountName
|
event_caldav_calendar_email.text = currentCalendar.accountName
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
val calendarColor = EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, currentCalendar.id)?.color
|
val calendarColor = EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(currentCalendar.id)?.color
|
||||||
?: currentCalendar.color
|
?: currentCalendar.color
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
|
@ -732,7 +732,7 @@ class EventActivity : SimpleActivity() {
|
||||||
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
val newEventType = if (!config.caldavSync || config.lastUsedCaldavCalendarId == 0 || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||||
mEventTypeId
|
mEventTypeId
|
||||||
} else {
|
} else {
|
||||||
EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId
|
EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(mEventCalendarId)?.id ?: config.lastUsedLocalEventTypeId
|
||||||
}
|
}
|
||||||
|
|
||||||
val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
val newSource = if (!config.caldavSync || mEventCalendarId == STORED_LOCALLY_ONLY) {
|
||||||
|
@ -785,7 +785,7 @@ class EventActivity : SimpleActivity() {
|
||||||
|
|
||||||
private fun storeEvent(wasRepeatable: Boolean) {
|
private fun storeEvent(wasRepeatable: Boolean) {
|
||||||
if (mEvent.id == 0L || mEvent.id == null) {
|
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 (DateTime.now().isAfter(mEventStartDateTime.millis)) {
|
||||||
if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) {
|
if (mEvent.repeatInterval == 0 && mEvent.getReminders().isNotEmpty()) {
|
||||||
notifyEvent(mEvent)
|
notifyEvent(mEvent)
|
||||||
|
@ -800,7 +800,7 @@ class EventActivity : SimpleActivity() {
|
||||||
showEditRepeatingEventDialog()
|
showEditRepeatingEventDialog()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
EventsHelper().updateEvent(applicationContext, this, mEvent, true) {
|
EventsHelper(applicationContext).updateEvent(this, mEvent, true) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,7 +811,7 @@ class EventActivity : SimpleActivity() {
|
||||||
EditRepeatingEventDialog(this) {
|
EditRepeatingEventDialog(this) {
|
||||||
if (it) {
|
if (it) {
|
||||||
Thread {
|
Thread {
|
||||||
EventsHelper().updateEvent(applicationContext, this, mEvent, true) {
|
EventsHelper(applicationContext).updateEvent(this, mEvent, true) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
@ -826,7 +826,7 @@ class EventActivity : SimpleActivity() {
|
||||||
repeatLimit = 0
|
repeatLimit = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
EventsHelper().insertEvent(applicationContext, this, mEvent, true) {
|
EventsHelper(applicationContext).insertEvent(this, mEvent, true) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
|
|
@ -112,7 +112,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
updateViewPager()
|
updateViewPager()
|
||||||
}
|
}
|
||||||
|
|
||||||
EventsHelper().getEventTypes(this) {
|
EventsHelper(applicationContext).getEventTypes(this) {
|
||||||
val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
val newShouldFilterBeVisible = it.size > 1 || config.displayEventTypes.isEmpty()
|
||||||
if (newShouldFilterBeVisible != mShouldFilterBeVisible) {
|
if (newShouldFilterBeVisible != mShouldFilterBeVisible) {
|
||||||
mShouldFilterBeVisible = newShouldFilterBeVisible
|
mShouldFilterBeVisible = newShouldFilterBeVisible
|
||||||
|
@ -402,10 +402,10 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
toast(R.string.importing)
|
toast(R.string.importing)
|
||||||
Thread {
|
Thread {
|
||||||
val holidays = getString(R.string.holidays)
|
val holidays = getString(R.string.holidays)
|
||||||
var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, holidays)
|
var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(holidays)
|
||||||
if (eventTypeId == -1L) {
|
if (eventTypeId == -1L) {
|
||||||
val eventType = EventType(null, holidays, resources.getColor(R.color.default_holidays_color))
|
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)
|
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)
|
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
|
||||||
|
|
||||||
if (!importIDs.contains(contactId)) {
|
if (!importIDs.contains(contactId)) {
|
||||||
EventsHelper().insertEvent(applicationContext, null, event, false) {
|
EventsHelper(applicationContext).insertEvent(null, event, false) {
|
||||||
eventsAdded++
|
eventsAdded++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,20 +528,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
||||||
|
|
||||||
private fun getBirthdaysEventTypeId(): Long {
|
private fun getBirthdaysEventTypeId(): Long {
|
||||||
val birthdays = getString(R.string.birthdays)
|
val birthdays = getString(R.string.birthdays)
|
||||||
var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, birthdays)
|
var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(birthdays)
|
||||||
if (eventTypeId == -1L) {
|
if (eventTypeId == -1L) {
|
||||||
val eventType = EventType(null, birthdays, resources.getColor(R.color.default_birthdays_color))
|
val eventType = EventType(null, birthdays, resources.getColor(R.color.default_birthdays_color))
|
||||||
eventTypeId = EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType)
|
eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||||
}
|
}
|
||||||
return eventTypeId
|
return eventTypeId
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getAnniversariesEventTypeId(): Long {
|
private fun getAnniversariesEventTypeId(): Long {
|
||||||
val anniversaries = getString(R.string.anniversaries)
|
val anniversaries = getString(R.string.anniversaries)
|
||||||
var eventTypeId = EventsHelper().getEventTypeIdWithTitle(applicationContext, anniversaries)
|
var eventTypeId = EventsHelper(applicationContext).getEventTypeIdWithTitle(anniversaries)
|
||||||
if (eventTypeId == -1L) {
|
if (eventTypeId == -1L) {
|
||||||
val eventType = EventType(null, anniversaries, resources.getColor(R.color.default_anniversaries_color))
|
val eventType = EventType(null, anniversaries, resources.getColor(R.color.default_anniversaries_color))
|
||||||
eventTypeId = EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType)
|
eventTypeId = EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||||
}
|
}
|
||||||
return eventTypeId
|
return eventTypeId
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getEventTypes() {
|
private fun getEventTypes() {
|
||||||
EventsHelper().getEventTypes(this) {
|
EventsHelper(applicationContext).getEventTypes(this) {
|
||||||
val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) {
|
val adapter = ManageEventTypesAdapter(this, it, this, manage_event_types_list) {
|
||||||
showEventTypeDialog(it as EventType)
|
showEventTypeDialog(it as EventType)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class ManageEventTypesActivity : SimpleActivity(), DeleteEventTypesListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
EventsHelper().deleteEventTypes(applicationContext, eventTypes, deleteEvents)
|
EventsHelper(applicationContext).deleteEventTypes(eventTypes, deleteEvents)
|
||||||
}.start()
|
}.start()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,11 +89,11 @@ class SettingsActivity : SimpleActivity() {
|
||||||
private fun checkPrimaryColor() {
|
private fun checkPrimaryColor() {
|
||||||
if (config.primaryColor != mStoredPrimaryColor) {
|
if (config.primaryColor != mStoredPrimaryColor) {
|
||||||
Thread {
|
Thread {
|
||||||
val eventTypes = EventsHelper().getEventTypesSync(this)
|
val eventTypes = EventsHelper(applicationContext).getEventTypesSync()
|
||||||
if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) {
|
if (eventTypes.filter { it.caldavCalendarId == 0 }.size == 1) {
|
||||||
val eventType = eventTypes.first { it.caldavCalendarId == 0 }
|
val eventType = eventTypes.first { it.caldavCalendarId == 0 }
|
||||||
eventType.color = config.primaryColor
|
eventType.color = config.primaryColor
|
||||||
EventsHelper().insertOrUpdateEventTypeSync(applicationContext, eventType)
|
EventsHelper(applicationContext).insertOrUpdateEventTypeSync(eventType)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
@ -208,13 +208,13 @@ class SettingsActivity : SimpleActivity() {
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
if (newCalendarIds.isNotEmpty()) {
|
if (newCalendarIds.isNotEmpty()) {
|
||||||
val existingEventTypeNames = EventsHelper().getEventTypesSync(applicationContext).map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
val existingEventTypeNames = EventsHelper(applicationContext).getEventTypesSync().map { it.getDisplayTitle().toLowerCase() } as ArrayList<String>
|
||||||
getSyncedCalDAVCalendars().forEach {
|
getSyncedCalDAVCalendars().forEach {
|
||||||
val calendarTitle = it.getFullTitle()
|
val calendarTitle = it.getFullTitle()
|
||||||
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
|
if (!existingEventTypeNames.contains(calendarTitle.toLowerCase())) {
|
||||||
val eventType = EventType(null, it.displayName, it.color, it.id, it.displayName, it.accountName)
|
val eventType = EventType(null, it.displayName, it.color, it.id, it.displayName, it.accountName)
|
||||||
existingEventTypeNames.add(calendarTitle.toLowerCase())
|
existingEventTypeNames.add(calendarTitle.toLowerCase())
|
||||||
EventsHelper().insertOrUpdateEventType(this, eventType)
|
EventsHelper(applicationContext).insertOrUpdateEventType(this, eventType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CalDAVHandler(applicationContext).refreshCalendars(this) {}
|
CalDAVHandler(applicationContext).refreshCalendars(this) {}
|
||||||
|
@ -223,8 +223,8 @@ class SettingsActivity : SimpleActivity() {
|
||||||
val removedCalendarIds = oldCalendarIds.filter { !newCalendarIds.contains(it) }
|
val removedCalendarIds = oldCalendarIds.filter { !newCalendarIds.contains(it) }
|
||||||
removedCalendarIds.forEach {
|
removedCalendarIds.forEach {
|
||||||
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
|
CalDAVHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong())
|
||||||
EventsHelper().getEventTypeWithCalDAVCalendarId(applicationContext, it)?.apply {
|
EventsHelper(applicationContext).getEventTypeWithCalDAVCalendarId(it)?.apply {
|
||||||
EventsHelper().deleteEventTypes(applicationContext, arrayListOf(this), true)
|
EventsHelper(applicationContext).deleteEventTypes(arrayListOf(this), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun eventTypeConfirmed(title: String, dialog: AlertDialog) {
|
private fun eventTypeConfirmed(title: String, dialog: AlertDialog) {
|
||||||
val eventIdWithTitle = EventsHelper().getEventTypeIdWithTitle(activity, title)
|
val eventIdWithTitle = EventsHelper(activity).getEventTypeIdWithTitle(title)
|
||||||
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L
|
var isEventTypeTitleTaken = isNewEvent && eventIdWithTitle != -1L
|
||||||
if (!isEventTypeTitleTaken) {
|
if (!isEventTypeTitleTaken) {
|
||||||
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L
|
isEventTypeTitleTaken = !isNewEvent && eventType!!.id != eventIdWithTitle && eventIdWithTitle != -1L
|
||||||
|
@ -77,7 +77,7 @@ class EditEventTypeDialog(val activity: Activity, var eventType: EventType? = nu
|
||||||
eventType!!.caldavDisplayName = title
|
eventType!!.caldavDisplayName = title
|
||||||
}
|
}
|
||||||
|
|
||||||
eventType!!.id = EventsHelper().insertOrUpdateEventTypeSync(activity, eventType!!)
|
eventType!!.id = EventsHelper(activity).insertOrUpdateEventTypeSync(eventType!!)
|
||||||
|
|
||||||
if (eventType!!.id != -1L) {
|
if (eventType!!.id != -1L) {
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ExportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||||
export_events_folder.text = activity.humanizePath(path)
|
export_events_folder.text = activity.humanizePath(path)
|
||||||
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
|
export_events_filename.setText("${activity.getString(R.string.events)}_${activity.getCurrentFormattedDateTime()}")
|
||||||
|
|
||||||
EventsHelper().getEventTypes(activity) {
|
EventsHelper(activity).getEventTypes(activity) {
|
||||||
val eventTypes = HashSet<String>()
|
val eventTypes = HashSet<String>()
|
||||||
it.mapTo(eventTypes) { it.id.toString() }
|
it.mapTo(eventTypes) { it.id.toString() }
|
||||||
|
|
||||||
|
|
|
@ -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)
|
private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_event_types, null)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
EventsHelper().getEventTypes(activity) {
|
EventsHelper(activity).getEventTypes(activity) {
|
||||||
val displayEventTypes = activity.config.displayEventTypes
|
val displayEventTypes = activity.config.displayEventTypes
|
||||||
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
view.filter_event_types_list.adapter = FilterEventTypeAdapter(activity, it, displayEventTypes)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ImportEventsDialog(val activity: SimpleActivity, val path: String, val cal
|
||||||
private fun initDialog() {
|
private fun initDialog() {
|
||||||
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId)
|
val isLastCaldavCalendarOK = config.caldavSync && config.getSyncedCalendarIdsAsList().contains(config.lastUsedCaldavCalendarId)
|
||||||
currEventTypeId = if (isLastCaldavCalendarOK) {
|
currEventTypeId = if (isLastCaldavCalendarOK) {
|
||||||
val lastUsedCalDAVCalendar = EventsHelper().getEventTypeWithCalDAVCalendarId(activity, config.lastUsedCaldavCalendarId)
|
val lastUsedCalDAVCalendar = EventsHelper(activity).getEventTypeWithCalDAVCalendarId(config.lastUsedCaldavCalendarId)
|
||||||
if (lastUsedCalDAVCalendar != null) {
|
if (lastUsedCalDAVCalendar != null) {
|
||||||
currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId
|
currEventTypeCalDAVCalendarId = config.lastUsedCaldavCalendarId
|
||||||
lastUsedCalDAVCalendar.id!!
|
lastUsedCalDAVCalendar.id!!
|
||||||
|
|
|
@ -28,7 +28,7 @@ class SelectEventCalendarDialog(val activity: Activity, val calendars: List<CalD
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
calendars.forEach {
|
calendars.forEach {
|
||||||
val localEventType = EventsHelper().getEventTypeWithCalDAVCalendarId(activity, it.id)
|
val localEventType = EventsHelper(activity).getEventTypeWithCalDAVCalendarId(it.id)
|
||||||
if (localEventType != null) {
|
if (localEventType != null) {
|
||||||
it.color = localEventType.color
|
it.color = localEventType.color
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
val view = activity.layoutInflater.inflate(R.layout.dialog_select_radio_group, null) as ViewGroup
|
||||||
radioGroup = view.dialog_radio_group
|
radioGroup = view.dialog_radio_group
|
||||||
|
|
||||||
EventsHelper().getEventTypes(activity) {
|
EventsHelper(activity).getEventTypes(activity) {
|
||||||
eventTypes = it
|
eventTypes = it
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
eventTypes.filter { showCalDAVCalendars || it.caldavCalendarId == 0 }.forEach {
|
||||||
|
|
|
@ -66,7 +66,7 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
EventsHelper().getEventTypes(activity!!) {
|
EventsHelper(activity!!).getEventTypes(activity!!) {
|
||||||
it.map { eventTypeColors.put(it.id!!, it.color) }
|
it.map { eventTypeColors.put(it.id!!, it.color) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,12 @@ class CalDAVHandler(val context: Context) {
|
||||||
fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) {
|
fun refreshCalendars(activity: SimpleActivity? = null, callback: () -> Unit) {
|
||||||
val calDAVCalendars = getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs)
|
val calDAVCalendars = getCalDAVCalendars(activity, context.config.caldavSyncedCalendarIDs)
|
||||||
for (calendar in calDAVCalendars) {
|
for (calendar in calDAVCalendars) {
|
||||||
val localEventType = EventsHelper().getEventTypeWithCalDAVCalendarId(context, calendar.id) ?: continue
|
val localEventType = EventsHelper(context).getEventTypeWithCalDAVCalendarId(calendar.id) ?: continue
|
||||||
localEventType.apply {
|
localEventType.apply {
|
||||||
title = calendar.displayName
|
title = calendar.displayName
|
||||||
caldavDisplayName = calendar.displayName
|
caldavDisplayName = calendar.displayName
|
||||||
caldavEmail = calendar.accountName
|
caldavEmail = calendar.accountName
|
||||||
EventsHelper().insertOrUpdateEventTypeSync(context, this)
|
EventsHelper(context).insertOrUpdateEventTypeSync(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity)
|
CalDAVHandler(context).fetchCalDAVCalendarEvents(calendar.id, localEventType.id!!, activity)
|
||||||
|
@ -226,7 +226,7 @@ class CalDAVHandler(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(context, null, event, false)
|
EventsHelper(context).updateEvent(null, event, false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the event is an exception from another events repeat rule, find the original parent event
|
// 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()) {
|
if (title.isNotEmpty()) {
|
||||||
importIdsMap[event.importId] = event
|
importIdsMap[event.importId] = event
|
||||||
EventsHelper().insertEvent(context, null, event, false)
|
EventsHelper(context).insertEvent(null, event, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
|
|
|
@ -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 childEventId = it
|
||||||
val eventRepetitionException = EventRepetitionException(null, Formatter.getDayCodeFromTS(occurrenceTS), parentEventId)
|
val eventRepetitionException = EventRepetitionException(null, Formatter.getDayCodeFromTS(occurrenceTS), parentEventId)
|
||||||
callback(eventRepetitionException)
|
callback(eventRepetitionException)
|
||||||
|
@ -302,7 +302,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
events = events
|
events = events
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.distinct()
|
.distinct()
|
||||||
.filterNot { EventsHelper().getEventRepetitionIgnoredOccurrences(context, it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
.filterNot { EventsHelper(context).getEventRepetitionIgnoredOccurrences(it).contains(Formatter.getDayCodeFromTS(it.startTS)) }
|
||||||
.toMutableList() as ArrayList<Event>
|
.toMutableList() as ArrayList<Event>
|
||||||
callback(events)
|
callback(events)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.simplemobiletools.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.calendar.pro.models.EventType
|
import com.simplemobiletools.calendar.pro.models.EventType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class EventsHelper {
|
class EventsHelper(val context: Context) {
|
||||||
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
|
fun getEventTypes(activity: Activity, callback: (notes: ArrayList<EventType>) -> Unit) {
|
||||||
Thread {
|
Thread {
|
||||||
val eventTypes = activity.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
val eventTypes = activity.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||||
|
@ -18,18 +18,18 @@ class EventsHelper {
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventTypesSync(context: Context) = context.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
fun getEventTypesSync() = context.eventTypesDB.getEventTypes().toMutableList() as ArrayList<EventType>
|
||||||
|
|
||||||
fun insertOrUpdateEventType(activity: Activity, eventType: EventType, callback: ((newEventTypeId: Long) -> Unit)? = null) {
|
fun insertOrUpdateEventType(activity: Activity, eventType: EventType, callback: ((newEventTypeId: Long) -> Unit)? = null) {
|
||||||
Thread {
|
Thread {
|
||||||
val eventTypeId = insertOrUpdateEventTypeSync(activity, eventType)
|
val eventTypeId = insertOrUpdateEventTypeSync(eventType)
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
callback?.invoke(eventTypeId)
|
callback?.invoke(eventTypeId)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertOrUpdateEventTypeSync(context: Context, eventType: EventType): Long {
|
fun insertOrUpdateEventTypeSync(eventType: EventType): Long {
|
||||||
if (eventType.id != null && eventType.id!! > 0 && eventType.caldavCalendarId != 0) {
|
if (eventType.id != null && eventType.id!! > 0 && eventType.caldavCalendarId != 0) {
|
||||||
CalDAVHandler(context).updateCalDAVCalendar(eventType)
|
CalDAVHandler(context).updateCalDAVCalendar(eventType)
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,11 @@ class EventsHelper {
|
||||||
return newId
|
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<EventType>, deleteEvents: Boolean) {
|
fun deleteEventTypes(eventTypes: ArrayList<EventType>, deleteEvents: Boolean) {
|
||||||
val typesToDelete = eventTypes.asSequence().filter { it.caldavCalendarId == 0 && it.id != DBHelper.REGULAR_EVENT_TYPE_ID }.toMutableList()
|
val typesToDelete = eventTypes.asSequence().filter { it.caldavCalendarId == 0 && it.id != DBHelper.REGULAR_EVENT_TYPE_ID }.toMutableList()
|
||||||
val deleteIds = typesToDelete.map { it.id }.toMutableList()
|
val deleteIds = typesToDelete.map { it.id }.toMutableList()
|
||||||
val deletedSet = deleteIds.map { it.toString() }.toHashSet()
|
val deletedSet = deleteIds.map { it.toString() }.toHashSet()
|
||||||
|
@ -64,7 +64,7 @@ class EventsHelper {
|
||||||
context.eventTypesDB.deleteEventTypes(typesToDelete)
|
context.eventTypesDB.deleteEventTypes(typesToDelete)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEventRepetitionIgnoredOccurrences(context: Context, event: Event): ArrayList<String> {
|
fun getEventRepetitionIgnoredOccurrences(event: Event): ArrayList<String> {
|
||||||
return if (event.id == null || event.repeatInterval == 0) {
|
return if (event.id == null || event.repeatInterval == 0) {
|
||||||
ArrayList()
|
ArrayList()
|
||||||
} else {
|
} 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) {
|
if (event.startTS > event.endTS) {
|
||||||
callback?.invoke(0)
|
callback?.invoke(0)
|
||||||
return
|
return
|
||||||
|
@ -95,31 +95,31 @@ class EventsHelper {
|
||||||
callback?.invoke(event.id!!)
|
callback?.invoke(event.id!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insertEvents(activity: Activity, events: ArrayList<Event>, addToCalDAV: Boolean) {
|
fun insertEvents(events: ArrayList<Event>, addToCalDAV: Boolean) {
|
||||||
try {
|
try {
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
if (event.startTS > event.endTS) {
|
if (event.startTS > event.endTS) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = activity.eventsDB.insertOrUpdate(event)
|
val id = context.eventsDB.insertOrUpdate(event)
|
||||||
event.id = id
|
event.id = id
|
||||||
|
|
||||||
if (event.repeatInterval != 0 && event.parentId == 0L) {
|
if (event.repeatInterval != 0 && event.parentId == 0L) {
|
||||||
activity.eventRepetitionsDB.insertOrUpdate(event.getEventRepetition())
|
context.eventRepetitionsDB.insertOrUpdate(event.getEventRepetition())
|
||||||
}
|
}
|
||||||
|
|
||||||
//context.scheduleNextEventReminder(event, this)
|
//context.scheduleNextEventReminder(event, this)
|
||||||
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && activity.config.caldavSync) {
|
if (addToCalDAV && event.source != SOURCE_SIMPLE_CALENDAR && event.source != SOURCE_IMPORTED_ICS && context.config.caldavSync) {
|
||||||
CalDAVHandler(activity).insertCalDAVEvent(event)
|
CalDAVHandler(context).insertCalDAVEvent(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} 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)
|
context.eventsDB.insertOrUpdate(event)
|
||||||
|
|
||||||
if (event.repeatInterval == 0) {
|
if (event.repeatInterval == 0) {
|
||||||
|
|
|
@ -92,7 +92,7 @@ class IcsExporter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fillIgnoredOccurrences(activity: BaseSimpleActivity, event: Event, out: BufferedWriter) {
|
private fun fillIgnoredOccurrences(activity: BaseSimpleActivity, event: Event, out: BufferedWriter) {
|
||||||
EventsHelper().getEventRepetitionIgnoredOccurrences(activity, event).forEach {
|
EventsHelper(activity).getEventRepetitionIgnoredOccurrences(event).forEach {
|
||||||
out.writeLn("$EXDATE:$it")
|
out.writeLn("$EXDATE:$it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
|
|
||||||
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
fun importEvents(path: String, defaultEventTypeId: Long, calDAVCalendarId: Int, overrideFileEventTypes: Boolean): ImportResult {
|
||||||
try {
|
try {
|
||||||
val eventTypes = EventsHelper().getEventTypesSync(activity)
|
val eventTypes = EventsHelper(activity).getEventTypesSync()
|
||||||
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
val existingEvents = activity.dbHelper.getEventsWithImportIds()
|
||||||
val eventsToInsert = ArrayList<Event>()
|
val eventsToInsert = ArrayList<Event>()
|
||||||
var prevLine = ""
|
var prevLine = ""
|
||||||
|
@ -158,7 +158,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
if (curRepeatExceptions.isEmpty()) {
|
if (curRepeatExceptions.isEmpty()) {
|
||||||
eventsToInsert.add(event)
|
eventsToInsert.add(event)
|
||||||
} else {
|
} else {
|
||||||
EventsHelper().insertEvent(activity, activity, event, true) {
|
EventsHelper(activity).insertEvent(activity, event, true) {
|
||||||
for (exceptionTS in curRepeatExceptions) {
|
for (exceptionTS in curRepeatExceptions) {
|
||||||
activity.dbHelper.addEventRepeatException(it, exceptionTS, true)
|
activity.dbHelper.addEventRepeatException(it, exceptionTS, true)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
event.id = eventToUpdate.id
|
event.id = eventToUpdate.id
|
||||||
EventsHelper().updateEvent(activity, null, event, true)
|
EventsHelper(activity).updateEvent(null, event, true)
|
||||||
}
|
}
|
||||||
eventsImported++
|
eventsImported++
|
||||||
resetValues()
|
resetValues()
|
||||||
|
@ -176,7 +176,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventsHelper().insertEvents(activity, eventsToInsert, true)
|
EventsHelper(activity).insertEvents(eventsToInsert, true)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
activity.showErrorToast(e, Toast.LENGTH_LONG)
|
activity.showErrorToast(e, Toast.LENGTH_LONG)
|
||||||
eventsFailed++
|
eventsFailed++
|
||||||
|
@ -223,11 +223,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
categories
|
categories
|
||||||
}
|
}
|
||||||
|
|
||||||
val eventId = EventsHelper().getEventTypeIdWithTitle(activity, eventTypeTitle)
|
val eventId = EventsHelper(activity).getEventTypeIdWithTitle(eventTypeTitle)
|
||||||
curEventTypeId = if (eventId == -1L) {
|
curEventTypeId = if (eventId == -1L) {
|
||||||
val newTypeColor = if (curCategoryColor == -2) activity.resources.getColor(R.color.color_primary) else curCategoryColor
|
val newTypeColor = if (curCategoryColor == -2) activity.resources.getColor(R.color.color_primary) else curCategoryColor
|
||||||
val eventType = EventType(null, eventTypeTitle, newTypeColor)
|
val eventType = EventType(null, eventTypeTitle, newTypeColor)
|
||||||
EventsHelper().insertOrUpdateEventTypeSync(activity, eventType)
|
EventsHelper(activity).insertOrUpdateEventTypeSync(eventType)
|
||||||
} else {
|
} else {
|
||||||
eventId
|
eventId
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||||
return
|
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.notifyEvent(event)
|
||||||
}
|
}
|
||||||
context.scheduleNextEventReminder(event, context.dbHelper)
|
context.scheduleNextEventReminder(event, context.dbHelper)
|
||||||
|
|
Loading…
Reference in New Issue