From c2b31a8de4918484c5d722f326fce25e2487cb27 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 23 Feb 2021 15:12:24 +0100 Subject: [PATCH] fix #1258, properly handle importing events, if exdates are split by line --- .../calendar/pro/helpers/IcsImporter.kt | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 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 a442ba033..047be8a6b 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 @@ -134,7 +134,13 @@ class IcsImporter(val activity: SimpleActivity) { value = value.substring(0, value.length - 1) } - curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(value))) + if (value.contains(",")) { + value.split(",").forEach { exdate -> + curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(exdate))) + } + } else { + curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(value))) + } } else if (line.startsWith(LOCATION)) { curLocation = getLocation(line.substring(LOCATION.length).replace("\\,", ",")) if (curLocation.trim().isEmpty()) { @@ -247,17 +253,19 @@ class IcsImporter(val activity: SimpleActivity) { private fun getTimestamp(fullString: String): Long { return try { - if (fullString.startsWith(';')) { - val value = fullString.substring(fullString.lastIndexOf(':') + 1).replace(" ", "") - if (value.isEmpty()) { - return 0 - } else if (!value.contains("T")) { - curFlags = curFlags or FLAG_ALL_DAY - } + when { + fullString.startsWith(';') -> { + val value = fullString.substring(fullString.lastIndexOf(':') + 1).replace(" ", "") + if (value.isEmpty()) { + return 0 + } else if (!value.contains("T")) { + curFlags = curFlags or FLAG_ALL_DAY + } - Parser().parseDateTimeValue(value) - } else { - Parser().parseDateTimeValue(fullString.substring(1)) + Parser().parseDateTimeValue(value) + } + fullString.startsWith(":") -> Parser().parseDateTimeValue(fullString.substring(1)) + else -> Parser().parseDateTimeValue(fullString) } } catch (e: Exception) { activity.showErrorToast(e)