mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
pass event IDs to delete as a list of longs
This commit is contained in:
parent
ea80900eea
commit
96d290a635
@ -682,7 +682,7 @@ class EventActivity : SimpleActivity() {
|
||||
when (it) {
|
||||
DELETE_SELECTED_OCCURRENCE -> dbHelper.addEventRepeatException(mEvent.id!!, mEventOccurrenceTS, true)
|
||||
DELETE_FUTURE_OCCURRENCES -> dbHelper.addEventRepeatLimit(mEvent.id!!, mEventOccurrenceTS)
|
||||
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
|
||||
DELETE_ALL_OCCURRENCES -> dbHelper.deleteEvents(arrayListOf(mEvent.id!!), true)
|
||||
}
|
||||
runOnUiThread {
|
||||
finish()
|
||||
@ -776,7 +776,7 @@ class EventActivity : SimpleActivity() {
|
||||
|
||||
// recreate the event if it was moved in a different CalDAV calendar
|
||||
if (mEvent.id != 0L && oldSource != newSource) {
|
||||
dbHelper.deleteEvents(arrayOf(mEvent.id.toString()), true)
|
||||
dbHelper.deleteEvents(arrayListOf(mEvent.id!!), true)
|
||||
mEvent.id = 0
|
||||
}
|
||||
|
||||
|
@ -143,10 +143,10 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, r
|
||||
events.removeAll(eventsToDelete)
|
||||
|
||||
Thread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.map { it.id.toString() }.toList().toTypedArray()
|
||||
val nonRepeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval == 0 }.mapNotNull { it.id }.toMutableList()
|
||||
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.map { it.id!! }.toList()
|
||||
val repeatingEventIDs = eventsToDelete.asSequence().filter { it.repeatInterval != 0 }.mapNotNull { it.id }.toList()
|
||||
activity.handleEventDeleting(repeatingEventIDs, timestamps, it)
|
||||
activity.runOnUiThread {
|
||||
removeSelectedItems(positions)
|
||||
|
@ -207,7 +207,7 @@ class EventListAdapter(activity: SimpleActivity, var listItems: ArrayList<ListIt
|
||||
listItems.removeAll(eventsToDelete)
|
||||
|
||||
Thread {
|
||||
val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.map { it.id.toString() }.toTypedArray()
|
||||
val nonRepeatingEventIDs = eventsToDelete.filter { !it.isRepeatable }.mapNotNull { it.id }.toMutableList()
|
||||
activity.dbHelper.deleteEvents(nonRepeatingEventIDs, true)
|
||||
|
||||
val repeatingEventIDs = eventsToDelete.filter { it.isRepeatable }.map { it.id }
|
||||
|
@ -457,8 +457,7 @@ fun Context.handleEventDeleting(eventIds: List<Long>, timestamps: List<Int>, act
|
||||
}
|
||||
}
|
||||
DELETE_ALL_OCCURRENCES -> {
|
||||
val eventIDs = Array(eventIds.size) { i -> (eventIds[i].toString()) }
|
||||
dbHelper.deleteEvents(eventIDs, true)
|
||||
dbHelper.deleteEvents(eventIds.toMutableList(), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -249,17 +249,17 @@ class CalDAVHandler(val context: Context) {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
val eventIdsToDelete = ArrayList<String>()
|
||||
val eventIdsToDelete = ArrayList<Long>()
|
||||
importIdsMap.keys.filter { !fetchedEventIds.contains(it) }.forEach {
|
||||
val caldavEventId = it
|
||||
existingEvents.forEach {
|
||||
if (it.importId == caldavEventId) {
|
||||
eventIdsToDelete.add(it.id.toString())
|
||||
eventIdsToDelete.add(it.id!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.dbHelper.deleteEvents(eventIdsToDelete.toTypedArray(), false)
|
||||
context.dbHelper.deleteEvents(eventIdsToDelete.toMutableList(), false)
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@ -357,7 +357,7 @@ class CalDAVHandler(val context: Context) {
|
||||
|
||||
fun deleteCalDAVCalendarEvents(calendarId: Long) {
|
||||
val events = context.dbHelper.getCalDAVCalendarEvents(calendarId)
|
||||
val eventIds = events.map { it.id.toString() }.toTypedArray()
|
||||
val eventIds = events.mapNotNull { it.id }.toMutableList()
|
||||
context.dbHelper.deleteEvents(eventIds, false)
|
||||
}
|
||||
|
||||
|
@ -92,53 +92,53 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
|
||||
fun deleteAllEvents() {
|
||||
val cursor = getEventsCursor()
|
||||
val events = fillEvents(cursor).map { it.id.toString() }.toTypedArray()
|
||||
val events = fillEvents(cursor).mapNotNull { it.id }.toMutableList()
|
||||
deleteEvents(events, true)
|
||||
}
|
||||
|
||||
fun deleteEvents(ids: Array<String>, deleteFromCalDAV: Boolean) {
|
||||
val args = TextUtils.join(", ", ids)
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
|
||||
fun deleteEvents(ids: MutableList<Long>, deleteFromCalDAV: Boolean) {
|
||||
val eventIds = TextUtils.join(", ", ids)
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($eventIds)"
|
||||
val cursor = getEventsCursor(selection)
|
||||
val events = fillEvents(cursor).filter { it.importId.isNotEmpty() }
|
||||
val eventsWithImportId = fillEvents(cursor).filter { it.importId.isNotEmpty() }
|
||||
|
||||
mDb.delete(MAIN_TABLE_NAME, selection, null)
|
||||
|
||||
context.updateWidgets()
|
||||
|
||||
// temporary workaround, will be rewritten in Room
|
||||
ids.filterNot { it == "null" }.forEach {
|
||||
context.cancelNotification(it.toLong())
|
||||
ids.filterNot { it == 0L }.forEach {
|
||||
context.cancelNotification(it)
|
||||
}
|
||||
|
||||
if (deleteFromCalDAV && context.config.caldavSync) {
|
||||
events.forEach {
|
||||
eventsWithImportId.forEach {
|
||||
CalDAVHandler(context).deleteCalDAVEvent(it)
|
||||
}
|
||||
}
|
||||
|
||||
deleteChildEvents(args, deleteFromCalDAV)
|
||||
deleteChildEvents(ids, deleteFromCalDAV)
|
||||
context.updateWidgets()
|
||||
}
|
||||
|
||||
private fun deleteChildEvents(ids: String, deleteFromCalDAV: Boolean) {
|
||||
private fun deleteChildEvents(ids: MutableList<Long>, deleteFromCalDAV: Boolean) {
|
||||
val projection = arrayOf(COL_ID)
|
||||
val selection = "$COL_PARENT_EVENT_ID IN ($ids)"
|
||||
val childIds = ArrayList<String>()
|
||||
val childIds = ArrayList<Long>()
|
||||
|
||||
var cursor: Cursor? = null
|
||||
try {
|
||||
cursor = mDb.query(MAIN_TABLE_NAME, projection, selection, null, null, null, null)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
childIds.add(cursor.getStringValue(COL_ID))
|
||||
childIds.add(cursor.getLongValue(COL_ID))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
if (childIds.isNotEmpty())
|
||||
deleteEvents(childIds.toTypedArray(), deleteFromCalDAV)
|
||||
if (childIds.isNotEmpty()) {
|
||||
deleteEvents(childIds, deleteFromCalDAV)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCalDAVCalendarEvents(calendarId: Long): List<Event> {
|
||||
@ -176,7 +176,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
val selectionArgs = arrayOf(eventTypeId.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
val eventIDs = Array(events.size) { i -> (events[i].id.toString()) }
|
||||
val eventIDs = events.mapNotNull { it.id }.toMutableList()
|
||||
deleteEvents(eventIDs, true)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user