diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index e88611caa..8f3367793 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -26,6 +26,7 @@ val BIWEEK = 1209600 val MONTH = 2592000 // exact value not taken into account, Joda is used for adding months and years val YEAR = 31536000 +val DAY_MINUTES = 24 * 60 val DAY_SECONDS = 24 * 60 * 60 val WEEK_SECONDS = 7 * DAY_SECONDS @@ -54,6 +55,8 @@ val BEGIN_CALENDAR = "BEGIN:VCALENDAR" val END_CALENDAR = "END:VCALENDAR" val BEGIN_EVENT = "BEGIN:VEVENT" val END_EVENT = "END:VEVENT" +val BEGIN_ALARM = "BEGIN:VALARM" +val END_ALARM = "END:VALARM" val DTSTART = "DTSTART" val DTEND = "DTEND" val DURATION = "DURATION:" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt index 9b77f78e6..39e85acef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt @@ -36,6 +36,7 @@ class IcsExporter { } fillRepeatInterval(event, out) + fillReminders(event, out) out.writeLn("$STATUS$CONFIRMED") out.writeLn(END_EVENT) @@ -92,4 +93,34 @@ class IcsExporter { else ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}" } + + 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) { + out.writeLn(BEGIN_ALARM) + out.writeLn("$ACTION$DISPLAY") + out.writeLn("$TRIGGER${getReminderString(minutes)}") + out.writeLn(END_ALARM) + } + } + + private fun getReminderString(minutes: Int): String { + var days = 0 + var hours = 0 + var remainder = minutes + if (remainder >= DAY_MINUTES) { + days = Math.floor(((remainder / DAY_MINUTES).toDouble())).toInt() + remainder -= days * DAY_MINUTES + } + if (remainder >= 60) { + hours = Math.floor(((remainder / 60).toDouble())).toInt() + remainder -= hours * 60 + } + return "-P${days}DT${hours}H${remainder}M0S" + } }