properly export and import custom event type colors through ics files

This commit is contained in:
tibbi 2017-12-03 22:57:01 +01:00
parent a0d8a5a5a9
commit 38f023bca1
3 changed files with 14 additions and 1 deletions

View File

@ -99,6 +99,9 @@ val BYDAY = "BYDAY"
val BYMONTHDAY = "BYMONTHDAY"
val LOCATION = "LOCATION:"
// this tag isn't a standard ICS tag, but there's no official way of adding a category color in an ics file
val CATEGORY_COLOR = "CATEGORY_COLOR:"
val DISPLAY = "DISPLAY"
val FREQ = "FREQ"
val UNTIL = "UNTIL"

View File

@ -33,6 +33,7 @@ class IcsExporter {
event.title.replace("\n", "\\n").let { if (it.isNotEmpty()) out.writeLn("$SUMMARY:$it") }
event.description.replace("\n", "\\n").let { if (it.isNotEmpty()) out.writeLn("$DESCRIPTION$it") }
event.importId.let { if (it.isNotEmpty()) out.writeLn("$UID$it") }
event.eventType.let { out.writeLn("$CATEGORY_COLOR${activity.dbHelper.getEventType(it)?.color}") }
event.eventType.let { out.writeLn("$CATEGORIES${activity.dbHelper.getEventType(it)?.title}") }
event.lastUpdated.let { out.writeLn("$LAST_MODIFIED:${Formatter.getExportedTime(it)}") }
event.location.let { if (it.isNotEmpty()) out.writeLn("$LOCATION$it") }

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.helpers.IcsImporter.ImportResult.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.areDigitsOnly
import com.simplemobiletools.commons.extensions.showErrorToast
import java.io.File
@ -30,6 +31,7 @@ class IcsImporter {
private var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
private var curLastModified = 0L
private var curLocation = ""
private var curCategoryColor = -2
private var isNotificationDescription = false
private var isProperReminderAction = false
private var curReminderTriggerMinutes = -1
@ -86,6 +88,11 @@ class IcsImporter {
isProperReminderAction = line.substring(ACTION.length) == DISPLAY
} else if (line.startsWith(TRIGGER)) {
curReminderTriggerMinutes = Parser().parseDurationSeconds(line.substring(TRIGGER.length)) / 60
} else if (line.startsWith(CATEGORY_COLOR)) {
val color = line.substring(CATEGORY_COLOR.length)
if (color.trimStart('-').areDigitsOnly()) {
curCategoryColor = Integer.parseInt(color)
}
} else if (line.startsWith(CATEGORIES)) {
val categories = line.substring(CATEGORIES.length)
tryAddCategories(categories, activity)
@ -179,7 +186,8 @@ class IcsImporter {
val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle)
curEventType = if (eventId == -1) {
val eventType = EventType(0, eventTypeTitle, context.resources.getColor(R.color.color_primary))
val newTypeColor = if (curCategoryColor == -2) context.resources.getColor(R.color.color_primary) else curCategoryColor
val eventType = EventType(0, eventTypeTitle, newTypeColor)
context.dbHelper.insertEventType(eventType)
} else {
eventId
@ -208,6 +216,7 @@ class IcsImporter {
curRepeatRule = 0
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
curLastModified = 0L
curCategoryColor = -2
curLocation = ""
isNotificationDescription = false
isProperReminderAction = false