fix importing and exporting new monthly repetition types

This commit is contained in:
tibbi 2017-11-26 00:12:14 +01:00
parent 078db574ca
commit 9785900e21
3 changed files with 12 additions and 9 deletions

View File

@ -227,16 +227,19 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
setRepeatRule(it) setRepeatRule(it)
} }
} else if (mRepeatInterval.isXMonthlyRepetition()) { } else if (mRepeatInterval.isXMonthlyRepetition()) {
val items = arrayListOf( val items = arrayListOf(RadioItem(REPEAT_MONTH_SAME_DAY, getString(R.string.repeat_on_the_same_day)))
RadioItem(REPEAT_MONTH_SAME_DAY, getString(R.string.repeat_on_the_same_day)),
RadioItem(REPEAT_MONTH_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY)))
// split Every Last Sunday and Every Fourth Sunday of the month, if the month has 4 sundays // split Every Last Sunday and Every Fourth Sunday of the month, if the month has 4 sundays
if (isLastWeekDayOfMonth()) { if (isLastWeekDayOfMonth()) {
val order = (mEventStartDateTime.dayOfMonth - 1) / 7 + 1 val order = (mEventStartDateTime.dayOfMonth - 1) / 7 + 1
if (order == 4) { if (order == 4) {
items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY)))
items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST)))
} else if (order == 5) {
items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST))) items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST)))
} }
} else {
items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY)))
} }
if (isLastDayOfTheMonth()) { if (isLastDayOfTheMonth()) {

View File

@ -57,7 +57,6 @@ class IcsExporter {
out.writeLn(END_CALENDAR) out.writeLn(END_CALENDAR)
} }
callback(when { callback(when {
eventsExported == 0 -> EXPORT_FAIL eventsExported == 0 -> EXPORT_FAIL
eventsFailed > 0 -> EXPORT_PARTIAL eventsFailed > 0 -> EXPORT_PARTIAL

View File

@ -41,7 +41,7 @@ class Parser {
if (repeatInterval.isXWeeklyRepetition()) { if (repeatInterval.isXWeeklyRepetition()) {
repeatRule = handleRepeatRule(value) repeatRule = handleRepeatRule(value)
} else if (repeatInterval.isXMonthlyRepetition()) { } else if (repeatInterval.isXMonthlyRepetition()) {
repeatRule = REPEAT_MONTH_ORDER_WEEKDAY repeatRule = if (value.startsWith("-1")) REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST else REPEAT_MONTH_ORDER_WEEKDAY
} }
} else if (key == BYMONTHDAY && value.toInt() == -1) { } else if (key == BYMONTHDAY && value.toInt() == -1) {
repeatRule = REPEAT_MONTH_LAST_DAY repeatRule = REPEAT_MONTH_LAST_DAY
@ -131,12 +131,13 @@ class Parser {
val days = getByDayString(event.repeatRule) val days = getByDayString(event.repeatRule)
";$BYDAY=$days" ";$BYDAY=$days"
} }
event.repeatInterval.isXMonthlyRepetition() -> when { event.repeatInterval.isXMonthlyRepetition() -> when (event.repeatRule) {
event.repeatRule == REPEAT_MONTH_LAST_DAY -> ";$BYMONTHDAY=-1" REPEAT_MONTH_LAST_DAY -> ";$BYMONTHDAY=-1"
event.repeatRule == REPEAT_MONTH_ORDER_WEEKDAY -> { REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, REPEAT_MONTH_ORDER_WEEKDAY -> {
val start = Formatter.getDateTimeFromTS(event.startTS) val start = Formatter.getDateTimeFromTS(event.startTS)
val dayOfMonth = start.dayOfMonth val dayOfMonth = start.dayOfMonth
val order = (dayOfMonth - 1) / 7 + 1 val isLastWeekday = start.monthOfYear != start.plusDays(7).monthOfYear
val order = if (isLastWeekday) "-1" else ((dayOfMonth - 1) / 7 + 1).toString()
val day = getDayLetters(start.dayOfWeek) val day = getDayLetters(start.dayOfWeek)
";$BYDAY=$order$day" ";$BYDAY=$order$day"
} }