create helper extension functions for checking xweekly and xmonthly repetition
This commit is contained in:
parent
fbdc667b8f
commit
0463f176ea
|
@ -167,9 +167,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
updateRepetitionText()
|
||||
checkRepeatTexts(interval)
|
||||
|
||||
if (isXWeeklyRepetition()) {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||
} else if (isXMonthlyRepetition()) {
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
setRepeatRule(REPEAT_MONTH_SAME_DAY)
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
event_repetition_limit_holder.beGoneIf(limit == 0)
|
||||
checkRepetitionLimitText()
|
||||
|
||||
event_repetition_rule_holder.beVisibleIf(isXWeeklyRepetition() || isXMonthlyRepetition())
|
||||
event_repetition_rule_holder.beVisibleIf(mRepeatInterval.isXWeeklyRepetition() || mRepeatInterval.isXMonthlyRepetition())
|
||||
checkRepetitionRuleText()
|
||||
}
|
||||
|
||||
|
@ -210,11 +210,11 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
|
||||
private fun showRepetitionRuleDialog() {
|
||||
hideKeyboard()
|
||||
if (isXWeeklyRepetition()) {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
RepeatRuleWeeklyDialog(this, mRepeatRule) {
|
||||
setRepeatRule(it)
|
||||
}
|
||||
} else if (isXMonthlyRepetition()) {
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
val items = arrayListOf(
|
||||
RadioItem(REPEAT_MONTH_SAME_DAY, getString(R.string.repeat_on_the_same_day)),
|
||||
RadioItem(REPEAT_MONTH_EVERY_XTH_DAY, getRepeatXthDayString(true)))
|
||||
|
@ -292,9 +292,9 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun checkRepetitionRuleText() {
|
||||
if (isXWeeklyRepetition()) {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
event_repetition_rule.text = if (mRepeatRule == EVERY_DAY) getString(R.string.every_day) else getSelectedDaysString()
|
||||
} else if (isXMonthlyRepetition()) {
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
event_repetition_rule_label.text = getString(if (mRepeatRule == REPEAT_MONTH_EVERY_XTH_DAY) R.string.repeat else R.string.repeat_on)
|
||||
event_repetition_rule.text = getMonthlyRepetitionRuleText()
|
||||
}
|
||||
|
@ -395,10 +395,6 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
event_end_time.beGoneIf(isChecked)
|
||||
}
|
||||
|
||||
private fun isXWeeklyRepetition() = mRepeatInterval != 0 && mRepeatInterval % WEEK == 0
|
||||
|
||||
private fun isXMonthlyRepetition() = mRepeatInterval != 0 && mRepeatInterval % MONTH == 0
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_event, menu)
|
||||
menu.findItem(R.id.delete).isVisible = mEvent.id != 0
|
||||
|
@ -576,12 +572,12 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun checkRepeatRule() {
|
||||
if (isXWeeklyRepetition()) {
|
||||
if (mRepeatInterval.isXWeeklyRepetition()) {
|
||||
val day = mRepeatRule
|
||||
if (day == MONDAY || day == TUESDAY || day == WEDNESDAY || day == THURSDAY || day == FRIDAY || day == SATURDAY || day == SUNDAY) {
|
||||
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||
}
|
||||
} else if (isXMonthlyRepetition()) {
|
||||
} else if (mRepeatInterval.isXMonthlyRepetition()) {
|
||||
checkRepetitionRuleText()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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.models.Event
|
||||
|
||||
fun Int.isTsOnProperDay(event: Event): Boolean {
|
||||
|
@ -8,3 +10,7 @@ fun Int.isTsOnProperDay(event: Event): Boolean {
|
|||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
return event.repeatRule and power != 0
|
||||
}
|
||||
|
||||
fun Int.isXWeeklyRepetition() = this != 0 && this % WEEK == 0
|
||||
|
||||
fun Int.isXMonthlyRepetition() = this != 0 && this % MONTH == 0
|
||||
|
|
|
@ -400,7 +400,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
val events = ArrayList<Event>()
|
||||
while (event.startTS <= toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
|
||||
if (event.endTS >= fromTS) {
|
||||
if (event.isRepeatingByXWeeks()) {
|
||||
if (event.repeatInterval.isXWeeklyRepetition()) {
|
||||
if (event.startTS.isTsOnProperDay(event)) {
|
||||
if (isOnProperWeek(event, startTimes)) {
|
||||
events.add(event.copy())
|
||||
|
@ -418,7 +418,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
private fun getEventsRepeatingXTimes(fromTS: Int, toTS: Int, startTimes: SparseIntArray, event: Event): ArrayList<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
while (event.repeatLimit < 0 && event.startTS <= toTS) {
|
||||
if (event.isRepeatingByXWeeks()) {
|
||||
if (event.repeatInterval.isXWeeklyRepetition()) {
|
||||
if (event.startTS.isTsOnProperDay(event)) {
|
||||
if (isOnProperWeek(event, startTimes)) {
|
||||
if (event.endTS >= fromTS) {
|
||||
|
|
|
@ -43,6 +43,4 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
|||
val isAllDay = flags and FLAG_ALL_DAY != 0
|
||||
|
||||
fun getReminders() = setOf(reminder1Minutes, reminder2Minutes, reminder3Minutes).filter { it != REMINDER_OFF }
|
||||
|
||||
fun isRepeatingByXWeeks() = repeatInterval > 0 && repeatInterval % WEEK == 0
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue