From 31061141d8f8184acaf59d2f76e7e3dbe165a2f1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 17 Jul 2017 19:59:42 +0200 Subject: [PATCH] add another event field, Source --- .../calendar/asynctasks/FetchGoogleEventsTask.kt | 6 +++--- .../com/simplemobiletools/calendar/helpers/DBHelper.kt | 10 +++++++--- .../com/simplemobiletools/calendar/models/Event.kt | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt index 57f7f86c9..580a31bb0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt @@ -58,10 +58,10 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre .setPageToken(currToken) .execute() - for (event in events) { - if (event.key == ITEMS) { + for ((key, value) in events) { + if (key == ITEMS) { dbHelper.getEventTypes { - parseEvents(event.value.toString(), it) + parseEvents(value.toString(), it) } } } 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 0d0d8b794..150337cab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -35,6 +35,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val COL_OFFSET = "offset" private val COL_IS_DST_INCLUDED = "is_dst_included" private val COL_LAST_UPDATED = "last_updated" + private val COL_SOURCE = "source" private val META_TABLE_NAME = "events_meta" private val COL_EVENT_ID = "event_id" @@ -78,7 +79,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY, $COL_START_TS INTEGER, $COL_END_TS INTEGER, $COL_TITLE TEXT, " + "$COL_DESCRIPTION TEXT, $COL_REMINDER_MINUTES INTEGER, $COL_REMINDER_MINUTES_2 INTEGER, $COL_REMINDER_MINUTES_3 INTEGER, " + "$COL_IMPORT_ID TEXT, $COL_FLAGS INTEGER, $COL_EVENT_TYPE INTEGER NOT NULL DEFAULT $REGULAR_EVENT_TYPE_ID, " + - "$COL_PARENT_EVENT_ID INTEGER, $COL_OFFSET TEXT, $COL_IS_DST_INCLUDED INTEGER, $COL_LAST_UPDATED INTEGER)") + "$COL_PARENT_EVENT_ID INTEGER, $COL_OFFSET TEXT, $COL_IS_DST_INCLUDED INTEGER, $COL_LAST_UPDATED INTEGER, $COL_SOURCE TEXT)") createMetaTable(db) createTypesTable(db) @@ -146,6 +147,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont if (oldVersion < 14) { db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_LAST_UPDATED INTEGER NOT NULL DEFAULT 0") + db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_SOURCE TEXT DEFAULT ''") } } @@ -225,6 +227,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont put(COL_OFFSET, event.offset) put(COL_IS_DST_INCLUDED, if (event.isDstIncluded) 1 else 0) put(COL_LAST_UPDATED, System.currentTimeMillis()) + put(COL_SOURCE, event.source) } } @@ -648,7 +651,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val allColumns: Array get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2, COL_REMINDER_MINUTES_3, COL_REPEAT_INTERVAL, COL_REPEAT_RULE, COL_IMPORT_ID, COL_FLAGS, COL_REPEAT_LIMIT, COL_EVENT_TYPE, COL_OFFSET, - COL_IS_DST_INCLUDED, COL_LAST_UPDATED) + COL_IS_DST_INCLUDED, COL_LAST_UPDATED, COL_SOURCE) private fun fillEvents(cursor: Cursor?): List { val events = ArrayList() @@ -672,6 +675,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val offset = cursor.getStringValue(COL_OFFSET) val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1 val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED) + val source = cursor.getStringValue(COL_SOURCE) val ignoreEventOccurrences = if (repeatInterval != 0) { getIgnoredOccurrences(id) @@ -685,7 +689,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes, repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded, - 0, lastUpdated) + 0, lastUpdated, source) events.add(event) } while (cursor.moveToNext()) } 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 75e4a057f..447f3cfa1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/models/Event.kt @@ -11,7 +11,8 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var var reminder1Minutes: Int = -1, var reminder2Minutes: Int = -1, var reminder3Minutes: Int = -1, var repeatInterval: Int = 0, var importId: String? = "", var flags: Int = 0, var repeatLimit: Int = 0, var repeatRule: Int = 0, var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList = ArrayList(), - var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L) : Serializable { + var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L, + var source: String = "") : Serializable { companion object { private val serialVersionUID = -32456795132345616L