check last updated timestamp at reimporting google events

This commit is contained in:
tibbi 2017-07-17 22:22:24 +02:00
parent 34e1717dcd
commit d89c723af7
4 changed files with 21 additions and 4 deletions

View File

@ -456,6 +456,8 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener {
eventType = mEventTypeId eventType = mEventTypeId
offset = getCurrentOffset() offset = getCurrentOffset()
isDstIncluded = TimeZone.getDefault().inDaylightTime(Date()) isDstIncluded = TimeZone.getDefault().inDaylightTime(Date())
lastUpdated = System.currentTimeMillis()
source = "Simple Calendar"
} }
if (mEvent.id == 0) { if (mEvent.id == 0) {

View File

@ -86,9 +86,13 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre
if (googleEvent.status != CONFIRMED) if (googleEvent.status != CONFIRMED)
continue continue
val lastUpdate = DateTime(googleEvent.updated).millis
val importId = googleEvent.iCalUID val importId = googleEvent.iCalUID
if (importIDs.contains(importId)) { if (importIDs.contains(importId)) {
continue val oldEvent = dbHelper.getEventWithImportId(importId)
if (oldEvent != null && oldEvent.lastUpdated >= lastUpdate) {
continue
}
} }
val reminders = getReminder(googleEvent.reminders) val reminders = getReminder(googleEvent.reminders)
@ -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 }), 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, reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval, importId, flags, repeatRule.repeatLimit, repeatRule.repeatRule,
eventTypeId) eventTypeId, lastUpdated = lastUpdate)
if (event.isAllDay && endTS > startTS) { if (event.isAllDay && endTS > startTS) {
event.endTS -= DAY event.endTS -= DAY

View File

@ -226,7 +226,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
put(COL_PARENT_EVENT_ID, event.parentId) put(COL_PARENT_EVENT_ID, event.parentId)
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, event.lastUpdated)
put(COL_SOURCE, event.source) 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> 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? { fun getEventWithId(id: Int): Event? {
val selection = "$MAIN_TABLE_NAME.$COL_ID = ?" val selection = "$MAIN_TABLE_NAME.$COL_ID = ?"
val selectionArgs = arrayOf(id.toString()) val selectionArgs = arrayOf(id.toString())

View File

@ -4,4 +4,4 @@ import com.google.gson.JsonArray
import com.google.gson.JsonObject import com.google.gson.JsonObject
data class GoogleEvent(val summary: String, val description: String, val status: String, val start: GoogleEventDateTime, val end: GoogleEventDateTime, 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)