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 BYMONTHDAY = "BYMONTHDAY"
|
||||||
const val BYMONTH = "BYMONTH"
|
const val BYMONTH = "BYMONTH"
|
||||||
const val LOCATION = "LOCATION"
|
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
|
// 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:"
|
const val CATEGORY_COLOR = "CATEGORY_COLOR:"
|
||||||
|
|
|
@ -23,6 +23,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
private var curLocation = ""
|
private var curLocation = ""
|
||||||
private var curDescription = ""
|
private var curDescription = ""
|
||||||
private var curImportId = ""
|
private var curImportId = ""
|
||||||
|
private var curRecurrenceDayCode = ""
|
||||||
private var curFlags = 0
|
private var curFlags = 0
|
||||||
private var curReminderMinutes = ArrayList<Int>()
|
private var curReminderMinutes = ArrayList<Int>()
|
||||||
private var curRepeatExceptions = ArrayList<String>()
|
private var curRepeatExceptions = ArrayList<String>()
|
||||||
|
@ -35,6 +36,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
private var isNotificationDescription = false
|
private var isNotificationDescription = false
|
||||||
private var isProperReminderAction = false
|
private var isProperReminderAction = false
|
||||||
private var isDescription = false
|
private var isDescription = false
|
||||||
|
private var isSequence = false
|
||||||
private var curReminderTriggerMinutes = -1
|
private var curReminderTriggerMinutes = -1
|
||||||
private val eventsHelper = activity.eventsHelper
|
private val eventsHelper = activity.eventsHelper
|
||||||
|
|
||||||
|
@ -121,6 +123,11 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(value)))
|
curRepeatExceptions.add(Formatter.getDayCodeFromTS(getTimestamp(value)))
|
||||||
} else if (line.startsWith(LOCATION)) {
|
} else if (line.startsWith(LOCATION)) {
|
||||||
curLocation = getLocation(line.substring(LOCATION.length).replace("\\,", ","))
|
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) {
|
} else if (line == END_ALARM) {
|
||||||
if (isProperReminderAction && curReminderTriggerMinutes != -1) {
|
if (isProperReminderAction && curReminderTriggerMinutes != -1) {
|
||||||
curReminderMinutes.add(curReminderTriggerMinutes)
|
curReminderMinutes.add(curReminderTriggerMinutes)
|
||||||
|
@ -157,7 +164,28 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventToUpdate == null) {
|
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 {
|
} else {
|
||||||
event.id = eventToUpdate.id
|
event.id = eventToUpdate.id
|
||||||
eventsHelper.updateEvent(null, event, true)
|
eventsHelper.updateEvent(null, event, true)
|
||||||
|
@ -241,6 +269,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
curLocation = ""
|
curLocation = ""
|
||||||
curDescription = ""
|
curDescription = ""
|
||||||
curImportId = ""
|
curImportId = ""
|
||||||
|
curRecurrenceDayCode = ""
|
||||||
curFlags = 0
|
curFlags = 0
|
||||||
curReminderMinutes = ArrayList()
|
curReminderMinutes = ArrayList()
|
||||||
curRepeatExceptions = ArrayList()
|
curRepeatExceptions = ArrayList()
|
||||||
|
@ -252,6 +281,7 @@ class IcsImporter(val activity: SimpleActivity) {
|
||||||
curCategoryColor = -2
|
curCategoryColor = -2
|
||||||
isNotificationDescription = false
|
isNotificationDescription = false
|
||||||
isProperReminderAction = false
|
isProperReminderAction = false
|
||||||
|
isSequence = false
|
||||||
curReminderTriggerMinutes = -1
|
curReminderTriggerMinutes = -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ interface EventsDao {
|
||||||
@Query("SELECT * FROM events WHERE id = :id")
|
@Query("SELECT * FROM events WHERE id = :id")
|
||||||
fun getEventWithId(id: Long): Event?
|
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")
|
@Query("SELECT * FROM events WHERE start_ts <= :toTS AND end_ts >= :fromTS AND repeat_interval = 0")
|
||||||
fun getOneTimeEventsFromTo(toTS: Long, fromTS: Long): List<Event>
|
fun getOneTimeEventsFromTo(toTS: Long, fromTS: Long): List<Event>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue