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,6 +105,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
||||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||||
var prevCode = ""
|
var prevCode = ""
|
||||||
sublist.forEach {
|
sublist.forEach {
|
||||||
|
if (!it.ignoreEventOccurrences.contains(it.startTS)) {
|
||||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||||
if (code != prevCode) {
|
if (code != prevCode) {
|
||||||
val day = Formatter.getDayTitle(context, code)
|
val day = Formatter.getDayTitle(context, code)
|
||||||
|
@ -114,6 +115,7 @@ class EventListWidgetAdapter(val context: Context, val intent: Intent) : RemoteV
|
||||||
}
|
}
|
||||||
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
|
this@EventListWidgetAdapter.events = listItems
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,8 +154,10 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DBHelper.GetEvents
|
||||||
override fun gotEvents(events: MutableList<Event>) {
|
override fun gotEvents(events: MutableList<Event>) {
|
||||||
val sorted = ArrayList<Event>(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })))
|
val sorted = ArrayList<Event>(events.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description })))
|
||||||
val filtered = context.getFilteredEvents(sorted)
|
val filtered = context.getFilteredEvents(sorted)
|
||||||
|
val notIgnored = filtered.filterNot { it.ignoreEventOccurrences.contains(it.startTS) }
|
||||||
|
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
updateEvents(filtered)
|
updateEvents(notIgnored)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,6 +68,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
|
||||||
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
val sublist = sorted.subList(0, Math.min(sorted.size, 100))
|
||||||
var prevCode = ""
|
var prevCode = ""
|
||||||
sublist.forEach {
|
sublist.forEach {
|
||||||
|
if (!it.ignoreEventOccurrences.contains(it.startTS)) {
|
||||||
val code = Formatter.getDayCodeFromTS(it.startTS)
|
val code = Formatter.getDayCodeFromTS(it.startTS)
|
||||||
if (code != prevCode) {
|
if (code != prevCode) {
|
||||||
val day = Formatter.getDayTitle(context, code)
|
val day = Formatter.getDayTitle(context, code)
|
||||||
|
@ -76,6 +77,7 @@ class EventListFragment : Fragment(), DBHelper.GetEventsListener, DBHelper.Event
|
||||||
}
|
}
|
||||||
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 ->
|
val eventsAdapter = EventListAdapter(activity as SimpleActivity, listItems, this) { eventId, eventTS ->
|
||||||
editEvent(eventId, eventTS)
|
editEvent(eventId, eventTS)
|
||||||
|
|
|
@ -232,6 +232,9 @@ class WeekFragment : Fragment(), WeeklyCalendar {
|
||||||
var hadAllDayEvent = false
|
var hadAllDayEvent = false
|
||||||
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
|
val sorted = filtered.sortedWith(compareBy({ it.startTS }, { it.endTS }, { it.title }, { it.description }))
|
||||||
for (event in sorted) {
|
for (event in sorted) {
|
||||||
|
if (event.ignoreEventOccurrences.contains(event.startTS))
|
||||||
|
continue
|
||||||
|
|
||||||
if (event.isAllDay || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
|
if (event.isAllDay || Formatter.getDayCodeFromTS(event.startTS) != Formatter.getDayCodeFromTS(event.endTS)) {
|
||||||
hadAllDayEvent = true
|
hadAllDayEvent = true
|
||||||
addAllDayEvent(event)
|
addAllDayEvent(event)
|
||||||
|
|
|
@ -347,10 +347,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
val selectionArgs = arrayOf(id.toString())
|
val selectionArgs = arrayOf(id.toString())
|
||||||
val cursor = getEventsCursor(selection, selectionArgs)
|
val cursor = getEventsCursor(selection, selectionArgs)
|
||||||
val events = fillEvents(cursor)
|
val events = fillEvents(cursor)
|
||||||
if (!events.isEmpty())
|
return if (!events.isEmpty())
|
||||||
return events[0]
|
events[0]
|
||||||
|
else
|
||||||
return null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEvents(fromTS: Int, toTS: Int, callback: GetEventsListener?) {
|
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)
|
if (flags and FLAG_ALL_DAY != 0)
|
||||||
endTS -= 1
|
endTS -= 1
|
||||||
|
|
||||||
|
val ignoreEventOccurrences = if (repeatInterval != 0) {
|
||||||
|
getIgnoredOccurrences(id)
|
||||||
|
} else {
|
||||||
|
ArrayList<Int>()
|
||||||
|
}
|
||||||
|
|
||||||
val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
|
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)
|
events.add(event)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
|
@ -487,6 +493,26 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
callback.invoke(eventTypes)
|
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 {
|
interface EventUpdateListener {
|
||||||
fun eventInserted(event: Event)
|
fun eventInserted(event: Event)
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,12 @@ class MonthlyCalendarImpl(val mCallback: MonthlyCalendar, val mContext: Context)
|
||||||
// it works more often than not, dont touch
|
// it works more often than not, dont touch
|
||||||
private fun markDaysWithEvents(days: ArrayList<Day>) {
|
private fun markDaysWithEvents(days: ArrayList<Day>) {
|
||||||
val eventCodes = ArrayList<String>()
|
val eventCodes = ArrayList<String>()
|
||||||
for ((id, startTS, endTS) in mEvents) {
|
for (event in mEvents) {
|
||||||
val startDateTime = DateTime().withMillis(startTS * 1000L)
|
if (event.ignoreEventOccurrences.contains(event.startTS))
|
||||||
val endDateTime = DateTime().withMillis(endTS * 1000L)
|
continue
|
||||||
|
|
||||||
|
val startDateTime = Formatter.getDateTimeFromTS(event.startTS)
|
||||||
|
val endDateTime = Formatter.getDateTimeFromTS(event.endTS)
|
||||||
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
|
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
|
||||||
|
|
||||||
var currDay = startDateTime
|
var currDay = startDateTime
|
||||||
|
|
|
@ -20,13 +20,15 @@ class YearlyCalendarImpl(val callback: YearlyCalendar, val context: Context, val
|
||||||
|
|
||||||
override fun gotEvents(events: MutableList<Event>) {
|
override fun gotEvents(events: MutableList<Event>) {
|
||||||
val filtered = context.getFilteredEvents(events)
|
val filtered = context.getFilteredEvents(events)
|
||||||
|
val notIgnored = filtered.filterNot { it.ignoreEventOccurrences.contains(it.startTS) }
|
||||||
val arr = SparseArray<ArrayList<Int>>(12)
|
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)
|
markDay(arr, startDateTime)
|
||||||
|
|
||||||
val startCode = Formatter.getDayCodeFromDateTime(startDateTime)
|
val startCode = Formatter.getDayCodeFromDateTime(startDateTime)
|
||||||
val endDateTime = DateTime().withMillis(endTS * 1000L)
|
val endDateTime = Formatter.getDateTimeFromTS(endTS)
|
||||||
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
|
val endCode = Formatter.getDayCodeFromDateTime(endDateTime)
|
||||||
if (startCode != endCode) {
|
if (startCode != endCode) {
|
||||||
var currDateTime = startDateTime
|
var currDateTime = startDateTime
|
||||||
|
|
|
@ -2,12 +2,15 @@ package com.simplemobiletools.calendar.models
|
||||||
|
|
||||||
import com.simplemobiletools.calendar.extensions.seconds
|
import com.simplemobiletools.calendar.extensions.seconds
|
||||||
import com.simplemobiletools.calendar.helpers.*
|
import com.simplemobiletools.calendar.helpers.*
|
||||||
|
import com.simplemobiletools.calendar.helpers.Formatter
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.io.Serializable
|
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 = "",
|
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 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 {
|
companion object {
|
||||||
private val serialVersionUID = -32456795132344616L
|
private val serialVersionUID = -32456795132344616L
|
||||||
|
|
Loading…
Reference in a new issue