properly handle birthday and anniversary updating

This commit is contained in:
tibbi 2019-07-26 10:33:56 +02:00
parent e269f030b8
commit ead64798cd
2 changed files with 23 additions and 2 deletions

View File

@ -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<String, Long>()
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<String>()
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++
}

View File

@ -110,4 +110,7 @@ interface EventsDao {
@Query("DELETE FROM events WHERE id IN (:ids)")
fun deleteEvents(ids: List<Long>)
@Query("DELETE FROM events WHERE source = :source AND import_id = :importId")
fun deleteBirthdayAnniversary(source: String, importId: String): Int
}