From 83f266afae9c386794f5192a738c4ff1e0149bb2 Mon Sep 17 00:00:00 2001 From: AzisuAzusa Date: Wed, 24 Oct 2018 15:58:28 +0700 Subject: [PATCH] #638 naming the parameters and check if there is a need for filtering the list by event type --- .../calendar/helpers/DBHelper.kt | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index a7299e313..09eaa4f9d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -683,12 +683,16 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont fun getEvents(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList) -> Unit) { Thread { - getEventsInBackground(fromTS, toTS, eventId, callback) + getEventsInBackground(fromTS = fromTS, toTS = toTS, eventId = eventId, callback = callback) }.start() } - fun getEventsInBackground(fromTS: Int, toTS: Int, eventId: Int = -1, callback: (events: ArrayList) -> Unit) { - val events = ArrayList() + fun getEventsInBackground(fromTS: Int, + toTS: Int, + eventId: Int = -1, + filterEventType: Boolean = false, + callback: (events: ArrayList) -> Unit) { + var events = ArrayList() var selection = "$COL_START_TS <= ? AND $COL_END_TS >= ? AND $COL_REPEAT_INTERVAL IS NULL AND $COL_START_TS != 0" if (eventId != -1) @@ -701,8 +705,17 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont events.addAll(getAllDayEvents(fromTS, eventId)) - val filtered = events.distinct().filterNot { it.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(it.startTS).toInt()) } as ArrayList - callback(filtered) + val displayEventTypes = context.config.displayEventTypes + if (filterEventType) { + events = events.filter { + displayEventTypes.contains(it.toString()) + } as ArrayList + } + + events = events + .distinct() + .filterNot { it.ignoreEventOccurrences.contains(Formatter.getDayCodeFromTS(it.startTS).toInt()) } as ArrayList + callback(events) } fun getRepeatableEventsFor(fromTS: Int, toTS: Int, eventId: Int = -1): List {