do not show the deleted occurrences of repeatable events
This commit is contained in:
parent
a4ee9eee52
commit
10e2021dc9
8 changed files with 69 additions and 26 deletions
|
@ -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
|
||||
|
|
|
@ -154,8 +154,10 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
|
|||
override fun gotEvents(events: MutableList<Event>) {
|
||||
val sorted = ArrayList<Event>(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 ->
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Int>()
|
||||
}
|
||||
|
||||
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<Int> {
|
||||
val projection = arrayOf(COL_OCCURRENCE_TIMESTAMP)
|
||||
val selection = "$COL_PARENT_EVENT_ID = ?"
|
||||
val selectionArgs = arrayOf(eventId.toString())
|
||||
val timestamps = ArrayList<Int>()
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
@ -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<Day>) {
|
||||
val eventCodes = ArrayList<String>()
|
||||
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
|
||||
|
|
|
@ -20,13 +20,15 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
|||
|
||||
override fun gotEvents(events: MutableList<Event>) {
|
||||
val filtered = context.getFilteredEvents(events)
|
||||
val notIgnored = filtered.filterNot { it.ignoreEventOccurrences.contains(it.startTS) }
|
||||
val arr = SparseArray<ArrayList<Int>>(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
|
||||
|
|
|
@ -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<Int> = ArrayList()) : Serializable {
|
||||
|
||||
companion object {
|
||||
private val serialVersionUID = -32456795132344616L
|
||||
|
|
Loading…
Reference in a new issue