fix importing events when the title is Unavailable

This commit is contained in:
tibbi 2017-04-23 22:16:25 +02:00
parent 3b440abf34
commit b02f055d6a
3 changed files with 11 additions and 3 deletions

View File

@ -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:"

View File

@ -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}") }

View File

@ -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")