check last updated timestamp at reimporting google events
This commit is contained in:
parent
34e1717dcd
commit
d89c723af7
|
@ -456,6 +456,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
|
|||
eventType = mEventTypeId
|
||||
offset = getCurrentOffset()
|
||||
isDstIncluded = TimeZone.getDefault().inDaylightTime(Date())
|
||||
lastUpdated = System.currentTimeMillis()
|
||||
source = "Simple Calendar"
|
||||
}
|
||||
|
||||
if (mEvent.id == 0) {
|
||||
|
|
|
@ -86,10 +86,14 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre
|
|||
if (googleEvent.status != CONFIRMED)
|
||||
continue
|
||||
|
||||
val lastUpdate = DateTime(googleEvent.updated).millis
|
||||
val importId = googleEvent.iCalUID
|
||||
if (importIDs.contains(importId)) {
|
||||
val oldEvent = dbHelper.getEventWithImportId(importId)
|
||||
if (oldEvent != null && oldEvent.lastUpdated >= lastUpdate) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
val reminders = getReminder(googleEvent.reminders)
|
||||
val start = googleEvent.start
|
||||
|
@ -127,7 +131,7 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre
|
|||
|
||||
val event = Event(0, startTS, endTS, googleEvent.summary, googleEvent.description, reminders.getOrElse(0, { -1 }), reminders.getOrElse(1, { -1 }),
|
||||
reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval, importId, flags, repeatRule.repeatLimit, repeatRule.repeatRule,
|
||||
eventTypeId)
|
||||
eventTypeId, lastUpdated = lastUpdate)
|
||||
|
||||
if (event.isAllDay && endTS > startTS) {
|
||||
event.endTS -= DAY
|
||||
|
|
|
@ -226,7 +226,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())
|
||||
put(COL_LAST_UPDATED, event.lastUpdated)
|
||||
put(COL_SOURCE, event.source)
|
||||
}
|
||||
}
|
||||
|
@ -432,6 +432,17 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return ids.filter { it.trim().isNotEmpty() } as ArrayList<String>
|
||||
}
|
||||
|
||||
fun getEventWithImportId(importId: String): Event? {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_IMPORT_ID = ?"
|
||||
val selectionArgs = arrayOf(importId.toString())
|
||||
val cursor = getEventsCursor(selection, selectionArgs)
|
||||
val events = fillEvents(cursor)
|
||||
return if (!events.isEmpty())
|
||||
events[0]
|
||||
else
|
||||
null
|
||||
}
|
||||
|
||||
fun getEventWithId(id: Int): Event? {
|
||||
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
|
||||
val selectionArgs = arrayOf(id.toString())
|
||||
|
|
|
@ -4,4 +4,4 @@ import com.google.gson.JsonArray
|
|||
import com.google.gson.JsonObject
|
||||
|
||||
data class GoogleEvent(val summary: String, val description: String, val status: String, val start: GoogleEventDateTime, val end: GoogleEventDateTime,
|
||||
val reminders: JsonObject, val recurrence: JsonArray?, val iCalUID: String, val colorId: Int)
|
||||
val reminders: JsonObject, val recurrence: JsonArray?, val iCalUID: String, val colorId: Int, val updated: String)
|
||||
|
|
Loading…
Reference in New Issue