mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-20 05:30:40 +01:00
properly export and import custom event type colors through ics files
This commit is contained in:
parent
a0d8a5a5a9
commit
38f023bca1
@ -99,6 +99,9 @@ val BYDAY = "BYDAY"
|
|||||||
val BYMONTHDAY = "BYMONTHDAY"
|
val BYMONTHDAY = "BYMONTHDAY"
|
||||||
val LOCATION = "LOCATION:"
|
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 DISPLAY = "DISPLAY"
|
||||||
val FREQ = "FREQ"
|
val FREQ = "FREQ"
|
||||||
val UNTIL = "UNTIL"
|
val UNTIL = "UNTIL"
|
||||||
|
@ -33,6 +33,7 @@ class IcsExporter {
|
|||||||
event.title.replace("\n", "\\n").let { if (it.isNotEmpty()) out.writeLn("$SUMMARY:$it") }
|
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.description.replace("\n", "\\n").let { if (it.isNotEmpty()) out.writeLn("$DESCRIPTION$it") }
|
||||||
event.importId.let { if (it.isNotEmpty()) out.writeLn("$UID$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.eventType.let { out.writeLn("$CATEGORIES${activity.dbHelper.getEventType(it)?.title}") }
|
||||||
event.lastUpdated.let { out.writeLn("$LAST_MODIFIED:${Formatter.getExportedTime(it)}") }
|
event.lastUpdated.let { out.writeLn("$LAST_MODIFIED:${Formatter.getExportedTime(it)}") }
|
||||||
event.location.let { if (it.isNotEmpty()) out.writeLn("$LOCATION$it") }
|
event.location.let { if (it.isNotEmpty()) out.writeLn("$LOCATION$it") }
|
||||||
|
@ -8,6 +8,7 @@ import com.simplemobiletools.calendar.extensions.dbHelper
|
|||||||
import com.simplemobiletools.calendar.helpers.IcsImporter.ImportResult.*
|
import com.simplemobiletools.calendar.helpers.IcsImporter.ImportResult.*
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
import com.simplemobiletools.calendar.models.EventType
|
import com.simplemobiletools.calendar.models.EventType
|
||||||
|
import com.simplemobiletools.commons.extensions.areDigitsOnly
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ class IcsImporter {
|
|||||||
private var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
private var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||||
private var curLastModified = 0L
|
private var curLastModified = 0L
|
||||||
private var curLocation = ""
|
private var curLocation = ""
|
||||||
|
private var curCategoryColor = -2
|
||||||
private var isNotificationDescription = false
|
private var isNotificationDescription = false
|
||||||
private var isProperReminderAction = false
|
private var isProperReminderAction = false
|
||||||
private var curReminderTriggerMinutes = -1
|
private var curReminderTriggerMinutes = -1
|
||||||
@ -86,6 +88,11 @@ class IcsImporter {
|
|||||||
isProperReminderAction = line.substring(ACTION.length) == DISPLAY
|
isProperReminderAction = line.substring(ACTION.length) == DISPLAY
|
||||||
} else if (line.startsWith(TRIGGER)) {
|
} else if (line.startsWith(TRIGGER)) {
|
||||||
curReminderTriggerMinutes = Parser().parseDurationSeconds(line.substring(TRIGGER.length)) / 60
|
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)) {
|
} else if (line.startsWith(CATEGORIES)) {
|
||||||
val categories = line.substring(CATEGORIES.length)
|
val categories = line.substring(CATEGORIES.length)
|
||||||
tryAddCategories(categories, activity)
|
tryAddCategories(categories, activity)
|
||||||
@ -179,7 +186,8 @@ class IcsImporter {
|
|||||||
|
|
||||||
val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle)
|
val eventId = context.dbHelper.getEventTypeIdWithTitle(eventTypeTitle)
|
||||||
curEventType = if (eventId == -1) {
|
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)
|
context.dbHelper.insertEventType(eventType)
|
||||||
} else {
|
} else {
|
||||||
eventId
|
eventId
|
||||||
@ -208,6 +216,7 @@ class IcsImporter {
|
|||||||
curRepeatRule = 0
|
curRepeatRule = 0
|
||||||
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||||
curLastModified = 0L
|
curLastModified = 0L
|
||||||
|
curCategoryColor = -2
|
||||||
curLocation = ""
|
curLocation = ""
|
||||||
isNotificationDescription = false
|
isNotificationDescription = false
|
||||||
isProperReminderAction = false
|
isProperReminderAction = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user