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 ba30c49b2..32b8e1ebe 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 @@ -315,7 +315,6 @@ class SettingsActivity : SimpleActivity() { } } - private fun setupWeekNumbers() { settings_week_numbers.isChecked = config.showWeekNumbers settings_week_numbers_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt index 6938c356d..ac90fa8a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/CalDAVHelper.kt @@ -53,7 +53,7 @@ class CalDAVHelper(val context: Context) { } @SuppressLint("MissingPermission") - fun getCalDAVCalendars(ids: String, showToasts: Boolean): List { + fun getCalDAVCalendars(ids: String, showToasts: Boolean): ArrayList { val calendars = ArrayList() if (!context.hasPermission(PERMISSION_WRITE_CALENDAR) || !context.hasPermission(PERMISSION_READ_CALENDAR)) { return calendars @@ -73,7 +73,7 @@ class CalDAVHelper(val context: Context) { var cursor: Cursor? = null try { cursor = context.contentResolver.query(uri, projection, selection, null, null) - if (cursor != null && cursor.moveToFirst()) { + if (cursor?.moveToFirst() == true) { do { val id = cursor.getIntValue(CalendarContract.Calendars._ID) val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME) @@ -145,7 +145,7 @@ class CalDAVHelper(val context: Context) { var cursor: Cursor? = null try { cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - if (cursor != null && cursor.moveToFirst()) { + if (cursor?.moveToFirst() == true) { do { val colorKey = cursor.getIntValue(CalendarContract.Colors.COLOR_KEY) val color = cursor.getIntValue(CalendarContract.Colors.COLOR) @@ -193,7 +193,7 @@ class CalDAVHelper(val context: Context) { var cursor: Cursor? = null try { cursor = context.contentResolver.query(uri, projection, selection, null, null) - if (cursor != null && cursor.moveToFirst()) { + if (cursor?.moveToFirst() == true) { do { val id = cursor.getLongValue(CalendarContract.Events._ID) val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: "" @@ -457,7 +457,7 @@ class CalDAVHelper(val context: Context) { var cursor: Cursor? = null try { cursor = context.contentResolver.query(uri, projection, selection, null, null) - if (cursor != null && cursor.moveToFirst()) { + if (cursor?.moveToFirst() == true) { do { val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES) val method = cursor.getIntValue(CalendarContract.Reminders.METHOD) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt index d2e0e3785..4878387c7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt @@ -100,6 +100,8 @@ const val SUMMARY = "SUMMARY" const val DESCRIPTION = "DESCRIPTION:" const val UID = "UID:" const val ACTION = "ACTION:" +const val ATTENDEE = "ATTENDEE:" +const val MAILTO = "mailto:" const val TRIGGER = "TRIGGER:" const val RRULE = "RRULE:" const val CATEGORIES = "CATEGORIES:" @@ -116,6 +118,7 @@ const val SEQUENCE = "SEQUENCE" const val CATEGORY_COLOR = "CATEGORY_COLOR:" const val DISPLAY = "DISPLAY" +const val EMAIL = "EMAIL" const val FREQ = "FREQ" const val UNTIL = "UNTIL" const val COUNT = "COUNT" 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 35a959666..1c7355b3c 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 @@ -1,8 +1,10 @@ package com.simplemobiletools.calendar.pro.helpers import com.simplemobiletools.calendar.pro.R +import com.simplemobiletools.calendar.pro.extensions.calDAVHelper import com.simplemobiletools.calendar.pro.extensions.eventTypesDB import com.simplemobiletools.calendar.pro.helpers.IcsExporter.ExportResult.* +import com.simplemobiletools.calendar.pro.models.CalDAVCalendar import com.simplemobiletools.calendar.pro.models.Event import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.getFileOutputStream @@ -19,6 +21,7 @@ class IcsExporter { private var eventsExported = 0 private var eventsFailed = 0 + private var calendars = ArrayList() fun exportEvents(activity: BaseSimpleActivity, file: File, events: ArrayList, showExportingToast: Boolean, callback: (result: ExportResult) -> Unit) { val fileDirItem = FileDirItem(file.absolutePath, file.name) @@ -29,6 +32,7 @@ class IcsExporter { } Thread { + calendars = activity.calDAVHelper.getCalDAVCalendars("", false) if (showExportingToast) { activity.toast(R.string.exporting) } @@ -77,17 +81,20 @@ class IcsExporter { } private fun fillReminders(event: Event, out: BufferedWriter) { - checkReminder(event.reminder1Minutes, out) - checkReminder(event.reminder2Minutes, out) - checkReminder(event.reminder3Minutes, out) - } - - private fun checkReminder(minutes: Int, out: BufferedWriter) { - if (minutes != -1) { + event.getReminders().forEach { + val reminder = it out.apply { writeLn(BEGIN_ALARM) - writeLn("$ACTION$DISPLAY") - writeLn("$TRIGGER-${Parser().getDurationCode(minutes.toLong())}") + if (reminder.type == REMINDER_NOTIFICATION) { + writeLn("$ACTION$DISPLAY") + } else { + writeLn("$ACTION$EMAIL") + val attendee = calendars.firstOrNull { it.id == event.getCalDAVCalendarId()}?.accountName + if (attendee != null) { + writeLn("$ATTENDEE$MAILTO$attendee") + } + } + writeLn("$TRIGGER-${Parser().getDurationCode(reminder.minutes.toLong())}") writeLn(END_ALARM) } }