postpone RRULE parsing at .ics files, if needed

This commit is contained in:
tibbi 2019-12-02 21:13:29 +01:00
parent 59f9494753
commit 841c812fd5
1 changed files with 18 additions and 4 deletions

View File

@ -25,6 +25,7 @@ class IcsImporter(val activity: SimpleActivity) {
private var curDescription = "" private var curDescription = ""
private var curImportId = "" private var curImportId = ""
private var curRecurrenceDayCode = "" private var curRecurrenceDayCode = ""
private var curRrule = ""
private var curFlags = 0 private var curFlags = 0
private var curReminderMinutes = ArrayList<Int>() private var curReminderMinutes = ArrayList<Int>()
private var curReminderActions = ArrayList<Int>() private var curReminderActions = ArrayList<Int>()
@ -88,6 +89,10 @@ class IcsImporter(val activity: SimpleActivity) {
} else if (line.startsWith(DTSTART)) { } else if (line.startsWith(DTSTART)) {
if (isParsingEvent) { if (isParsingEvent) {
curStart = getTimestamp(line.substring(DTSTART.length)) curStart = getTimestamp(line.substring(DTSTART.length))
if (curRrule != "") {
parseRepeatRule()
}
} }
} else if (line.startsWith(DTEND)) { } else if (line.startsWith(DTEND)) {
curEnd = getTimestamp(line.substring(DTEND.length)) curEnd = getTimestamp(line.substring(DTEND.length))
@ -103,10 +108,11 @@ class IcsImporter(val activity: SimpleActivity) {
} else if (line.startsWith(UID)) { } else if (line.startsWith(UID)) {
curImportId = line.substring(UID.length).trim() curImportId = line.substring(UID.length).trim()
} else if (line.startsWith(RRULE)) { } else if (line.startsWith(RRULE)) {
val repeatRule = Parser().parseRepeatInterval(line.substring(RRULE.length), curStart) curRrule = line.substring(RRULE.length)
curRepeatRule = repeatRule.repeatRule // some RRULRs need to know the events start datetime. If it's yet unknown, postpone RRULE parsing
curRepeatInterval = repeatRule.repeatInterval if (curStart != -1L) {
curRepeatLimit = repeatRule.repeatLimit parseRepeatRule()
}
} else if (line.startsWith(ACTION)) { } else if (line.startsWith(ACTION)) {
isNotificationDescription = true isNotificationDescription = true
val action = line.substring(ACTION.length) 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() { private fun resetValues() {
curStart = -1L curStart = -1L
curEnd = -1L curEnd = -1L
@ -297,6 +310,7 @@ class IcsImporter(val activity: SimpleActivity) {
curDescription = "" curDescription = ""
curImportId = "" curImportId = ""
curRecurrenceDayCode = "" curRecurrenceDayCode = ""
curRrule = ""
curFlags = 0 curFlags = 0
curReminderMinutes = ArrayList() curReminderMinutes = ArrayList()
curReminderActions = ArrayList() curReminderActions = ArrayList()