From 16538e1bde987a3890bffc7e1bc22d15bf330ecc Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 16 Aug 2017 23:31:19 +0200 Subject: [PATCH] implement CalDAV event deleting --- .../calendar/helpers/CalDAVEventsHandler.kt | 7 +++++++ .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 6 ++++++ .../kotlin/com/simplemobiletools/calendar/models/Event.kt | 2 ++ 3 files changed, 15 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt index 37d1e1262..916c9878e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt @@ -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 { val reminders = ArrayList() val uri = CalendarContract.Reminders.CONTENT_URI diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt index 8a702dd37..2848bcdfb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -334,6 +334,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont fun deleteEvents(ids: Array) { 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) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt index 930be5fe8..cbec0fe19 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -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() }