fix #711, handle some new cases at importing linked events via sequences
This commit is contained in:
parent
25f490aeb9
commit
9b4be2717e
3 changed files with 36 additions and 1 deletions
|
@ -104,6 +104,8 @@ const val BYDAY = "BYDAY"
|
|||
const val BYMONTHDAY = "BYMONTHDAY"
|
||||
const val BYMONTH = "BYMONTH"
|
||||
const val LOCATION = "LOCATION"
|
||||
const val RECURRENCE_ID = "RECURRENCE-ID"
|
||||
const val SEQUENCE = "SEQUENCE"
|
||||
|
||||
// this tag isn't a standard ICS tag, but there's no official way of adding a category color in an ics file
|
||||
const val CATEGORY_COLOR = "CATEGORY_COLOR:"
|
||||
|
|
|
@ -23,6 +23,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
private var curLocation = ""
|
||||
private var curDescription = ""
|
||||
private var curImportId = ""
|
||||
private var curRecurrenceDayCode = ""
|
||||
private var curFlags = 0
|
||||
private var curReminderMinutes = ArrayList<Int>()
|
||||
private var curRepeatExceptions = ArrayList<String>()
|
||||
|
@ -35,6 +36,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
private var isNotificationDescription = false
|
||||
private var isProperReminderAction = false
|
||||
private var isDescription = false
|
||||
private var isSequence = false
|
||||
private var curReminderTriggerMinutes = -1
|
||||
private val eventsHelper = activity.eventsHelper
|
||||
|
||||
|
@ -121,6 +123,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(value)))
|
||||
} else if (line.startsWith(LOCATION)) {
|
||||
curLocation = getLocation(line.substring(LOCATION.length).replace("\\,", ","))
|
||||
} else if (line.startsWith(RECURRENCE_ID)) {
|
||||
val timestamp = getTimestamp(line.substring(RECURRENCE_ID.length))
|
||||
curRecurrenceDayCode = Formatter.getDayCodeFromTS(timestamp)
|
||||
} else if (line.startsWith(SEQUENCE)) {
|
||||
isSequence = true
|
||||
} else if (line == END_ALARM) {
|
||||
if (isProperReminderAction && curReminderTriggerMinutes != -1) {
|
||||
curReminderMinutes.add(curReminderTriggerMinutes)
|
||||
|
@ -157,7 +164,28 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
}
|
||||
|
||||
if (eventToUpdate == null) {
|
||||
eventsToInsert.add(event)
|
||||
// if an event belongs to a sequence insert it immediately, to avoid some glitches with linked events
|
||||
if (isSequence) {
|
||||
if (curRecurrenceDayCode.isEmpty()) {
|
||||
eventsHelper.insertEvent(null, event, true)
|
||||
} else {
|
||||
// if an event contains the RECURRENCE-ID field, it is an exception to a recurring event, so update its parent too
|
||||
val parentEvent = activity.eventsDB.getEventWithImportId(event.importId)
|
||||
if (parentEvent != null) {
|
||||
if (parentEvent.repetitionExceptions.contains(curRecurrenceDayCode)) {
|
||||
continue
|
||||
}
|
||||
|
||||
parentEvent.repetitionExceptions.add(curRecurrenceDayCode)
|
||||
activity.eventsDB.insertOrUpdate(parentEvent)
|
||||
|
||||
event.parentId = parentEvent.id!!
|
||||
eventsToInsert.add(event)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventsToInsert.add(event)
|
||||
}
|
||||
} else {
|
||||
event.id = eventToUpdate.id
|
||||
eventsHelper.updateEvent(null, event, true)
|
||||
|
@ -241,6 +269,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
curLocation = ""
|
||||
curDescription = ""
|
||||
curImportId = ""
|
||||
curRecurrenceDayCode = ""
|
||||
curFlags = 0
|
||||
curReminderMinutes = ArrayList()
|
||||
curRepeatExceptions = ArrayList()
|
||||
|
@ -252,6 +281,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
|||
curCategoryColor = -2
|
||||
isNotificationDescription = false
|
||||
isProperReminderAction = false
|
||||
isSequence = false
|
||||
curReminderTriggerMinutes = -1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ interface EventsDao {
|
|||
@Query("SELECT * FROM events WHERE id = :id")
|
||||
fun getEventWithId(id: Long): Event?
|
||||
|
||||
@Query("SELECT * FROM events WHERE import_id = :importId")
|
||||
fun getEventWithImportId(importId: String): Event?
|
||||
|
||||
@Query("SELECT * FROM events WHERE start_ts <= :toTS AND end_ts >= :fromTS AND repeat_interval = 0")
|
||||
fun getOneTimeEventsFromTo(toTS: Long, fromTS: Long): List<Event>
|
||||
|
||||
|
|
Loading…
Reference in a new issue