store the CalDAV calendar id at EventTypes too

This commit is contained in:
tibbi 2017-08-18 15:52:55 +02:00
parent 0817efbd1d
commit bd9372b8c4
4 changed files with 10 additions and 5 deletions

View file

@ -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)
}

View file

@ -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,

View file

@ -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)
}

View file

@ -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)