mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-18 20:40:46 +01:00
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
|
return@getContacts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val contacts = it
|
||||||
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
if (refreshTabsMask and CONTACTS_TAB_MASK != 0) {
|
||||||
contacts_fragment?.refreshContacts(it)
|
contacts_fragment?.refreshContacts(contacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
|
if (refreshTabsMask and FAVORITES_TAB_MASK != 0) {
|
||||||
favorites_fragment?.refreshContacts(it)
|
favorites_fragment?.refreshContacts(contacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||||
recents_fragment?.refreshContacts(it)
|
recents_fragment?.refreshContacts(contacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
if (refreshTabsMask and GROUPS_TAB_MASK != 0) {
|
||||||
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
if (refreshTabsMask == GROUPS_TAB_MASK) {
|
||||||
groups_fragment.skipHashComparing = true
|
groups_fragment.skipHashComparing = true
|
||||||
}
|
}
|
||||||
groups_fragment?.refreshContacts(it)
|
groups_fragment?.refreshContacts(contacts)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
if (refreshTabsMask and RECENTS_TAB_MASK != 0) {
|
||||||
ContactsHelper(this).getRecents {
|
ContactsHelper(this).getRecents {
|
||||||
val localContacts = LocalContactsHelper(applicationContext).getAllContacts()
|
it.filter { it.name == null }.forEach {
|
||||||
it.filter { it.name == null }.forEach {
|
val namelessCall = it
|
||||||
val namelessCall = it
|
val contact = contacts.firstOrNull { it.doesContainPhoneNumber(namelessCall.number) }
|
||||||
val localContact = localContacts.firstOrNull { it.doesContainPhoneNumber(namelessCall.number) }
|
if (contact != null) {
|
||||||
if (localContact != null) {
|
it.name = contact.getNameToDisplay()
|
||||||
it.name = localContact.getNameToDisplay()
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
recents_fragment?.updateRecentCalls(it)
|
recents_fragment?.updateRecentCalls(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ class ContactsHelper(val context: Context) {
|
|||||||
do {
|
do {
|
||||||
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
val id = cursor.getIntValue(ContactsContract.Data.RAW_CONTACT_ID)
|
||||||
val number = cursor.getStringValue(CommonDataKinds.Phone.NUMBER) ?: continue
|
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 type = cursor.getIntValue(CommonDataKinds.Phone.TYPE)
|
||||||
val label = cursor.getStringValue(CommonDataKinds.Phone.LABEL) ?: ""
|
val label = cursor.getStringValue(CommonDataKinds.Phone.LABEL) ?: ""
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.contacts.pro.models
|
package com.simplemobiletools.contacts.pro.models
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
|
import android.telephony.PhoneNumberUtils
|
||||||
import com.simplemobiletools.commons.extensions.normalizeString
|
import com.simplemobiletools.commons.extensions.normalizeString
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_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 {
|
fun doesContainPhoneNumber(text: String): Boolean {
|
||||||
return if (text.isNotEmpty()) {
|
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 {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user