handle exporting and importing events repeating every Xth day

This commit is contained in:
tibbi 2017-05-08 23:12:03 +02:00
parent 57fb030d96
commit bb53596b6e
2 changed files with 25 additions and 1 deletions

View File

@ -111,6 +111,12 @@ class IcsExporter {
} else if (event.repeatInterval.isXMonthlyRepetition()) { } else if (event.repeatInterval.isXMonthlyRepetition()) {
if (event.repeatRule == REPEAT_MONTH_LAST_DAY) { if (event.repeatRule == REPEAT_MONTH_LAST_DAY) {
";$BYMONTHDAY=-1" ";$BYMONTHDAY=-1"
} else if (event.repeatRule == REPEAT_MONTH_EVERY_XTH_DAY) {
val start = Formatter.getDateTimeFromTS(event.startTS)
val dayOfMonth = start.dayOfMonth
val order = (dayOfMonth - 1) / 7 + 1
val day = getDayLetters(start.dayOfWeek)
";$BYDAY=$order$day"
} else { } else {
"" ""
} }
@ -138,6 +144,18 @@ class IcsExporter {
return result.trimEnd(',') return result.trimEnd(',')
} }
private fun getDayLetters(dayOfWeek: Int): String {
return when (dayOfWeek) {
1 -> MO
2 -> TU
3 -> WE
4 -> TH
5 -> FR
6 -> SA
else -> SU
}
}
private fun fillReminders(event: Event, out: BufferedWriter) { private fun fillReminders(event: Event, out: BufferedWriter) {
checkReminder(event.reminder1Minutes, out) checkReminder(event.reminder1Minutes, out)
checkReminder(event.reminder2Minutes, out) checkReminder(event.reminder2Minutes, out)

View File

@ -3,6 +3,8 @@ package com.simplemobiletools.calendar.helpers
import android.content.Context import android.content.Context
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.dbHelper import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.isXMonthlyRepetition
import com.simplemobiletools.calendar.extensions.isXWeeklyRepetition
import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.extensions.seconds
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
@ -212,7 +214,11 @@ class IcsImporter {
} else if (key == INTERVAL) { } else if (key == INTERVAL) {
frequencySeconds *= value.toInt() frequencySeconds *= value.toInt()
} else if (key == BYDAY) { } else if (key == BYDAY) {
if (frequencySeconds.isXWeeklyRepetition()) {
handleRepeatRule(value) handleRepeatRule(value)
} else if (frequencySeconds.isXMonthlyRepetition()) {
curRepeatRule = REPEAT_MONTH_EVERY_XTH_DAY
}
} else if (key == BYMONTHDAY && value.toInt() == -1) { } else if (key == BYMONTHDAY && value.toInt() == -1) {
curRepeatRule = REPEAT_MONTH_LAST_DAY curRepeatRule = REPEAT_MONTH_LAST_DAY
} }