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 8913c0f7b..0d0d8b794 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/DBHelper.kt @@ -14,6 +14,7 @@ import com.simplemobiletools.calendar.extensions.* import com.simplemobiletools.calendar.models.Event import com.simplemobiletools.calendar.models.EventType import com.simplemobiletools.commons.extensions.getIntValue +import com.simplemobiletools.commons.extensions.getLongValue import com.simplemobiletools.commons.extensions.getStringValue import org.joda.time.DateTime import java.util.* @@ -33,6 +34,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val COL_EVENT_TYPE = "event_type" private val COL_OFFSET = "offset" private val COL_IS_DST_INCLUDED = "is_dst_included" + private val COL_LAST_UPDATED = "last_updated" private val META_TABLE_NAME = "events_meta" private val COL_EVENT_ID = "event_id" @@ -56,7 +58,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont private val mDb: SQLiteDatabase = writableDatabase companion object { - private val DB_VERSION = 13 + private val DB_VERSION = 14 val DB_NAME = "events.db" val REGULAR_EVENT_TYPE_ID = 1 var dbInstance: DBHelper? = null @@ -76,7 +78,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_PARENT_EVENT_ID INTEGER, $COL_OFFSET TEXT, $COL_IS_DST_INCLUDED INTEGER, $COL_LAST_UPDATED INTEGER)") createMetaTable(db) createTypesTable(db) @@ -141,6 +143,10 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont db.execSQL("ALTER TABLE $EXCEPTIONS_TABLE_NAME ADD COLUMN $COL_CHILD_EVENT_ID INTEGER NOT NULL DEFAULT 0") } } + + if (oldVersion < 14) { + db.execSQL("ALTER TABLE $MAIN_TABLE_NAME ADD COLUMN $COL_LAST_UPDATED INTEGER NOT NULL DEFAULT 0") + } } private fun createMetaTable(db: SQLiteDatabase) { @@ -218,6 +224,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont put(COL_PARENT_EVENT_ID, event.parentId) put(COL_OFFSET, event.offset) put(COL_IS_DST_INCLUDED, if (event.isDstIncluded) 1 else 0) + put(COL_LAST_UPDATED, System.currentTimeMillis()) } } @@ -641,7 +648,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_IS_DST_INCLUDED, COL_LAST_UPDATED) private fun fillEvents(cursor: Cursor?): List { val events = ArrayList() @@ -664,6 +671,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val eventType = cursor.getIntValue(COL_EVENT_TYPE) val offset = cursor.getStringValue(COL_OFFSET) val isDstIncluded = cursor.getIntValue(COL_IS_DST_INCLUDED) == 1 + val lastUpdated = cursor.getLongValue(COL_LAST_UPDATED) val ignoreEventOccurrences = if (repeatInterval != 0) { getIgnoredOccurrences(id) @@ -676,7 +684,8 @@ 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) + repeatInterval, importId, flags, repeatLimit, repeatRule, eventType, ignoreEventOccurrences, offset, isDstIncluded, + 0, lastUpdated) 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 92ff84b1d..75e4a057f 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,7 @@ 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) : Serializable { + var offset: String = "", var isDstIncluded: Boolean = false, var parentId: Int = 0, var lastUpdated: Long = 0L) : Serializable { companion object { private val serialVersionUID = -32456795132345616L