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