show the day picker at multiple week repetition too
This commit is contained in:
parent
db6c7e5738
commit
b620a7c2e9
|
@ -152,7 +152,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
updateRepetitionText()
|
||||
checkRepeatTexts(interval)
|
||||
|
||||
if (mRepeatInterval == WEEK) {
|
||||
if (isXWeeklyRepetition()) {
|
||||
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt())
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
event_repetition_limit_holder.beGoneIf(limit == 0)
|
||||
checkRepetitionLimitText()
|
||||
|
||||
event_repetition_rule_holder.beVisibleIf(mRepeatInterval == WEEK)
|
||||
event_repetition_rule_holder.beVisibleIf(isXWeeklyRepetition())
|
||||
checkRepetitionRuleText()
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun showRepetitionRuleDialog() {
|
||||
if (mRepeatInterval == WEEK) {
|
||||
if (isXWeeklyRepetition()) {
|
||||
RepeatRuleDailyDialog(this, mRepeatRule) {
|
||||
setRepeatRule(it)
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
|
||||
private fun checkRepetitionRuleText() {
|
||||
if (mRepeatInterval == WEEK) {
|
||||
if (isXWeeklyRepetition()) {
|
||||
event_repetition_rule.text = getString(if (mRepeatRule == EVERY_DAY) R.string.every_day else R.string.selected_days)
|
||||
}
|
||||
}
|
||||
|
@ -273,11 +273,13 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
}
|
||||
}
|
||||
|
||||
fun toggleAllDay(isChecked: Boolean) {
|
||||
private fun toggleAllDay(isChecked: Boolean) {
|
||||
event_start_time.beGoneIf(isChecked)
|
||||
event_end_time.beGoneIf(isChecked)
|
||||
}
|
||||
|
||||
private fun isXWeeklyRepetition() = mRepeatInterval != 0 && mRepeatInterval % WEEK == 0
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_event, menu)
|
||||
menu.findItem(R.id.cab_delete).isVisible = mEvent.id != 0
|
||||
|
|
|
@ -56,7 +56,7 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
|||
val reminderSeconds = event.getReminders().reversed().map { it * 60 }
|
||||
reminderSeconds.forEach {
|
||||
var startTS = event.startTS - it
|
||||
if (event.repeatInterval == DAY || event.repeatInterval == WEEK) {
|
||||
if (event.repeatInterval == DAY || (event.repeatInterval != 0 && event.repeatInterval % WEEK == 0)) {
|
||||
while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) {
|
||||
startTS += DAY
|
||||
}
|
||||
|
|
|
@ -381,22 +381,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
// get repeatable events
|
||||
val selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS < $toTS"
|
||||
val events = getEvents(selection)
|
||||
for (event in events) {
|
||||
while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) {
|
||||
if (event.startTS >= fromTS) {
|
||||
if (event.repeatInterval == WEEK) {
|
||||
val dateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||
events.forEach {
|
||||
while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
|
||||
if (it.startTS >= fromTS) {
|
||||
if (it.repeatInterval % WEEK == 0) {
|
||||
val dateTime = Formatter.getDateTimeFromTS(it.startTS)
|
||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||
if (event.repeatRule and power != 0) {
|
||||
newEvents.add(event.copy())
|
||||
if (it.repeatRule and power != 0) {
|
||||
newEvents.add(it.copy())
|
||||
}
|
||||
} else {
|
||||
newEvents.add(event.copy())
|
||||
newEvents.add(it.copy())
|
||||
}
|
||||
} else if (getRunningEvents && (event.startTS <= fromTS && event.endTS >= toTS)) {
|
||||
newEvents.add(event.copy())
|
||||
} else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) {
|
||||
newEvents.add(it.copy())
|
||||
}
|
||||
event.addIntervalTime()
|
||||
it.addIntervalTime()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,17 +591,20 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
private fun setupRepeatRules(db: SQLiteDatabase) {
|
||||
val projection = arrayOf(COL_EVENT_ID, COL_REPEAT_INTERVAL)
|
||||
val selection = "$COL_REPEAT_INTERVAL = ? OR $COL_REPEAT_INTERVAL = ?"
|
||||
val selectionArgs = arrayOf(DAY.toString(), MONTH.toString())
|
||||
val projection = arrayOf(COL_EVENT_ID, COL_REPEAT_INTERVAL, COL_REPEAT_START)
|
||||
val selection = "$COL_REPEAT_INTERVAL != 0"
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = db.query(META_TABLE_NAME, projection, selection, selectionArgs, null, null, null)
|
||||
cursor = db.query(META_TABLE_NAME, projection, selection, null, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val eventId = cursor.getIntValue(COL_EVENT_ID)
|
||||
val interval = cursor.getIntValue(COL_REPEAT_INTERVAL)
|
||||
var rule = EVERY_DAY
|
||||
if (interval != MONTH && interval % WEEK != 0)
|
||||
continue
|
||||
|
||||
val eventId = cursor.getIntValue(COL_EVENT_ID)
|
||||
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
|
||||
}
|
||||
|
|
|
@ -20,12 +20,15 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
|||
val currStart = Formatter.getDateTimeFromTS(startTS)
|
||||
val newStart: DateTime
|
||||
newStart = when (repeatInterval) {
|
||||
DAY, WEEK -> currStart.plusDays(1) // step through weekly repetition by days too, as it can trigger multiple times a week
|
||||
DAY -> currStart.plusDays(1)
|
||||
else -> {
|
||||
if (repeatInterval % YEAR == 0) {
|
||||
currStart.plusYears(repeatInterval / YEAR)
|
||||
} else if (repeatInterval % MONTH == 0) {
|
||||
currStart.plusMonths(repeatInterval / MONTH)
|
||||
} else if (repeatInterval % WEEK == 0) {
|
||||
// step through weekly repetition by days too, as events can trigger multiple times a week
|
||||
currStart.plusDays(1)
|
||||
} else {
|
||||
currStart.plusSeconds(repeatInterval)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue