Fix delete logic in contact view and contact list if contact merging is disabled

This commit is contained in:
Stephan Ritscher
2024-01-24 13:29:13 +01:00
parent d98ee8a59b
commit cdfe45618a
2 changed files with 9 additions and 11 deletions

View File

@@ -114,7 +114,7 @@ class ViewContactActivity : ContactActivity() {
}
findItem(R.id.delete).setOnMenuItemClickListener {
deleteContactFromAllSources()
deleteContactWithMergeLogic()
true
}
@@ -838,8 +838,8 @@ class ViewContactActivity : ContactActivity() {
}
}
private fun deleteContactFromAllSources() {
val addition = if (binding.contactSourcesHolder.childCount > 1) {
private fun deleteContactWithMergeLogic() {
val addition = if (binding.contactSourcesHolder.childCount > 1 && mergeDuplicate) {
"\n\n${getString(R.string.delete_from_all_sources)}"
} else {
""
@@ -848,7 +848,7 @@ class ViewContactActivity : ContactActivity() {
val message = "${getString(org.fossify.commons.R.string.proceed_with_deletion)}$addition"
ConfirmationDialog(this, message) {
if (contact != null) {
ContactsHelper(this).deleteContact(contact!!, true) {
ContactsHelper(this).deleteContact(contact!!, mergeDuplicate) {
finish()
}
}

View File

@@ -224,13 +224,11 @@ class ContactsAdapter(
ContactsHelper(activity).getContacts(true) { allContacts ->
ensureBackgroundThread {
contactsToRemove.forEach {
val contactToRemove = it
val duplicates = allContacts.filter { it.id != contactToRemove.id && it.getHashToCompare() == contactToRemove.getHashToCompare() }
.toMutableList() as ArrayList<Contact>
duplicates.add(contactToRemove)
ContactsHelper(activity).deleteContacts(duplicates)
}
ContactsHelper(activity).deleteContacts(contactsToRemove
.flatMap { contactToRemove -> allContacts.filter {
(config.mergeDuplicateContacts || it.id == contactToRemove.id) && (it.getHashToCompare() == contactToRemove.getHashToCompare())
} }
.toMutableList() as ArrayList<Contact>)
activity.runOnUiThread {
if (contactItems.isEmpty()) {