improve the name detection at Recents tab
This commit is contained in:
parent
12973ac57c
commit
c3ac30d47e
|
@ -519,39 +519,39 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
|
|||
return@getContacts
|
||||
}
|
||||
|
||||
val contacts = it
|
||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||
contacts_fragment?.refreshContacts(it)
|
||||
contacts_fragment?.refreshContacts(contacts)
|
||||
}
|
||||
|
||||
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
|
||||
favorites_fragment?.refreshContacts(it)
|
||||
favorites_fragment?.refreshContacts(contacts)
|
||||
}
|
||||
|
||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||
recents_fragment?.refreshContacts(it)
|
||||
recents_fragment?.refreshContacts(contacts)
|
||||
}
|
||||
|
||||
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
||||
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
||||
groups_fragment.skipHashComparing = true
|
||||
}
|
||||
groups_fragment?.refreshContacts(it)
|
||||
groups_fragment?.refreshContacts(contacts)
|
||||
}
|
||||
}
|
||||
|
||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||
ContactsHelper(this).getRecents {
|
||||
val localContacts = LocalContactsHelper(applicationContext).getAllContacts()
|
||||
it.filter { it.name == null }.forEach {
|
||||
val namelessCall = it
|
||||
val localContact = localContacts.firstOrNull { it.doesContainPhoneNumber(namelessCall.number) }
|
||||
if (localContact != null) {
|
||||
it.name = localContact.getNameToDisplay()
|
||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||
ContactsHelper(this).getRecents {
|
||||
it.filter { it.name == null }.forEach {
|
||||
val namelessCall = it
|
||||
val contact = contacts.firstOrNull { it.doesContainPhoneNumber(namelessCall.number) }
|
||||
if (contact != null) {
|
||||
it.name = contact.getNameToDisplay()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runOnUiThread {
|
||||
recents_fragment?.updateRecentCalls(it)
|
||||
runOnUiThread {
|
||||
recents_fragment?.updateRecentCalls(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ class ContactsHelper(val context: Context) {
|
|||
do {
|
||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||
val number = cursor.getStringValue(CommonDataKinds.Phone.NUMBER) ?: continue
|
||||
val normalizedNumber = cursor.getStringValue(CommonDataKinds.Phone.NORMALIZED_NUMBER) ?: ""
|
||||
val normalizedNumber = cursor.getStringValue(CommonDataKinds.Phone.NORMALIZED_NUMBER) ?: number.normalizeNumber()
|
||||
val type = cursor.getIntValue(CommonDataKinds.Phone.TYPE)
|
||||
val label = cursor.getStringValue(CommonDataKinds.Phone.LABEL) ?: ""
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.contacts.pro.models
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||
|
@ -128,7 +129,13 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
|
|||
|
||||
fun doesContainPhoneNumber(text: String): Boolean {
|
||||
return if (text.isNotEmpty()) {
|
||||
phoneNumbers.any { it.value.contains(text) || it.normalizedNumber?.contains(text.normalizeNumber()) == true || it.value.normalizeNumber().contains(text.normalizeNumber()) }
|
||||
val normalizedText = text.normalizeNumber()
|
||||
phoneNumbers.any {
|
||||
PhoneNumberUtils.compare(it.normalizedNumber, normalizedText) ||
|
||||
it.value.contains(text) ||
|
||||
it.normalizedNumber?.contains(normalizedText) == true ||
|
||||
it.value.normalizeNumber().contains(normalizedText)
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue