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 038639bf7..c9841a712 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -146,7 +146,7 @@ class SettingsActivity : SimpleActivity() { val calendars = CalDAVEventsHandler(applicationContext).getCalDAVCalendars(config.caldavSyncedCalendarIDs) calendars.forEach { if (!eventTypeNames.contains(it.displayName.toLowerCase())) { - val eventType = EventType(0, it.displayName, it.color) + val eventType = EventType(0, it.displayName, it.color, it.id) eventTypeNames.add(it.displayName.toLowerCase()) dbHelper.insertEventType(eventType) } 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 25be16944..71fb2bd87 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/CalDAVEventsHandler.kt @@ -22,7 +22,6 @@ class CalDAVEventsHandler(val context: Context) { return calendars } - context.dbHelper.fetchEventTypes() val uri = CalendarContract.Calendars.CONTENT_URI val projection = arrayOf( CalendarContract.Calendars._ID, 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 cb0a26a0b..8fb4ef71b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -48,6 +48,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val COL_TYPE_ID = "event_type_id" private val COL_TYPE_TITLE = "event_type_title" private val COL_TYPE_COLOR = "event_type_color" + private val COL_TYPE_CALDAV_CALENDAR_ID = "event_caldav_calendar_id" private val EXCEPTIONS_TABLE_NAME = "event_repeat_exceptions" private val COL_EXCEPTION_ID = "event_exception_id" @@ -59,7 +60,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val mDb: SQLiteDatabase = writableDatabase companion object { - private val DB_VERSION = 15 + private val DB_VERSION = 16 val DB_NAME = "events.db" val REGULAR_EVENT_TYPE_ID = 1 var dbInstance: DBHelper? = null @@ -152,6 +153,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont if (oldVersion < 15) { db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_EVENT_SOURCE TEXT DEFAULT ''") } + + if (oldVersion < 16) { + db.execSQL("ALTER TABLE $TYPES_TABLE_NAME ADD COLUMN $COL_TYPE_CALDAV_CALENDAR_ID INTEGER NOT NULL DEFAULT 0") + } } private fun createMetaTable(db: SQLiteDatabase) { @@ -160,7 +165,8 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } private fun createTypesTable(db: SQLiteDatabase) { - db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_TYPE_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER)") + db.execSQL("CREATE TABLE $TYPES_TABLE_NAME ($COL_TYPE_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_TYPE_TITLE TEXT, $COL_TYPE_COLOR INTEGER, " + + "$COL_TYPE_CALDAV_CALENDAR_ID INTEGER)") addRegularEventType(db) } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/models/EventType.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/models/EventType.kt index 6ce719aec..4c5f7cd6f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/EventType.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/EventType.kt @@ -1,3 +1,3 @@ package com.simplemobiletools.calendar.models -data class EventType(var id: Int = 0, var title: String, var color: Int) +data class EventType(var id: Int = 0, var title: String, var color: Int, var caldavCalendarId: Int = 0)