Small improvements regarding contacts
This commit is contained in:
parent
7f035cccbc
commit
fc901e8131
3 changed files with 14 additions and 3 deletions
|
@ -88,7 +88,6 @@ class ContactsListViewModel : ViewModel() {
|
|||
|
||||
fun updateContactsList(clearCache: Boolean) {
|
||||
val filterValue = filter.value.orEmpty()
|
||||
contactsList.value.orEmpty().forEach(ContactViewModel::destroy)
|
||||
|
||||
if (clearCache || (
|
||||
previousFilter.isNotEmpty() && (
|
||||
|
@ -122,6 +121,8 @@ class ContactsListViewModel : ViewModel() {
|
|||
|
||||
private fun processMagicSearchResults(results: Array<SearchResult>) {
|
||||
Log.i("[Contacts] Processing ${results.size} results")
|
||||
contactsList.value.orEmpty().forEach(ContactViewModel::destroy)
|
||||
|
||||
val list = arrayListOf<ContactViewModel>()
|
||||
for (result in results) {
|
||||
val contact = searchMatchingContact(result) ?: Contact(searchResult = result)
|
||||
|
@ -230,8 +231,9 @@ class ContactsListViewModel : ViewModel() {
|
|||
if (contact != null) return contact
|
||||
}
|
||||
|
||||
if (searchResult.phoneNumber != null) {
|
||||
return coreContext.contactsManager.findContactByPhoneNumber(searchResult.phoneNumber.orEmpty())
|
||||
val phoneNumber = searchResult.phoneNumber
|
||||
if (phoneNumber != null) {
|
||||
return coreContext.contactsManager.findContactByPhoneNumber(phoneNumber)
|
||||
}
|
||||
|
||||
return null
|
||||
|
|
|
@ -59,6 +59,7 @@ open class Contact() : Comparable<Contact> {
|
|||
|
||||
constructor(searchResult: SearchResult) : this() {
|
||||
friend = searchResult.friend
|
||||
fullName = friend?.name
|
||||
addAddressAndPhoneNumberFromSearchResult(searchResult)
|
||||
}
|
||||
|
||||
|
|
|
@ -233,16 +233,24 @@ class ContactsManager(private val context: Context) {
|
|||
}
|
||||
|
||||
val address = friend.address
|
||||
var potentialContact: Contact? = null
|
||||
if (address != null) {
|
||||
val friends = coreContext.core.findFriends(address)
|
||||
for (f in friends) {
|
||||
if (f.name == friend.name) {
|
||||
val contact: Contact? = f.userData as? Contact
|
||||
if (contact != null) return contact
|
||||
} else {
|
||||
val contact: Contact? = f.userData as? Contact
|
||||
if (contact != null) potentialContact = contact
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (potentialContact != null) {
|
||||
return potentialContact
|
||||
}
|
||||
|
||||
for (list in coreContext.core.friendsLists) {
|
||||
for (f in list.friends) {
|
||||
if (f.name == friend.name) {
|
||||
|
|
Loading…
Reference in a new issue