From dbaf0d79c70d431e5befc0463fcfff3308f4a7d1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 5 Apr 2017 23:17:25 +0200 Subject: [PATCH] properly handle importing events with multiple reminders --- .../calendar/dialogs/ImportEventsDialog.kt | 2 +- .../calendar/helpers/IcsImporter.kt | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt index 469378008..fc302b20c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/dialogs/ImportEventsDialog.kt @@ -38,7 +38,7 @@ class ImportEventsDialog(val activity: Activity, val path: String, val callback: activity.setupDialogStuff(view, this, R.string.import_events) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ Thread({ - val result = IcsImporter().parseIcs(context, path, currEventTypeId) + val result = IcsImporter().importEvents(context, path, currEventTypeId) handleParseResult(result) dismiss() }).start() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt index 1f5179646..68199c7bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt @@ -22,17 +22,17 @@ class IcsImporter { var curDescription = "" var curImportId = "" var curFlags = 0 - var curReminderMinutes = -1 + var curReminderMinutes = ArrayList() var curRepeatInterval = 0 var curRepeatLimit = 0 var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID - var curShouldHaveNotification = false var isNotificationDescription = false + var lastReminderAction = "" var eventsImported = 0 var eventsFailed = 0 - fun parseIcs(context: Context, path: String, defaultEventType: Int): ImportResult { + fun importEvents(context: Context, path: String, defaultEventType: Int): ImportResult { try { val importIDs = context.dbHelper.getImportIds() var prevLine = "" @@ -69,12 +69,10 @@ class IcsImporter { curRepeatInterval = parseRepeatInterval(line.substring(RRULE.length)) } else if (line.startsWith(ACTION)) { isNotificationDescription = true - if (line.substring(ACTION.length) == DISPLAY) - curShouldHaveNotification = true + lastReminderAction = line.substring(ACTION.length) } else if (line.startsWith(TRIGGER)) { - if (curReminderMinutes == -1 && curShouldHaveNotification) { - curReminderMinutes = decodeTime(line.substring(TRIGGER.length)) / 60 - } + if (lastReminderAction == DISPLAY) + curReminderMinutes.add(decodeTime(line.substring(TRIGGER.length)) / 60) } else if (line.startsWith(CATEGORIES)) { val categories = line.substring(CATEGORIES.length) tryAddCategories(categories, context) @@ -83,7 +81,8 @@ class IcsImporter { continue importIDs.add(curImportId) - val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes, -1, -1, curRepeatInterval, + val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }), + curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval, curImportId, curFlags, curRepeatLimit, curEventType) context.dbHelper.insert(event) { } eventsImported++ @@ -216,11 +215,11 @@ class IcsImporter { curDescription = "" curImportId = "" curFlags = 0 - curReminderMinutes = -1 + curReminderMinutes = ArrayList() curRepeatInterval = 0 curRepeatLimit = 0 curEventType = DBHelper.REGULAR_EVENT_TYPE_ID - curShouldHaveNotification = false isNotificationDescription = false + lastReminderAction = "" } }