From b02f055d6a0f285ed01090fa34a652a5dcef0583 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 23 Apr 2017 22:16:25 +0200 Subject: [PATCH] fix importing events when the title is Unavailable --- .../simplemobiletools/calendar/helpers/Constants.kt | 2 +- .../simplemobiletools/calendar/helpers/IcsExporter.kt | 2 +- .../simplemobiletools/calendar/helpers/IcsImporter.kt | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) 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 03f125b06..9bd29a8d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -73,7 +73,7 @@ val END_ALARM = "END:VALARM" val DTSTART = "DTSTART" val DTEND = "DTEND" val DURATION = "DURATION:" -val SUMMARY = "SUMMARY:" +val SUMMARY = "SUMMARY" val DESCRIPTION = "DESCRIPTION:" val UID = "UID:" val ACTION = "ACTION:" 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 2040484f1..df3358774 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt @@ -22,7 +22,7 @@ class IcsExporter { for (event in events) { out.writeLn(BEGIN_EVENT) - event.title.let { if (it.isNotEmpty()) out.writeLn("$SUMMARY$it") } + event.title.let { if (it.isNotEmpty()) out.writeLn("$SUMMARY:$it") } event.description.let { if (it.isNotEmpty()) out.writeLn("$DESCRIPTION$it") } event.importId?.let { if (it.isNotEmpty()) out.writeLn("$UID$it") } event.eventType.let { out.writeLn("$CATEGORIES${context.dbHelper.getEventType(it)?.title}") } 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 7b654319a..c63415775 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsImporter.kt @@ -62,7 +62,7 @@ class IcsImporter { curEnd = curStart + decodeTime(duration) } else if (line.startsWith(SUMMARY) && !isNotificationDescription) { curTitle = line.substring(SUMMARY.length) - curTitle = curTitle.substring(0, Math.min(curTitle.length, 50)) + curTitle = getTitle(curTitle) } else if (line.startsWith(DESCRIPTION) && !isNotificationDescription) { curDescription = line.substring(DESCRIPTION.length) } else if (line.startsWith(UID)) { @@ -156,6 +156,14 @@ class IcsImporter { } } + private fun getTitle(title: String): String { + return if (title.startsWith(";") && title.contains(":")) { + title.substring(title.lastIndexOf(':') + 1) + } else { + title.substring(1, Math.min(title.length, 50)) + } + } + // P0DT1H0M0S private fun decodeTime(duration: String): Int { val weeks = getDurationValue(duration, "W")