improve some monthly repetition rules

This commit is contained in:
tibbi 2017-11-25 23:27:51 +01:00
parent a89072e244
commit 078db574ca
3 changed files with 14 additions and 8 deletions

View file

@ -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()
}

View file

@ -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

View file

@ -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 -> {