mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2024-12-25 07:50:56 +01:00
properly export email event reminders in .ics files
This commit is contained in:
parent
44bc741572
commit
69d78a1b58
@ -315,7 +315,6 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun setupWeekNumbers() {
|
||||
settings_week_numbers.isChecked = config.showWeekNumbers
|
||||
settings_week_numbers_holder.setOnClickListener {
|
||||
|
@ -53,7 +53,7 @@ class CalDAVHelper(val context: Context) {
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
fun getCalDAVCalendars(ids: String, showToasts: Boolean): List<CalDAVCalendar> {
|
||||
fun getCalDAVCalendars(ids: String, showToasts: Boolean): ArrayList<CalDAVCalendar> {
|
||||
val calendars = ArrayList<CalDAVCalendar>()
|
||||
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)
|
||||
|
@ -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"
|
||||
|
@ -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<CalDAVCalendar>()
|
||||
|
||||
fun exportEvents(activity: BaseSimpleActivity, file: File, events: ArrayList<Event>, 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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user