use ignored event daycodes instead of timestamps
This commit is contained in:
parent
829646b6a0
commit
d63e6f30b2
6 changed files with 21 additions and 14 deletions
|
@ -57,7 +57,7 @@ fun Context.scheduleNextEventReminder(event: Event) {
|
|||
reminderSeconds.forEach {
|
||||
var startTS = event.startTS - it
|
||||
if (event.repeatInterval == DAY || event.repeatInterval == WEEK || event.repeatInterval == BIWEEK) {
|
||||
while (startTS < now || event.ignoreEventOccurrences.contains(startTS + it)) {
|
||||
while (startTS < now || event.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(startTS + it).toInt())) {
|
||||
startTS += event.repeatInterval
|
||||
}
|
||||
nextTS = Math.min(nextTS, startTS)
|
||||
|
|
|
@ -68,7 +68,7 @@ val TRIGGER = "TRIGGER:"
|
|||
val RRULE = "RRULE:"
|
||||
val CATEGORIES = "CATEGORIES:"
|
||||
val STATUS = "STATUS:"
|
||||
val EXDATE = "EXDATE:"
|
||||
val EXDATE = "EXDATE"
|
||||
|
||||
val DISPLAY = "DISPLAY"
|
||||
val FREQ = "FREQ"
|
||||
|
|
|
@ -239,7 +239,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
private fun fillExceptionValues(parentEventId: Int, occurrenceTS: Int): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(COL_PARENT_EVENT_ID, parentEventId)
|
||||
put(COL_OCCURRENCE_TIMESTAMP, occurrenceTS)
|
||||
put(COL_OCCURRENCE_DAYCODE, Formatter.getDayCodeFromTS(occurrenceTS))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
fun deleteEventOccurrence(parentEventId: Int, occurrenceTS: Int) {
|
||||
val exceptionSelection = "$COL_PARENT_EVENT_ID = $parentEventId AND $COL_OCCURRENCE_TIMESTAMP = $occurrenceTS"
|
||||
val exceptionSelection = "$COL_PARENT_EVENT_ID = $parentEventId AND $COL_OCCURRENCE_DAYCODE = ${Formatter.getDayCodeFromTS(occurrenceTS)}"
|
||||
mDb.delete(EXCEPTIONS_TABLE_NAME, exceptionSelection, null)
|
||||
|
||||
val values = fillExceptionValues(parentEventId, occurrenceTS)
|
||||
|
@ -375,7 +375,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
|
||||
events.addAll(getRepeatableEventsFor(fromTS, toTS))
|
||||
|
||||
val filtered = events.filterNot { it.ignoreEventOccurrences.contains(it.startTS) } as MutableList<Event>
|
||||
val filtered = events.filterNot { it.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(it.startTS).toInt()) } as MutableList<Event>
|
||||
callback(filtered)
|
||||
}
|
||||
|
||||
|
@ -544,23 +544,23 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
}
|
||||
|
||||
private fun getIgnoredOccurrences(eventId: Int): ArrayList<Int> {
|
||||
val projection = arrayOf(COL_OCCURRENCE_TIMESTAMP)
|
||||
val projection = arrayOf(COL_OCCURRENCE_DAYCODE)
|
||||
val selection = "$COL_PARENT_EVENT_ID = ?"
|
||||
val selectionArgs = arrayOf(eventId.toString())
|
||||
val timestamps = ArrayList<Int>()
|
||||
val daycodes = ArrayList<Int>()
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = mDb.query(EXCEPTIONS_TABLE_NAME, projection, selection, selectionArgs, null, null, COL_OCCURRENCE_TIMESTAMP)
|
||||
cursor = mDb.query(EXCEPTIONS_TABLE_NAME, projection, selection, selectionArgs, null, null, COL_OCCURRENCE_DAYCODE)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
timestamps.add(cursor.getIntValue(COL_OCCURRENCE_TIMESTAMP))
|
||||
daycodes.add(cursor.getIntValue(COL_OCCURRENCE_DAYCODE))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
return timestamps
|
||||
return daycodes
|
||||
}
|
||||
|
||||
private fun convertExceptionTimestampToDaycode(db: SQLiteDatabase) {
|
||||
|
|
|
@ -60,8 +60,6 @@ object Formatter {
|
|||
|
||||
fun getDayEndTS(dayCode: String) = getLocalDateTimeFromCode(dayCode).plusDays(1).minusMinutes(1).seconds()
|
||||
|
||||
fun getDayCodeFromTS(ts: Int) = getDateTimeFromTS(ts).toString(DAYCODE_PATTERN)
|
||||
|
||||
fun getDayCodeFromDateTime(dateTime: DateTime) = dateTime.toString(DAYCODE_PATTERN)
|
||||
|
||||
fun getDateTimeFromTS(ts: Int) = DateTime(ts * 1000L, DateTimeZone.getDefault())
|
||||
|
@ -77,4 +75,12 @@ object Formatter {
|
|||
val dateTime = getDateTimeFromTS(ts)
|
||||
return "${dateTime.toString(DAYCODE_PATTERN)}T${dateTime.toString(TIME_PATTERN)}Z"
|
||||
}
|
||||
|
||||
fun getDayCodeFromTS(ts: Int): String {
|
||||
val daycode = getDateTimeFromTS(ts).toString(DAYCODE_PATTERN)
|
||||
return if (daycode.isNotEmpty())
|
||||
daycode
|
||||
else
|
||||
"0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ class IcsExporter {
|
|||
|
||||
private fun fillIgnoredOccurrences(event: Event, out: BufferedWriter) {
|
||||
event.ignoreEventOccurrences.forEach {
|
||||
out.writeLn("$EXDATE${Formatter.getDayCodeFromTS(it)}")
|
||||
out.writeLn("$EXDATE:$it}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.simplemobiletools.calendar.extensions.notifyEvent
|
|||
import com.simplemobiletools.calendar.extensions.scheduleNextEventReminder
|
||||
import com.simplemobiletools.calendar.extensions.updateListWidget
|
||||
import com.simplemobiletools.calendar.helpers.EVENT_ID
|
||||
import com.simplemobiletools.calendar.helpers.Formatter
|
||||
|
||||
class NotificationReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
|
@ -20,7 +21,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||
if (event == null || event.getReminders().isEmpty())
|
||||
return
|
||||
|
||||
if (!event.ignoreEventOccurrences.contains(event.startTS)) {
|
||||
if (!event.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(event.startTS).toInt())) {
|
||||
context.notifyEvent(event)
|
||||
}
|
||||
context.scheduleNextEventReminder(event)
|
||||
|
|
Loading…
Reference in a new issue