diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt index dd95b5281..8066921fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/MainActivity.kt @@ -538,7 +538,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { if (cursor?.moveToFirst() == true) { val dateFormats = getDateFormats() val existingEvents = if (birthdays) eventsDB.getBirthdays() else eventsDB.getAnniversaries() - val importIDs = existingEvents.map { it.importId } + val importIDs = HashMap() + existingEvents.forEach { + importIDs[it.importId] = it.startTS + } + val eventTypeId = if (birthdays) getBirthdaysEventTypeId() else getAnniversariesEventTypeId() do { @@ -561,7 +565,21 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { reminder3Minutes = reminders[2], importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY, eventType = eventTypeId, source = source, lastUpdated = lastUpdated) - if (!importIDs.contains(contactId)) { + val importIDsToDelete = ArrayList() + for ((key, value) in importIDs) { + if (key == contactId && value != timestamp) { + val deleted = eventsDB.deleteBirthdayAnniversary(source, key) + if (deleted == 1) { + importIDsToDelete.add(key) + } + } + } + + importIDsToDelete.forEach { + importIDs.remove(it) + } + + if (!importIDs.containsKey(contactId)) { eventsHelper.insertEvent(event, false, false) { eventsAdded++ } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt index 5a06904ce..5c19ea063 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/interfaces/EventsDao.kt @@ -110,4 +110,7 @@ interface EventsDao { @Query("DELETE FROM events WHERE id IN (:ids)") fun deleteEvents(ids: List) + + @Query("DELETE FROM events WHERE source = :source AND import_id = :importId") + fun deleteBirthdayAnniversary(source: String, importId: String): Int }