implement CalDAV event deleting
This commit is contained in:
parent
3d2ba4d0ef
commit
16538e1bde
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.calendar.helpers
|
||||
|
||||
import android.content.ContentUris
|
||||
import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
|
@ -156,6 +157,12 @@ class CalDAVEventsHandler(val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
fun deleteCalDAVEvent(event: Event) {
|
||||
val uri = CalendarContract.Events.CONTENT_URI
|
||||
val contentUri = ContentUris.withAppendedId(uri, event.getCalDAVId())
|
||||
context.contentResolver.delete(contentUri, null, null)
|
||||
}
|
||||
|
||||
fun getCalDAVEventReminders(eventId: Long): List<Int> {
|
||||
val reminders = ArrayList<Int>()
|
||||
val uri = CalendarContract.Reminders.CONTENT_URI
|
||||
|
|
|
@ -334,6 +334,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
fun deleteEvents(ids: Array<String>) {
|
||||
val args = TextUtils.join(", ", ids)
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID IN ($args)"
|
||||
val cursor = getEventsCursor(selection)
|
||||
val events = fillEvents(cursor).filter { it.importId.isNotEmpty() }
|
||||
|
||||
mDb.delete(MAIN_TABLE_NAME, selection, null)
|
||||
|
||||
|
@ -350,6 +352,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
context.cancelNotification(it.toInt())
|
||||
}
|
||||
|
||||
events.forEach {
|
||||
CalDAVEventsHandler(context).deleteCalDAVEvent(it)
|
||||
}
|
||||
|
||||
deleteChildEvents(args)
|
||||
}
|
||||
|
||||
|
|
|
@ -104,4 +104,6 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
|
|||
startTS
|
||||
}
|
||||
}
|
||||
|
||||
fun getCalDAVId() = (importId.split("-").lastOrNull() ?: "0").toString().toLong()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue