import event repeat exceptions from ics files too
This commit is contained in:
parent
d63e6f30b2
commit
7be0a0d333
8 changed files with 23 additions and 15 deletions
|
@ -261,7 +261,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
if (it) {
|
||||
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()))
|
||||
} else {
|
||||
dbHelper.deleteEventOccurrence(mEvent.id, mEventOccurrenceTS)
|
||||
dbHelper.addEventRepeatException(mEvent.id, mEventOccurrenceTS)
|
||||
}
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ class DayEventsAdapter(val activity: SimpleActivity, val mItems: List<Event>, va
|
|||
if (it) {
|
||||
listener?.deleteItems(eventIds)
|
||||
} else {
|
||||
listener?.deleteEventOccurrences(eventIds, timestamps)
|
||||
listener?.addEventRepeatException(eventIds, timestamps)
|
||||
}
|
||||
actMode?.finish()
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ class EventListAdapter(val activity: SimpleActivity, val mItems: List<ListItem>,
|
|||
if (it) {
|
||||
listener?.deleteItems(eventIds)
|
||||
} else {
|
||||
listener?.deleteEventOccurrences(eventIds, timestamps)
|
||||
listener?.addEventRepeatException(eventIds, timestamps)
|
||||
}
|
||||
actMode?.finish()
|
||||
}
|
||||
|
|
|
@ -152,9 +152,9 @@ class DayFragment : Fragment(), DBHelper.EventUpdateListener, DeleteEventsListen
|
|||
DBHelper.newInstance(activity.applicationContext, this).deleteEvents(eventIDs)
|
||||
}
|
||||
|
||||
override fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
parentIds.forEachIndexed { index, value ->
|
||||
context.dbHelper.deleteEventOccurrence(parentIds[index], timestamps[index])
|
||||
context.dbHelper.addEventRepeatException(parentIds[index], timestamps[index])
|
||||
}
|
||||
(activity as DayActivity).recheckEvents()
|
||||
}
|
||||
|
|
|
@ -114,9 +114,9 @@ class EventListFragment : Fragment(), DBHelper.EventUpdateListener, DeleteEvents
|
|||
DBHelper.newInstance(activity.applicationContext, this).deleteEvents(eventIDs)
|
||||
}
|
||||
|
||||
override fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
|
||||
parentIds.forEachIndexed { index, value ->
|
||||
context.dbHelper.deleteEventOccurrence(value, timestamps[index])
|
||||
context.dbHelper.addEventRepeatException(value, timestamps[index])
|
||||
}
|
||||
checkEvents()
|
||||
}
|
||||
|
|
|
@ -138,9 +138,9 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
addEventType(eventType, db)
|
||||
}
|
||||
|
||||
fun insert(event: Event) {
|
||||
fun insert(event: Event): Int {
|
||||
if (event.startTS > event.endTS || event.title.trim().isEmpty())
|
||||
return
|
||||
return 0
|
||||
|
||||
val eventValues = fillEventValues(event)
|
||||
val id = mDb.insert(MAIN_TABLE_NAME, null, eventValues)
|
||||
|
@ -154,6 +154,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
context.updateWidgets()
|
||||
context.scheduleReminder(event)
|
||||
mEventsListener?.eventInserted(event)
|
||||
return event.id
|
||||
}
|
||||
|
||||
fun update(event: Event) {
|
||||
|
@ -292,10 +293,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
mEventsListener?.eventsDeleted(ids.size)
|
||||
}
|
||||
|
||||
fun deleteEventOccurrence(parentEventId: Int, occurrenceTS: Int) {
|
||||
val exceptionSelection = "$COL_PARENT_EVENT_ID = $parentEventId AND $COL_OCCURRENCE_DAYCODE = ${Formatter.getDayCodeFromTS(occurrenceTS)}"
|
||||
mDb.delete(EXCEPTIONS_TABLE_NAME, exceptionSelection, null)
|
||||
|
||||
fun addEventRepeatException(parentEventId: Int, occurrenceTS: Int) {
|
||||
val values = fillExceptionValues(parentEventId, occurrenceTS)
|
||||
mDb.insert(EXCEPTIONS_TABLE_NAME, null, values)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class IcsImporter {
|
|||
var curImportId = ""
|
||||
var curFlags = 0
|
||||
var curReminderMinutes = ArrayList<Int>()
|
||||
var curRepeatExceptions = ArrayList<Int>()
|
||||
var curRepeatInterval = 0
|
||||
var curRepeatLimit = 0
|
||||
var curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
|
@ -76,6 +77,8 @@ class IcsImporter {
|
|||
} else if (line.startsWith(CATEGORIES)) {
|
||||
val categories = line.substring(CATEGORIES.length)
|
||||
tryAddCategories(categories, context)
|
||||
} else if (line.startsWith(EXDATE)) {
|
||||
curRepeatExceptions.add(getTimestamp(line.substring(EXDATE.length)))
|
||||
} else if (line == END_EVENT) {
|
||||
if (curTitle.isEmpty() || curStart == -1 || curEnd == -1 || importIDs.contains(curImportId))
|
||||
continue
|
||||
|
@ -84,7 +87,13 @@ class IcsImporter {
|
|||
val event = Event(0, curStart, curEnd, curTitle, curDescription, curReminderMinutes.getOrElse(0, { -1 }),
|
||||
curReminderMinutes.getOrElse(1, { -1 }), curReminderMinutes.getOrElse(2, { -1 }), curRepeatInterval,
|
||||
curImportId, curFlags, curRepeatLimit, curEventType)
|
||||
context.dbHelper.insert(event)
|
||||
|
||||
val eventId = context.dbHelper.insert(event)
|
||||
|
||||
for (exceptionTS in curRepeatExceptions) {
|
||||
context.dbHelper.addEventRepeatException(eventId, exceptionTS)
|
||||
}
|
||||
|
||||
eventsImported++
|
||||
resetValues()
|
||||
}
|
||||
|
@ -216,6 +225,7 @@ class IcsImporter {
|
|||
curImportId = ""
|
||||
curFlags = 0
|
||||
curReminderMinutes = ArrayList<Int>()
|
||||
curRepeatExceptions = ArrayList<Int>()
|
||||
curRepeatInterval = 0
|
||||
curRepeatLimit = 0
|
||||
curEventType = DBHelper.REGULAR_EVENT_TYPE_ID
|
||||
|
|
|
@ -5,5 +5,5 @@ import java.util.*
|
|||
interface DeleteEventsListener {
|
||||
fun deleteItems(ids: ArrayList<Int>)
|
||||
|
||||
fun deleteEventOccurrences(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>)
|
||||
fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue