From da75540321c8294c9b0f16d48f3ef6af1a84be90 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Mar 2017 21:59:31 +0100 Subject: [PATCH] if an ics file event contains multiple categories, use the first one --- .../calendar/helpers/IcsParser.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt index e18c309fc..c07166be2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsParser.kt @@ -155,16 +155,19 @@ class IcsParser { } private fun tryAddCategories(categories: String, context: Context) { - if (!categories.contains(",")) { - val eventTitle = categories - val dbHelper = DBHelper.newInstance(context) - val eventId = dbHelper.getEventTypeIdWithTitle(eventTitle) - if (eventId == -1) { - val eventType = EventType(0, eventTitle, context.resources.getColor(R.color.color_primary)) - curEventType = dbHelper.insertEventType(eventType) - } else { - curEventType = eventId - } + val eventTypeTitle = if (categories.contains(",")) { + categories.split(",")[0] + } else { + categories + } + + val dbHelper = DBHelper.newInstance(context) + val eventId = dbHelper.getEventTypeIdWithTitle(eventTypeTitle) + if (eventId == -1) { + val eventType = EventType(0, eventTypeTitle, context.resources.getColor(R.color.color_primary)) + curEventType = dbHelper.insertEventType(eventType) + } else { + curEventType = eventId } }