mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-02-17 04:10:45 +01:00
properly handle birthday and anniversary updating
This commit is contained in:
parent
e269f030b8
commit
ead64798cd
@ -538,7 +538,11 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
if (cursor?.moveToFirst() == true) {
|
if (cursor?.moveToFirst() == true) {
|
||||||
val dateFormats = getDateFormats()
|
val dateFormats = getDateFormats()
|
||||||
val existingEvents = if (birthdays) eventsDB.getBirthdays() else eventsDB.getAnniversaries()
|
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()
|
val eventTypeId = if (birthdays) getBirthdaysEventTypeId() else getAnniversariesEventTypeId()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -561,7 +565,21 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||||||
reminder3Minutes = reminders[2], importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY,
|
reminder3Minutes = reminders[2], importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR, repeatRule = REPEAT_SAME_DAY,
|
||||||
eventType = eventTypeId, source = source, lastUpdated = lastUpdated)
|
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) {
|
eventsHelper.insertEvent(event, false, false) {
|
||||||
eventsAdded++
|
eventsAdded++
|
||||||
}
|
}
|
||||||
|
@ -110,4 +110,7 @@ interface EventsDao {
|
|||||||
|
|
||||||
@Query("DELETE FROM events WHERE id IN (:ids)")
|
@Query("DELETE FROM events WHERE id IN (:ids)")
|
||||||
fun deleteEvents(ids: List<Long>)
|
fun deleteEvents(ids: List<Long>)
|
||||||
|
|
||||||
|
@Query("DELETE FROM events WHERE source = :source AND import_id = :importId")
|
||||||
|
fun deleteBirthdayAnniversary(source: String, importId: String): Int
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user