Improved contact lookup from native addressbook
This commit is contained in:
parent
aab38ad176
commit
fbe7986641
2 changed files with 16 additions and 13 deletions
|
@ -51,6 +51,7 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
|
|||
|
||||
private var sipUriToAdd: String? = null
|
||||
private var editOnClick: Boolean = false
|
||||
private var contactIdToDisplay: String? = null
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.contact_master_fragment
|
||||
|
||||
|
@ -149,6 +150,15 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
|
|||
})
|
||||
|
||||
listViewModel.contactsList.observe(viewLifecycleOwner, {
|
||||
val id = contactIdToDisplay
|
||||
if (id != null) {
|
||||
val contact = coreContext.contactsManager.findContactById(id)
|
||||
if (contact != null) {
|
||||
contactIdToDisplay = null
|
||||
Log.i("[Contacts] Found matching contact $contact after callback")
|
||||
adapter.selectedContactEvent.value = Event(contact)
|
||||
}
|
||||
}
|
||||
adapter.submitList(it)
|
||||
})
|
||||
|
||||
|
@ -181,6 +191,9 @@ class MasterContactsFragment : MasterFragment<ContactMasterFragmentBinding, Cont
|
|||
if (contact != null) {
|
||||
Log.i("[Contacts] Found matching contact $contact")
|
||||
adapter.selectedContactEvent.value = Event(contact)
|
||||
} else {
|
||||
Log.w("[Contacts] Matching contact not found yet, waiting for contacts updated callback")
|
||||
contactIdToDisplay = id
|
||||
}
|
||||
} else {
|
||||
val sipUri = arguments?.getString("sipUri")
|
||||
|
|
|
@ -187,20 +187,10 @@ class ContactsManager(private val context: Context) {
|
|||
}
|
||||
}
|
||||
|
||||
if (found == null && PermissionHelper.required(context).hasReadContactsPermission()) {
|
||||
// First of all abort background contacts fetching
|
||||
loadContactsTask?.cancel(true)
|
||||
|
||||
Log.i("[Contacts Manager] Creating native contact with id $id and fetch information from Android database directly")
|
||||
found = NativeContact(id)
|
||||
found.syncValuesFromAndroidContact(context)
|
||||
// Create a LinphoneFriend to be able to receive presence information
|
||||
found.createOrUpdateFriendFromNativeContact()
|
||||
|
||||
// Restart contacts async fetching
|
||||
fetchContactsAsync()
|
||||
if (found == null) {
|
||||
Log.i("[Contacts Manager] Contact with id $id not found yet")
|
||||
} else {
|
||||
Log.d("[Contacts Manager] Found contact with id [$id]: ${found?.fullName}")
|
||||
Log.d("[Contacts Manager] Found contact with id [$id]: ${found.fullName}")
|
||||
}
|
||||
|
||||
return found
|
||||
|
|
Loading…
Reference in a new issue