From 078db574caa017a442fd02198c71388d9af9ffe2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 25 Nov 2017 23:27:51 +0100 Subject: [PATCH] improve some monthly repetition rules --- .../calendar/activities/EventActivity.kt | 12 +++++++++--- .../simplemobiletools/calendar/helpers/Constants.kt | 8 ++++---- .../com/simplemobiletools/calendar/models/Event.kt | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index f4dd4a493..ea7d4286b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -235,7 +235,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { if (isLastWeekDayOfMonth()) { val order = (mEventStartDateTime.dayOfMonth - 1) / 7 + 1 if (order == 4) { - items.add(RadioItem(REPEAT_MONTH_LAST_WEEKDAY, getRepeatXthDayString(true, REPEAT_MONTH_LAST_WEEKDAY))) + items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST))) } } @@ -278,7 +278,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { private fun getOrderString(repeatRule: Int): String { val dayOfMonth = mEventStartDateTime.dayOfMonth - val order = if (repeatRule == REPEAT_MONTH_LAST_WEEKDAY) -1 else (dayOfMonth - 1) / 7 + 1 + var order = (dayOfMonth - 1) / 7 + 1 + if (order == 4 && repeatRule == REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST) { + order = -1 + } + val isMale = isMaleGender(mEventStartDateTime.dayOfWeek) return getString(when (order) { 1 -> if (isMale) R.string.first_m else R.string.first_f @@ -313,7 +317,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { if (mRepeatInterval.isXWeeklyRepetition()) { event_repetition_rule.text = if (mRepeatRule == EVERY_DAY) getString(R.string.every_day) else getSelectedDaysString() } else if (mRepeatInterval.isXMonthlyRepetition()) { - val repeatString = if (mRepeatRule == REPEAT_MONTH_ORDER_WEEKDAY || mRepeatRule == REPEAT_MONTH_LAST_WEEKDAY) R.string.repeat else R.string.repeat_on + val repeatString = if (mRepeatRule == REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST || mRepeatRule == REPEAT_MONTH_ORDER_WEEKDAY) + R.string.repeat else R.string.repeat_on + event_repetition_rule_label.text = getString(repeatString) event_repetition_rule.text = getMonthlyRepetitionRuleText() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index c1d8c533b..5d6abcd6a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -64,10 +64,10 @@ val SUNDAY = 64 val EVERY_DAY = 127 // repeat_rule for monthly repetition -val REPEAT_MONTH_SAME_DAY = 1 // ie 25th every month -val REPEAT_MONTH_ORDER_WEEKDAY = 2 // ie every 4th sunday, even if a month has 4 sundays only (will stay 4th even at months with 5) -val REPEAT_MONTH_LAST_DAY = 3 // ie every last day of the month -val REPEAT_MONTH_LAST_WEEKDAY = 4 // ie every last sunday +val REPEAT_MONTH_SAME_DAY = 1 // ie 25th every month +val REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST = 2 // ie every xth sunday. 4th if a month has 4 sundays, 5th if 5 +val REPEAT_MONTH_LAST_DAY = 3 // ie every last day of the month +val REPEAT_MONTH_ORDER_WEEKDAY = 4 // ie every 4th sunday, even if a month has 4 sundays only (will stay 4th even at months with 5) // special event flags val FLAG_ALL_DAY = 1 diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index 4b201e91e..8f9a2e3ba 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -28,8 +28,8 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var repeatInterval % YEAR == 0 -> currStart.plusYears(repeatInterval / YEAR) repeatInterval % MONTH == 0 -> when (repeatRule) { REPEAT_MONTH_SAME_DAY -> addMonthsWithSameDay(currStart, original) + REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true) REPEAT_MONTH_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false) - REPEAT_MONTH_LAST_WEEKDAY -> addXthDayInterval(currStart, original, true) else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue() } repeatInterval % WEEK == 0 -> {