From a5d11ec1fdbd8afb489325471513f66cff0ff246 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 22 Aug 2017 13:38:36 +0200 Subject: [PATCH] delete event types created at caldav sync, if the calendar is unsynced --- .../simplemobiletools/calendar/activities/SettingsActivity.kt | 4 +++- .../kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index 236370ded..80dc0e8a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -70,7 +70,7 @@ class SettingsActivity : SimpleActivity() { if (config.primaryColor != mStoredPrimaryColor) { dbHelper.getEventTypes { if (it.filter { it.caldavCalendarId == 0 }.size == 1) { - val eventType = it[0] + val eventType = it.first { it.caldavCalendarId == 0 } eventType.color = config.primaryColor dbHelper.updateEventType(eventType) } @@ -156,6 +156,8 @@ class SettingsActivity : SimpleActivity() { oldCalendarIds.filter { !newCalendarIds.contains(it) }.forEach { CalDAVEventsHandler(applicationContext).deleteCalDAVCalendarEvents(it.toLong()) + val eventId = dbHelper.getEventTypeIdWithCalDAVCalendarId(it.toInt()) + dbHelper.deleteEventTypes(arrayListOf(eventId), true) {} } }).start() } 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 2364b5cce..e3ae9ba93 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -18,6 +18,7 @@ import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getStringValue import org.joda.time.DateTime import java.util.* +import kotlin.collections.ArrayList class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(context, DB_NAME, null, DB_VERSION) { private val MAIN_TABLE_NAME = "events"