mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
properly export email event reminders in .ics files
This commit is contained in:
@@ -315,7 +315,6 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun setupWeekNumbers() {
|
private fun setupWeekNumbers() {
|
||||||
settings_week_numbers.isChecked = config.showWeekNumbers
|
settings_week_numbers.isChecked = config.showWeekNumbers
|
||||||
settings_week_numbers_holder.setOnClickListener {
|
settings_week_numbers_holder.setOnClickListener {
|
||||||
|
@@ -53,7 +53,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
fun getCalDAVCalendars(ids: String, showToasts: Boolean): List<CalDAVCalendar> {
|
fun getCalDAVCalendars(ids: String, showToasts: Boolean): ArrayList<CalDAVCalendar> {
|
||||||
val calendars = ArrayList<CalDAVCalendar>()
|
val calendars = ArrayList<CalDAVCalendar>()
|
||||||
if (!context.hasPermission(PERMISSION_WRITE_CALENDAR) || !context.hasPermission(PERMISSION_READ_CALENDAR)) {
|
if (!context.hasPermission(PERMISSION_WRITE_CALENDAR) || !context.hasPermission(PERMISSION_READ_CALENDAR)) {
|
||||||
return calendars
|
return calendars
|
||||||
@@ -73,7 +73,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(CalendarContract.Calendars._ID)
|
val id = cursor.getIntValue(CalendarContract.Calendars._ID)
|
||||||
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
val displayName = cursor.getStringValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME)
|
||||||
@@ -145,7 +145,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val colorKey = cursor.getIntValue(CalendarContract.Colors.COLOR_KEY)
|
val colorKey = cursor.getIntValue(CalendarContract.Colors.COLOR_KEY)
|
||||||
val color = cursor.getIntValue(CalendarContract.Colors.COLOR)
|
val color = cursor.getIntValue(CalendarContract.Colors.COLOR)
|
||||||
@@ -193,7 +193,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
val id = cursor.getLongValue(CalendarContract.Events._ID)
|
||||||
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
val title = cursor.getStringValue(CalendarContract.Events.TITLE) ?: ""
|
||||||
@@ -457,7 +457,7 @@ class CalDAVHelper(val context: Context) {
|
|||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
try {
|
try {
|
||||||
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
cursor = context.contentResolver.query(uri, projection, selection, null, null)
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
do {
|
do {
|
||||||
val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES)
|
val minutes = cursor.getIntValue(CalendarContract.Reminders.MINUTES)
|
||||||
val method = cursor.getIntValue(CalendarContract.Reminders.METHOD)
|
val method = cursor.getIntValue(CalendarContract.Reminders.METHOD)
|
||||||
|
@@ -100,6 +100,8 @@ const val SUMMARY = "SUMMARY"
|
|||||||
const val DESCRIPTION = "DESCRIPTION:"
|
const val DESCRIPTION = "DESCRIPTION:"
|
||||||
const val UID = "UID:"
|
const val UID = "UID:"
|
||||||
const val ACTION = "ACTION:"
|
const val ACTION = "ACTION:"
|
||||||
|
const val ATTENDEE = "ATTENDEE:"
|
||||||
|
const val MAILTO = "mailto:"
|
||||||
const val TRIGGER = "TRIGGER:"
|
const val TRIGGER = "TRIGGER:"
|
||||||
const val RRULE = "RRULE:"
|
const val RRULE = "RRULE:"
|
||||||
const val CATEGORIES = "CATEGORIES:"
|
const val CATEGORIES = "CATEGORIES:"
|
||||||
@@ -116,6 +118,7 @@ const val SEQUENCE = "SEQUENCE"
|
|||||||
const val CATEGORY_COLOR = "CATEGORY_COLOR:"
|
const val CATEGORY_COLOR = "CATEGORY_COLOR:"
|
||||||
|
|
||||||
const val DISPLAY = "DISPLAY"
|
const val DISPLAY = "DISPLAY"
|
||||||
|
const val EMAIL = "EMAIL"
|
||||||
const val FREQ = "FREQ"
|
const val FREQ = "FREQ"
|
||||||
const val UNTIL = "UNTIL"
|
const val UNTIL = "UNTIL"
|
||||||
const val COUNT = "COUNT"
|
const val COUNT = "COUNT"
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package com.simplemobiletools.calendar.pro.helpers
|
package com.simplemobiletools.calendar.pro.helpers
|
||||||
|
|
||||||
import com.simplemobiletools.calendar.pro.R
|
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.extensions.eventTypesDB
|
||||||
import com.simplemobiletools.calendar.pro.helpers.IcsExporter.ExportResult.*
|
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.calendar.pro.models.Event
|
||||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||||
@@ -19,6 +21,7 @@ class IcsExporter {
|
|||||||
|
|
||||||
private var eventsExported = 0
|
private var eventsExported = 0
|
||||||
private var eventsFailed = 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) {
|
fun exportEvents(activity: BaseSimpleActivity, file: File, events: ArrayList<Event>, showExportingToast: Boolean, callback: (result: ExportResult) -> Unit) {
|
||||||
val fileDirItem = FileDirItem(file.absolutePath, file.name)
|
val fileDirItem = FileDirItem(file.absolutePath, file.name)
|
||||||
@@ -29,6 +32,7 @@ class IcsExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
|
calendars = activity.calDAVHelper.getCalDAVCalendars("", false)
|
||||||
if (showExportingToast) {
|
if (showExportingToast) {
|
||||||
activity.toast(R.string.exporting)
|
activity.toast(R.string.exporting)
|
||||||
}
|
}
|
||||||
@@ -77,17 +81,20 @@ class IcsExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun fillReminders(event: Event, out: BufferedWriter) {
|
private fun fillReminders(event: Event, out: BufferedWriter) {
|
||||||
checkReminder(event.reminder1Minutes, out)
|
event.getReminders().forEach {
|
||||||
checkReminder(event.reminder2Minutes, out)
|
val reminder = it
|
||||||
checkReminder(event.reminder3Minutes, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkReminder(minutes: Int, out: BufferedWriter) {
|
|
||||||
if (minutes != -1) {
|
|
||||||
out.apply {
|
out.apply {
|
||||||
writeLn(BEGIN_ALARM)
|
writeLn(BEGIN_ALARM)
|
||||||
writeLn("$ACTION$DISPLAY")
|
if (reminder.type == REMINDER_NOTIFICATION) {
|
||||||
writeLn("$TRIGGER-${Parser().getDurationCode(minutes.toLong())}")
|
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)
|
writeLn(END_ALARM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user