mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-03-05 19:47:50 +01:00
fix #218, improve duplicate contact filtering, show the one with more info
This commit is contained in:
parent
03b739f01e
commit
de387a938d
@ -42,12 +42,22 @@ class ContactsHelper(val activity: Activity) {
|
||||
}
|
||||
|
||||
val contactsSize = contacts.size()
|
||||
var resultContacts = ArrayList<Contact>(contactsSize)
|
||||
(0 until contactsSize).mapTo(resultContacts) { contacts.valueAt(it) }
|
||||
var tempContacts = ArrayList<Contact>(contactsSize)
|
||||
val resultContacts = ArrayList<Contact>(contactsSize)
|
||||
(0 until contactsSize).mapTo(tempContacts) { contacts.valueAt(it) }
|
||||
if (activity.config.filterDuplicates) {
|
||||
resultContacts = resultContacts.distinctBy {
|
||||
tempContacts = tempContacts.distinctBy {
|
||||
it.getHashToCompare()
|
||||
} as ArrayList<Contact>
|
||||
|
||||
tempContacts.groupBy { "${it.getFullName().toLowerCase()}${it.emails}" }.values.forEach {
|
||||
if (it.size == 1) {
|
||||
resultContacts.add(it.first())
|
||||
} else {
|
||||
val sorted = it.sortedByDescending { it.getStringToCompare().length }
|
||||
resultContacts.add(sorted.first())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// groups are obtained with contactID, not rawID, so assign them to proper contacts like this
|
||||
|
@ -92,7 +92,7 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
||||
}
|
||||
}
|
||||
|
||||
fun getHashToCompare(): Int {
|
||||
fun getStringToCompare(): String {
|
||||
val newPhoneNumbers = ArrayList<PhoneNumber>()
|
||||
phoneNumbers.mapTo(newPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0, "") }
|
||||
|
||||
@ -100,7 +100,9 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
||||
emails.mapTo(newEmails) { Email(it.value, 0, "") }
|
||||
|
||||
return copy(id = 0, prefix = "", firstName = getFullName().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "",
|
||||
phoneNumbers = newPhoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,
|
||||
contactId = 0, thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", "")).hashCode()
|
||||
phoneNumbers = phoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,
|
||||
contactId = 0, thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", "")).toString()
|
||||
}
|
||||
|
||||
fun getHashToCompare() = getStringToCompare().hashCode()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user