mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
updating some constants in preparation for advanced yearly repetition rules
This commit is contained in:
parent
c2d120b99d
commit
59486f98d0
@ -221,7 +221,7 @@ class EventActivity : SimpleActivity() {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
setRepeatRule(REPEAT_MONTH_SAME_DAY)
|
||||
setRepeatRule(REPEAT_SAME_DAY)
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,7 +229,7 @@ class EventActivity : SimpleActivity() {
|
||||
event_repetition_limit_holder.beGoneIf(limit == 0)
|
||||
checkRepetitionLimitText()
|
||||
|
||||
event_repetition_rule_holder.beVisibleIf(mRepeatInterval.isXWeeklyRepetition() || mRepeatInterval.isXMonthlyRepetition())
|
||||
event_repetition_rule_holder.beVisibleIf(mRepeatInterval.isXWeeklyRepetition() || mRepeatInterval.isXMonthlyRepetition() || mRepeatInterval.isXYearlyRepetition())
|
||||
checkRepetitionRuleText()
|
||||
}
|
||||
|
||||
@ -270,23 +270,23 @@ class EventActivity : SimpleActivity() {
|
||||
setRepeatRule(it)
|
||||
}
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
val items = arrayListOf(RadioItem(REPEAT_MONTH_SAME_DAY, getString(R.string.repeat_on_the_same_day)))
|
||||
val items = arrayListOf(RadioItem(REPEAT_SAME_DAY, getString(R.string.repeat_on_the_same_day)))
|
||||
|
||||
// split Every Last Sunday and Every Fourth Sunday of the month, if the month has 4 sundays
|
||||
if (isLastWeekDayOfMonth()) {
|
||||
val order = (mEventStartDateTime.dayOfMonth - 1) / 7 + 1
|
||||
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)))
|
||||
items.add(RadioItem(REPEAT_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_ORDER_WEEKDAY)))
|
||||
items.add(RadioItem(REPEAT_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_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_ORDER_WEEKDAY_USE_LAST, getRepeatXthDayString(true, REPEAT_ORDER_WEEKDAY_USE_LAST)))
|
||||
}
|
||||
} else {
|
||||
items.add(RadioItem(REPEAT_MONTH_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_MONTH_ORDER_WEEKDAY)))
|
||||
items.add(RadioItem(REPEAT_ORDER_WEEKDAY, getRepeatXthDayString(true, REPEAT_ORDER_WEEKDAY)))
|
||||
}
|
||||
|
||||
if (isLastDayOfTheMonth()) {
|
||||
items.add(RadioItem(REPEAT_MONTH_LAST_DAY, getString(R.string.repeat_on_the_last_day)))
|
||||
items.add(RadioItem(REPEAT_LAST_DAY, getString(R.string.repeat_on_the_last_day)))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items, mRepeatRule) {
|
||||
@ -325,7 +325,7 @@ class EventActivity : SimpleActivity() {
|
||||
private fun getOrderString(repeatRule: Int): String {
|
||||
val dayOfMonth = mEventStartDateTime.dayOfMonth
|
||||
var order = (dayOfMonth - 1) / 7 + 1
|
||||
if (order == 4 && isLastWeekDayOfMonth() && repeatRule == REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST) {
|
||||
if (order == 4 && isLastWeekDayOfMonth() && repeatRule == REPEAT_ORDER_WEEKDAY_USE_LAST) {
|
||||
order = -1
|
||||
}
|
||||
|
||||
@ -360,20 +360,26 @@ class EventActivity : SimpleActivity() {
|
||||
}
|
||||
|
||||
private fun checkRepetitionRuleText() {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
event_repetition_rule.text = if (mRepeatRule == EVERY_DAY_BIT) getString(R.string.every_day) else getSelectedDaysString(mRepeatRule)
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
val repeatString = if (mRepeatRule == REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST || mRepeatRule == REPEAT_MONTH_ORDER_WEEKDAY)
|
||||
R.string.repeat else R.string.repeat_on
|
||||
when {
|
||||
mRepeatInterval.isXWeeklyRepetition() -> {
|
||||
event_repetition_rule.text = if (mRepeatRule == EVERY_DAY_BIT) getString(R.string.every_day) else getSelectedDaysString(mRepeatRule)
|
||||
}
|
||||
mRepeatInterval.isXMonthlyRepetition() -> {
|
||||
val repeatString = if (mRepeatRule == REPEAT_ORDER_WEEKDAY_USE_LAST || mRepeatRule == REPEAT_ORDER_WEEKDAY)
|
||||
R.string.repeat else R.string.repeat_on
|
||||
|
||||
event_repetition_rule_label.text = getString(repeatString)
|
||||
event_repetition_rule.text = getMonthlyRepetitionRuleText()
|
||||
event_repetition_rule_label.text = getString(repeatString)
|
||||
event_repetition_rule.text = getMonthlyRepetitionRuleText()
|
||||
}
|
||||
mRepeatInterval.isXYearlyRepetition() -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMonthlyRepetitionRuleText() = when (mRepeatRule) {
|
||||
REPEAT_MONTH_SAME_DAY -> getString(R.string.the_same_day)
|
||||
REPEAT_MONTH_LAST_DAY -> getString(R.string.the_last_day)
|
||||
REPEAT_SAME_DAY -> getString(R.string.the_same_day)
|
||||
REPEAT_LAST_DAY -> getString(R.string.the_last_day)
|
||||
else -> getRepeatXthDayString(false, mRepeatRule)
|
||||
}
|
||||
|
||||
@ -804,8 +810,8 @@ class EventActivity : SimpleActivity() {
|
||||
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||
}
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
if (mRepeatRule == REPEAT_MONTH_LAST_DAY && !isLastDayOfTheMonth())
|
||||
mRepeatRule = REPEAT_MONTH_SAME_DAY
|
||||
if (mRepeatRule == REPEAT_LAST_DAY && !isLastDayOfTheMonth())
|
||||
mRepeatRule = REPEAT_SAME_DAY
|
||||
checkRepetitionRuleText()
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.simplemobiletools.calendar.extensions
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
import com.simplemobiletools.calendar.helpers.MONTH
|
||||
import com.simplemobiletools.calendar.helpers.WEEK
|
||||
import com.simplemobiletools.calendar.helpers.YEAR
|
||||
import com.simplemobiletools.calendar.models.Event
|
||||
|
||||
fun Int.isTsOnProperDay(event: Event): Boolean {
|
||||
@ -14,3 +15,5 @@ fun Int.isTsOnProperDay(event: Event): Boolean {
|
||||
fun Int.isXWeeklyRepetition() = this != 0 && this % WEEK == 0
|
||||
|
||||
fun Int.isXMonthlyRepetition() = this != 0 && this % MONTH == 0
|
||||
|
||||
fun Int.isXYearlyRepetition() = this != 0 && this % YEAR == 0
|
||||
|
@ -54,10 +54,10 @@ const val LOOP_REMINDERS = "loop_reminders"
|
||||
const val DIM_PAST_EVENTS = "dim_past_events"
|
||||
|
||||
// repeat_rule for monthly repetition
|
||||
const val REPEAT_MONTH_SAME_DAY = 1 // ie 25th every month
|
||||
const val REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST = 2 // ie every xth sunday. 4th if a month has 4 sundays, 5th if 5
|
||||
const val REPEAT_MONTH_LAST_DAY = 3 // ie every last day of the month
|
||||
const 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)
|
||||
const val REPEAT_SAME_DAY = 1 // i.e. 25th every month, or 3rd june (if yearly repetition)
|
||||
const val REPEAT_ORDER_WEEKDAY_USE_LAST = 2 // i.e. every last sunday. 4th if a month has 4 sundays, 5th if 5 (or last sunday in june, if yearly)
|
||||
const val REPEAT_LAST_DAY = 3 // i.e. every last day of the month
|
||||
const val REPEAT_ORDER_WEEKDAY = 4 // i.e. every 4th sunday, even if a month has 4 sundays only (will stay 4th even at months with 5)
|
||||
|
||||
// special event flags
|
||||
const val FLAG_ALL_DAY = 1
|
||||
|
@ -915,7 +915,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
}
|
||||
|
||||
if (repeatInterval > 0 && repeatInterval % MONTH == 0 && repeatRule == 0) {
|
||||
repeatRule = REPEAT_MONTH_SAME_DAY
|
||||
repeatRule = REPEAT_SAME_DAY
|
||||
}
|
||||
|
||||
val isPastEvent = endTS < getNowSeconds()
|
||||
@ -1033,7 +1033,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
val start = cursor.getIntValue(COL_REPEAT_START)
|
||||
var rule = Math.pow(2.0, (Formatter.getDateTimeFromTS(start).dayOfWeek - 1).toDouble()).toInt()
|
||||
if (interval == MONTH) {
|
||||
rule = REPEAT_MONTH_SAME_DAY
|
||||
rule = REPEAT_SAME_DAY
|
||||
}
|
||||
|
||||
val values = ContentValues()
|
||||
|
@ -30,7 +30,7 @@ class Parser {
|
||||
val start = Formatter.getDateTimeFromTS(startTS)
|
||||
repeatRule = Math.pow(2.0, (start.dayOfWeek - 1).toDouble()).toInt()
|
||||
} else if (value == MONTHLY) {
|
||||
repeatRule = REPEAT_MONTH_SAME_DAY
|
||||
repeatRule = REPEAT_SAME_DAY
|
||||
}
|
||||
} else if (key == COUNT) {
|
||||
repeatLimit = -value.toInt()
|
||||
@ -42,10 +42,10 @@ class Parser {
|
||||
if (repeatInterval.isXWeeklyRepetition()) {
|
||||
repeatRule = handleRepeatRule(value)
|
||||
} else if (repeatInterval.isXMonthlyRepetition()) {
|
||||
repeatRule = if (value.startsWith("-1")) REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST else REPEAT_MONTH_ORDER_WEEKDAY
|
||||
repeatRule = if (value.startsWith("-1")) REPEAT_ORDER_WEEKDAY_USE_LAST else REPEAT_ORDER_WEEKDAY
|
||||
}
|
||||
} else if (key == BYMONTHDAY && value.toInt() == -1) {
|
||||
repeatRule = REPEAT_MONTH_LAST_DAY
|
||||
repeatRule = REPEAT_LAST_DAY
|
||||
}
|
||||
}
|
||||
return RepeatRule(repeatInterval, repeatRule, repeatLimit)
|
||||
@ -133,8 +133,8 @@ class Parser {
|
||||
";$BYDAY=$days"
|
||||
}
|
||||
event.repeatInterval.isXMonthlyRepetition() -> when (event.repeatRule) {
|
||||
REPEAT_MONTH_LAST_DAY -> ";$BYMONTHDAY=-1"
|
||||
REPEAT_MONTH_ORDER_WEEKDAY_USE_LAST, REPEAT_MONTH_ORDER_WEEKDAY -> {
|
||||
REPEAT_LAST_DAY -> ";$BYMONTHDAY=-1"
|
||||
REPEAT_ORDER_WEEKDAY_USE_LAST, REPEAT_ORDER_WEEKDAY -> {
|
||||
val start = Formatter.getDateTimeFromTS(event.startTS)
|
||||
val dayOfMonth = start.dayOfMonth
|
||||
val isLastWeekday = start.monthOfYear != start.plusDays(7).monthOfYear
|
||||
|
@ -31,9 +31,9 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
||||
val newStart = when {
|
||||
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_SAME_DAY -> addMonthsWithSameDay(currStart, original)
|
||||
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true)
|
||||
REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false)
|
||||
else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue()
|
||||
}
|
||||
repeatInterval % WEEK == 0 -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user