show the day picker at multiple week repetition too

This commit is contained in:
tibbi
2017-04-15 22:27:35 +02:00
parent db6c7e5738
commit b620a7c2e9
4 changed files with 32 additions and 24 deletions

View File

@@ -152,7 +152,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
updateRepetitionText() updateRepetitionText()
checkRepeatTexts(interval) checkRepeatTexts(interval)
if (mRepeatInterval == WEEK) { if (isXWeeklyRepetition()) {
setRepeatRule(Math.pow(2.0, (mEventStartDateTime.dayOfWeek - 1).toDouble()).toInt()) 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) event_repetition_limit_holder.beGoneIf(limit == 0)
checkRepetitionLimitText() checkRepetitionLimitText()
event_repetition_rule_holder.beVisibleIf(mRepeatInterval == WEEK) event_repetition_rule_holder.beVisibleIf(isXWeeklyRepetition())
checkRepetitionRuleText() checkRepetitionRuleText()
} }
@@ -192,7 +192,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} }
private fun showRepetitionRuleDialog() { private fun showRepetitionRuleDialog() {
if (mRepeatInterval == WEEK) { if (isXWeeklyRepetition()) {
RepeatRuleDailyDialog(this, mRepeatRule) { RepeatRuleDailyDialog(this, mRepeatRule) {
setRepeatRule(it) setRepeatRule(it)
} }
@@ -208,7 +208,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
} }
private fun checkRepetitionRuleText() { 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) 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_start_time.beGoneIf(isChecked)
event_end_time.beGoneIf(isChecked) event_end_time.beGoneIf(isChecked)
} }
private fun isXWeeklyRepetition() = mRepeatInterval != 0 && mRepeatInterval % WEEK == 0
override fun onCreateOptionsMenu(menu: Menu): Boolean { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_event, menu) menuInflater.inflate(R.menu.menu_event, menu)
menu.findItem(R.id.cab_delete).isVisible = mEvent.id != 0 menu.findItem(R.id.cab_delete).isVisible = mEvent.id != 0

View File

@@ -56,7 +56,7 @@ fun Context.scheduleNextEventReminder(event: Event) {
val reminderSeconds = event.getReminders().reversed().map { it * 60 } val reminderSeconds = event.getReminders().reversed().map { it * 60 }
reminderSeconds.forEach { reminderSeconds.forEach {
var startTS = event.startTS - it 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)) { while (startTS < now || isOccurrenceIgnored(event, startTS, it) || isWrongDay(event, startTS, it)) {
startTS += DAY startTS += DAY
} }

View File

@@ -381,22 +381,22 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
// get repeatable events // get repeatable events
val selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS < $toTS" val selection = "$COL_REPEAT_INTERVAL != 0 AND $COL_START_TS < $toTS"
val events = getEvents(selection) val events = getEvents(selection)
for (event in events) { events.forEach {
while (event.startTS < toTS && (event.repeatLimit == 0 || event.repeatLimit >= event.startTS)) { while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
if (event.startTS >= fromTS) { if (it.startTS >= fromTS) {
if (event.repeatInterval == WEEK) { if (it.repeatInterval % WEEK == 0) {
val dateTime = Formatter.getDateTimeFromTS(event.startTS) val dateTime = Formatter.getDateTimeFromTS(it.startTS)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt() val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
if (event.repeatRule and power != 0) { if (it.repeatRule and power != 0) {
newEvents.add(event.copy()) newEvents.add(it.copy())
} }
} else { } else {
newEvents.add(event.copy()) newEvents.add(it.copy())
} }
} else if (getRunningEvents && (event.startTS <= fromTS && event.endTS >= toTS)) { } else if (getRunningEvents && (it.startTS <= fromTS && it.endTS >= toTS)) {
newEvents.add(event.copy()) 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) { private fun setupRepeatRules(db: SQLiteDatabase) {
val projection = arrayOf(COL_EVENT_ID, COL_REPEAT_INTERVAL) val projection = arrayOf(COL_EVENT_ID, COL_REPEAT_INTERVAL, COL_REPEAT_START)
val selection = "$COL_REPEAT_INTERVAL = ? OR $COL_REPEAT_INTERVAL = ?" val selection = "$COL_REPEAT_INTERVAL != 0"
val selectionArgs = arrayOf(DAY.toString(), MONTH.toString())
var cursor: Cursor? = null var cursor: Cursor? = null
try { 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) { if (cursor?.moveToFirst() == true) {
do { do {
val eventId = cursor.getIntValue(COL_EVENT_ID)
val interval = cursor.getIntValue(COL_REPEAT_INTERVAL) 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) { if (interval == MONTH) {
rule = REPEAT_MONTH_SAME_DAY rule = REPEAT_MONTH_SAME_DAY
} }

View File

@@ -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 currStart = Formatter.getDateTimeFromTS(startTS)
val newStart: DateTime val newStart: DateTime
newStart = when (repeatInterval) { 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 -> { else -> {
if (repeatInterval % YEAR == 0) { if (repeatInterval % YEAR == 0) {
currStart.plusYears(repeatInterval / YEAR) currStart.plusYears(repeatInterval / YEAR)
} else if (repeatInterval % MONTH == 0) { } else if (repeatInterval % MONTH == 0) {
currStart.plusMonths(repeatInterval / MONTH) 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 { } else {
currStart.plusSeconds(repeatInterval) currStart.plusSeconds(repeatInterval)
} }