mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
improve the repeatition of events repeating by x weeks
This commit is contained in:
@@ -3,7 +3,7 @@ package com.simplemobiletools.calendar.extensions
|
|||||||
import com.simplemobiletools.calendar.helpers.Formatter
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
import com.simplemobiletools.calendar.models.Event
|
import com.simplemobiletools.calendar.models.Event
|
||||||
|
|
||||||
fun Int.isTsOnValidDay(event: Event): Boolean {
|
fun Int.isTsOnProperDay(event: Event): Boolean {
|
||||||
val dateTime = Formatter.getDateTimeFromTS(this)
|
val dateTime = Formatter.getDateTimeFromTS(this)
|
||||||
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
|
||||||
return event.repeatRule and power != 0
|
return event.repeatRule and power != 0
|
||||||
|
@@ -391,7 +391,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
|
while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
|
||||||
if (it.startTS >= fromTS) {
|
if (it.startTS >= fromTS) {
|
||||||
if (it.repeatInterval % WEEK == 0) {
|
if (it.repeatInterval % WEEK == 0) {
|
||||||
if (it.startTS.isTsOnValidDay(it)) {
|
if (it.startTS.isTsOnProperDay(it)) {
|
||||||
newEvents.add(it.copy())
|
newEvents.add(it.copy())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -406,39 +406,31 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
// events repeating x times
|
// events repeating x times
|
||||||
while (it.repeatLimit < 0 && it.endTS < toTS) {
|
while (it.repeatLimit < 0 && it.endTS < toTS) {
|
||||||
if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) {
|
if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) {
|
||||||
if (it.startTS.isTsOnValidDay(it)) {
|
if (it.startTS.isTsOnProperDay(it)) {
|
||||||
if (it.startTS >= fromTS && it.startTS < toTS) {
|
|
||||||
newEvents.add(it.copy())
|
|
||||||
}
|
|
||||||
it.repeatLimit++
|
|
||||||
}
|
|
||||||
it.addIntervalTime()
|
|
||||||
} else {
|
|
||||||
if (it.startTS >= fromTS && it.startTS < toTS) {
|
|
||||||
newEvents.add(it.copy())
|
|
||||||
}
|
|
||||||
it.addIntervalTime()
|
|
||||||
it.repeatLimit++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if weekly repeatable events are on the correct day
|
|
||||||
val filteredEvents = ArrayList<Event>(newEvents.size)
|
|
||||||
newEvents.forEach {
|
|
||||||
if (it.repeatInterval != 0 && it.repeatInterval % WEEK == 0) {
|
|
||||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[it.id]).weekOfWeekyear
|
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[it.id]).weekOfWeekyear
|
||||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(it.startTS).weekOfWeekyear
|
val currentWeekOfYear = Formatter.getDateTimeFromTS(it.startTS).weekOfWeekyear
|
||||||
|
|
||||||
|
// check if its the proper week, for events repeating by x weeks
|
||||||
if ((currentWeekOfYear - initialWeekOfYear) % (it.repeatInterval / WEEK) == 0) {
|
if ((currentWeekOfYear - initialWeekOfYear) % (it.repeatInterval / WEEK) == 0) {
|
||||||
filteredEvents.add(it)
|
if (it.startTS >= fromTS && it.startTS < toTS) {
|
||||||
|
newEvents.add(it.copy())
|
||||||
}
|
}
|
||||||
|
it.repeatLimit++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
it.addIntervalTime()
|
||||||
} else {
|
} else {
|
||||||
filteredEvents.add(it)
|
if (it.startTS >= fromTS && it.startTS < toTS) {
|
||||||
|
newEvents.add(it.copy())
|
||||||
|
}
|
||||||
|
it.addIntervalTime()
|
||||||
|
it.repeatLimit++
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredEvents
|
return newEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRunningEvents(): List<Event> {
|
fun getRunningEvents(): List<Event> {
|
||||||
|
Reference in New Issue
Block a user