properly handle importing repeat rules

This commit is contained in:
tibbi 2017-04-16 20:50:38 +02:00
parent 4e292e32dd
commit 5aa71c846b
1 changed files with 28 additions and 4 deletions

View File

@ -26,6 +26,7 @@ class IcsImporter {
var curRepeatExceptions = ArrayList<Int>() var curRepeatExceptions = ArrayList<Int>()
var curRepeatInterval = 0 var curRepeatInterval = 0
var curRepeatLimit = 0 var curRepeatLimit = 0
var curRepeatRule = 0
var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
var isNotificationDescription = false var isNotificationDescription = false
var lastReminderAction = "" var lastReminderAction = ""
@ -86,14 +87,13 @@ class IcsImporter {
importIDs.add(curImportId) importIDs.add(curImportId)
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }), val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval, curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
curImportId, curFlags, curRepeatLimit, curEventType) curImportId, curFlags, curRepeatLimit, curRepeatRule, curEventType)
val eventId = context.dbHelper.insert(event) val eventId = context.dbHelper.insert(event)
for (exceptionTS in curRepeatExceptions) { for (exceptionTS in curRepeatExceptions) {
context.dbHelper.addEventRepeatException(eventId, exceptionTS) context.dbHelper.addEventRepeatException(eventId, exceptionTS)
} }
eventsImported++ eventsImported++
resetValues() resetValues()
} }
@ -188,8 +188,12 @@ class IcsImporter {
val value = keyValue[1] val value = keyValue[1]
if (key == FREQ) { if (key == FREQ) {
frequencySeconds = getFrequencySeconds(value) frequencySeconds = getFrequencySeconds(value)
if (value == WEEKLY) {
val start = Formatter.getDateTimeFromTS(curStart)
curRepeatRule = Math.pow(2.0, (start.dayOfWeek - 1).toDouble()).toInt()
}
} else if (key == COUNT) { } else if (key == COUNT) {
count = value.toInt() count = value.toInt() - 1
if (frequencySeconds != 0) { if (frequencySeconds != 0) {
curRepeatLimit = curStart + count * frequencySeconds curRepeatLimit = curStart + count * frequencySeconds
} }
@ -200,8 +204,10 @@ class IcsImporter {
val repeatInterval = frequencySeconds * interval val repeatInterval = frequencySeconds * interval
if (count > 0) { if (count > 0) {
curRepeatLimit = curStart + count * repeatInterval curRepeatLimit = curStart + count * repeatInterval
return repeatInterval frequencySeconds *= interval
} }
} else if (key == BYDAY) {
handleRepeatRule(value)
} }
} }
return frequencySeconds return frequencySeconds
@ -217,6 +223,23 @@ class IcsImporter {
} }
} }
private fun handleRepeatRule(value: String) {
if (value.contains(MO))
curRepeatRule = curRepeatRule or MONDAY
if (value.contains(TU))
curRepeatRule = curRepeatRule or TUESDAY
if (value.contains(WE))
curRepeatRule = curRepeatRule or WEDNESDAY
if (value.contains(TH))
curRepeatRule = curRepeatRule or THURSDAY
if (value.contains(FR))
curRepeatRule = curRepeatRule or FRIDAY
if (value.contains(SA))
curRepeatRule = curRepeatRule or SATURDAY
if (value.contains(SU))
curRepeatRule = curRepeatRule or SUNDAY
}
private fun resetValues() { private fun resetValues() {
curStart = -1 curStart = -1
curEnd = -1 curEnd = -1
@ -228,6 +251,7 @@ class IcsImporter {
curRepeatExceptions = ArrayList<Int>() curRepeatExceptions = ArrayList<Int>()
curRepeatInterval = 0 curRepeatInterval = 0
curRepeatLimit = 0 curRepeatLimit = 0
curRepeatRule = 0
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
isNotificationDescription = false isNotificationDescription = false
lastReminderAction = "" lastReminderAction = ""