add another event field, Source

This commit is contained in:
tibbi 2017-07-17 19:59:42 +02:00
parent 55a97d2cd3
commit 31061141d8
3 changed files with 12 additions and 7 deletions

View File

@ -58,10 +58,10 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre
.setPageToken(currToken) .setPageToken(currToken)
.execute() .execute()
for (event in events) { for ((key, value) in events) {
if (event.key == ITEMS) { if (key == ITEMS) {
dbHelper.getEventTypes { dbHelper.getEventTypes {
parseEvents(event.value.toString(), it) parseEvents(value.toString(), it)
} }
} }
} }

View File

@ -35,6 +35,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
private val COL_OFFSET = "offset" private val COL_OFFSET = "offset"
private val COL_IS_DST_INCLUDED = "is_dst_included" private val COL_IS_DST_INCLUDED = "is_dst_included"
private val COL_LAST_UPDATED = "last_updated" private val COL_LAST_UPDATED = "last_updated"
private val COL_SOURCE = "source"
private val META_TABLE_NAME = "events_meta" private val META_TABLE_NAME = "events_meta"
private val COL_EVENT_ID = "event_id" 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, " + 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_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_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) createMetaTable(db)
createTypesTable(db) createTypesTable(db)
@ -146,6 +147,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
if (oldVersion < 14) { 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_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_OFFSET, event.offset)
put(COL_IS_DST_INCLUDED, if (event.isDstIncluded) 1 else 0) put(COL_IS_DST_INCLUDED, if (event.isDstIncluded) 1 else 0)
put(COL_LAST_UPDATED, System.currentTimeMillis()) 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<String> private val allColumns: Array<String>
get() = arrayOf("$MAIN_TABLE_NAME.$COL_ID", COL_START_TS, COL_END_TS, COL_TITLE, COL_DESCRIPTION, COL_REMINDER_MINUTES, COL_REMINDER_MINUTES_2, 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_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<Event> { private fun fillEvents(cursor: Cursor?): List<Event> {
val events = ArrayList<Event>() val events = ArrayList<Event>()
@ -672,6 +675,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
val offset = cursor.getStringValue(COL_OFFSET) val offset = cursor.getStringValue(COL_OFFSET)
val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1 val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1
val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED) val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED)
val source = cursor.getStringValue(COL_SOURCE)
val ignoreEventOccurrences = if (repeatInterval != 0) { val ignoreEventOccurrences = if (repeatInterval != 0) {
getIgnoredOccurrences(id) 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, val event = Event(id, startTS, endTS, title, description, reminder1Minutes, reminder2Minutes, reminder3Minutes,
repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded, repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded,
0, lastUpdated) 0, lastUpdated, source)
events.add(event) events.add(event)
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }

View File

@ -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 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 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<Int> = ArrayList(), var eventType: Int = DBHelper.REGULAR_EVENT_TYPE_ID, var ignoreEventOccurrences: ArrayList<Int> = 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 { companion object {
private val serialVersionUID = -32456795132345616L private val serialVersionUID = -32456795132345616L