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 16aed9801..57f7f86c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/asynctasks/FetchGoogleEventsTask.kt @@ -77,6 +77,7 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre } private fun parseEvents(json: String, eventTypes: ArrayList): List { + val importIDs = activity.dbHelper.getImportIds() val events = ArrayList() val token = object : TypeToken>() {}.type val googleEvents = Gson().fromJson>(json, token) ?: ArrayList(8) @@ -84,6 +85,11 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre if (googleEvent.status != CONFIRMED) continue + val importId = googleEvent.iCalUID + if (importIDs.contains(importId)) { + continue + } + val reminders = getReminder(googleEvent.reminders) val start = googleEvent.start val end = googleEvent.end @@ -118,9 +124,12 @@ class FetchGoogleEventsTask(val activity: Activity, credential: GoogleAccountCre repeatRule = Parser().parseRepeatInterval(recurrence.toString().trim('\"').substring(RRULE.length), startTS) } - Event(0, startTS, endTS, googleEvent.summary, googleEvent.description, reminders.getOrElse(0, { -1 }), reminders.getOrElse(1, { -1 }), - reminders.getOrElse(2, { -1 }), repeatRule.repeatInterval, googleEvent.iCalUID, flags, repeatRule.repeatLimit, repeatRule.repeatRule, + 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) + + importIDs.add(importId) + dbHelper.insert(event) {} } return events }