From 841c812fd5d146c51a518fcddd63bdada85953ee Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 2 Dec 2019 21:13:29 +0100 Subject: [PATCH] postpone RRULE parsing at .ics files, if needed --- .../calendar/pro/helpers/IcsImporter.kt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt index 70bdd61a4..775afbbff 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/IcsImporter.kt @@ -25,6 +25,7 @@ class IcsImporter(val activity: SimpleActivity) { private var curDescription = "" private var curImportId = "" private var curRecurrenceDayCode = "" + private var curRrule = "" private var curFlags = 0 private var curReminderMinutes = ArrayList() private var curReminderActions = ArrayList() @@ -88,6 +89,10 @@ class IcsImporter(val activity: SimpleActivity) { } else if (line.startsWith(DTSTART)) { if (isParsingEvent) { curStart = getTimestamp(line.substring(DTSTART.length)) + + if (curRrule != "") { + parseRepeatRule() + } } } else if (line.startsWith(DTEND)) { curEnd = getTimestamp(line.substring(DTEND.length)) @@ -103,10 +108,11 @@ class IcsImporter(val activity: SimpleActivity) { } else if (line.startsWith(UID)) { curImportId = line.substring(UID.length).trim() } else if (line.startsWith(RRULE)) { - val repeatRule = Parser().parseRepeatInterval(line.substring(RRULE.length), curStart) - curRepeatRule = repeatRule.repeatRule - curRepeatInterval = repeatRule.repeatInterval - curRepeatLimit = repeatRule.repeatLimit + curRrule = line.substring(RRULE.length) + // some RRULRs need to know the events start datetime. If it's yet unknown, postpone RRULE parsing + if (curStart != -1L) { + parseRepeatRule() + } } else if (line.startsWith(ACTION)) { isNotificationDescription = true val action = line.substring(ACTION.length) @@ -289,6 +295,13 @@ class IcsImporter(val activity: SimpleActivity) { } } + private fun parseRepeatRule() { + val repeatRule = Parser().parseRepeatInterval(curRrule, curStart) + curRepeatRule = repeatRule.repeatRule + curRepeatInterval = repeatRule.repeatInterval + curRepeatLimit = repeatRule.repeatLimit + } + private fun resetValues() { curStart = -1L curEnd = -1L @@ -297,6 +310,7 @@ class IcsImporter(val activity: SimpleActivity) { curDescription = "" curImportId = "" curRecurrenceDayCode = "" + curRrule = "" curFlags = 0 curReminderMinutes = ArrayList() curReminderActions = ArrayList()