From 10e2021dc95c580d917ed7fa5cdb0228e1563a95 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 5 Mar 2017 20:10:36 +0100 Subject: [PATCH] do not show the deleted occurrences of repeatable events --- .../adapters/EventListWidgetAdapter.kt | 16 +++++---- .../calendar/fragments/DayFragment.kt | 4 ++- .../calendar/fragments/EventListFragment.kt | 14 ++++---- .../calendar/fragments/WeekFragment.kt | 3 ++ .../calendar/helpers/DBHelper.kt | 36 ++++++++++++++++--- .../calendar/helpers/MonthlyCalendarImpl.kt | 9 +++-- .../calendar/helpers/YearlyCalendarImpl.kt | 8 +++-- .../calendar/models/Event.kt | 5 ++- 8 files changed, 69 insertions(+), 26 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt index 86890e500..c71f0b16c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/EventListWidgetAdapter.kt @@ -105,14 +105,16 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV val sublist = sorted.subList(0, Math.min(sorted.size, 100)) var prevCode = "" sublist.forEach { - val code = Formatter.getDayCodeFromTS(it.startTS) - if (code != prevCode) { - val day = Formatter.getDayTitle(context, code) - if (day != todayDate) - listItems.add(ListSection(day)) - prevCode = code + if (!it.ignoreEventOccurrences.contains(it.startTS)) { + val code = Formatter.getDayCodeFromTS(it.startTS) + if (code != prevCode) { + val day = Formatter.getDayTitle(context, code) + if (day != todayDate) + listItems.add(ListSection(day)) + prevCode = code + } + listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay)) } - listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay)) } this@EventListWidgetAdapter.events = listItems diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt index 22a547aa5..2d72eed09 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt @@ -154,8 +154,10 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents override fun gotEvents(events: MutableList) { val sorted = ArrayList(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))) val filtered = context.getFilteredEvents(sorted) + val notIgnored = filtered.filterNot { it.ignoreEventOccurrences.contains(it.startTS) } + activity?.runOnUiThread { - updateEvents(filtered) + updateEvents(notIgnored) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt index c4c833258..cd01873d2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/EventListFragment.kt @@ -68,13 +68,15 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event val sublist = sorted.subList(0, Math.min(sorted.size, 100)) var prevCode = "" sublist.forEach { - val code = Formatter.getDayCodeFromTS(it.startTS) - if (code != prevCode) { - val day = Formatter.getDayTitle(context, code) - listItems.add(ListSection(day)) - prevCode = code + if (!it.ignoreEventOccurrences.contains(it.startTS)) { + val code = Formatter.getDayCodeFromTS(it.startTS) + if (code != prevCode) { + val day = Formatter.getDayTitle(context, code) + listItems.add(ListSection(day)) + prevCode = code + } + listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay)) } - listItems.add(ListEvent(it.id, it.startTS, it.endTS, it.title, it.description, it.isAllDay)) } val eventsAdapter = EventListAdapter(activity as SimpleActivity, listItems, this) { eventId, eventTS -> diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index f6c2d6aee..e0b94e62c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -232,6 +232,9 @@ class WeekFragment : Fragment(), WeeklyCalendar { var hadAllDayEvent = false val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })) for (event in sorted) { + if (event.ignoreEventOccurrences.contains(event.startTS)) + continue + if (event.isAllDay || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) { hadAllDayEvent = true addAllDayEvent(event) 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 b4c3e6428..7e35f9827 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -347,10 +347,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val selectionArgs = arrayOf(id.toString()) val cursor = getEventsCursor(selection, selectionArgs) val events = fillEvents(cursor) - if (!events.isEmpty()) - return events[0] - - return null + return if (!events.isEmpty()) + events[0] + else + null } fun getEvents(fromTS: Int, toTS: Int, callback: GetEventsListener?) { @@ -449,8 +449,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont if (flags and FLAG_ALL_DAY != 0) endTS -= 1 + val ignoreEventOccurrences = if (repeatInterval != 0) { + getIgnoredOccurrences(id) + } else { + ArrayList() + } + val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes, - repeatInterval, importId, flags, repeatLimit, eventType) + repeatInterval, importId, flags, repeatLimit, eventType, ignoreEventOccurrences) events.add(event) } while (cursor.moveToNext()) } @@ -487,6 +493,26 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont callback.invoke(eventTypes) } + private fun getIgnoredOccurrences(eventId: Int): ArrayList { + val projection = arrayOf(COL_OCCURRENCE_TIMESTAMP) + val selection = "$COL_PARENT_EVENT_ID = ?" + val selectionArgs = arrayOf(eventId.toString()) + val timestamps = ArrayList() + + var cursor: Cursor? = null + try { + cursor = mDb.query(EXCEPTIONS_TABLE_NAME, projection, selection, selectionArgs, null, null, COL_OCCURRENCE_TIMESTAMP) + if (cursor?.moveToFirst() == true) { + do { + timestamps.add(cursor.getIntValue(COL_OCCURRENCE_TIMESTAMP)) + } while (cursor.moveToNext()) + } + } finally { + cursor?.close() + } + return timestamps + } + interface EventUpdateListener { fun eventInserted(event: Event) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt index 3f06cf12e..7ef17ede3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/MonthlyCalendarImpl.kt @@ -85,9 +85,12 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context) // it works more often than not, dont touch private fun markDaysWithEvents(days: ArrayList) { val eventCodes = ArrayList() - for ((id, startTS, endTS) in mEvents) { - val startDateTime = DateTime().withMillis(startTS * 1000L) - val endDateTime = DateTime().withMillis(endTS * 1000L) + for (event in mEvents) { + if (event.ignoreEventOccurrences.contains(event.startTS)) + continue + + val startDateTime = Formatter.getDateTimeFromTS(event.startTS) + val endDateTime = Formatter.getDateTimeFromTS(event.endTS) val endCode = Formatter.getDayCodeFromDateTime(endDateTime) var currDay = startDateTime diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt index 613ce3e7d..5b86acc79 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/YearlyCalendarImpl.kt @@ -20,13 +20,15 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val override fun gotEvents(events: MutableList) { val filtered = context.getFilteredEvents(events) + val notIgnored = filtered.filterNot { it.ignoreEventOccurrences.contains(it.startTS) } val arr = SparseArray>(12) - for ((id, startTS, endTS) in filtered) { - val startDateTime = DateTime().withMillis(startTS * 1000L) + + for ((id, startTS, endTS) in notIgnored) { + val startDateTime = Formatter.getDateTimeFromTS(startTS) markDay(arr, startDateTime) val startCode = Formatter.getDayCodeFromDateTime(startDateTime) - val endDateTime = DateTime().withMillis(endTS * 1000L) + val endDateTime = Formatter.getDateTimeFromTS(endTS) val endCode = Formatter.getDayCodeFromDateTime(endDateTime) if (startCode != endCode) { var currDateTime = startDateTime diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index 6a6f23629..a988c04a4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -2,12 +2,15 @@ package com.simplemobiletools.calendar.models import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.helpers.* +import com.simplemobiletools.calendar.helpers.Formatter import org.joda.time.DateTime import java.io.Serializable +import java.util.* data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var title: String = "", var description: String = "", var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0, - var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID) : Serializable { + var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, + var ignoreEventOccurrences: ArrayList = ArrayList()) : Serializable { companion object { private val serialVersionUID = -32456795132344616L