From 7223bc481c93b71735e09e57e2858a611c7c5c93 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 25 Oct 2017 13:04:57 +0200 Subject: [PATCH] Fixed contacts search list content when multiple contacts have same address or one contact has multiple addresses --- .../contacts/SearchContactsListAdapter.java | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/android/org/linphone/contacts/SearchContactsListAdapter.java b/src/android/org/linphone/contacts/SearchContactsListAdapter.java index fbf88e8e0..936af7ce2 100644 --- a/src/android/org/linphone/contacts/SearchContactsListAdapter.java +++ b/src/android/org/linphone/contacts/SearchContactsListAdapter.java @@ -116,16 +116,14 @@ public class SearchContactsListAdapter extends BaseAdapter { public List getContactsList() { List list = new ArrayList<>(); if (ContactsManager.getInstance().hasContacts()) { - for (Address addr : LinphoneManager.getLc().findContactsByChar("", mOnlySipContact)) { - LinphoneContact cont = ContactsManager.getInstance().findContactFromAddress(addr); - if (cont == null) { - cont = new LinphoneContact(); - cont.setFullName(addr.getUsername()); + List contacts = mOnlySipContact ? ContactsManager.getInstance().getContacts() : ContactsManager.getInstance().getSIPContacts(); + for (LinphoneContact contact : contacts) { + for (LinphoneNumberOrAddress noa : contact.getNumbersOrAddresses()) { + if (noa.isSIPAddress()) { + ContactAddress ca = new ContactAddress(contact , noa.getValue(), contact.isFriend()); + list.add(ca); + } } - // TODO Rechercher si un contact est associé à cette sip uri - // TODO Rechercher si un displayname est associé à cette sip uri - ContactAddress ca = new ContactAddress(cont , addr.asString(), cont.isFriend()); - list.add(ca); } } @@ -142,12 +140,7 @@ public class SearchContactsListAdapter extends BaseAdapter { } public ContactAddress getItem(int position) { - if (contacts == null || position >= contacts.size()) { - contacts = getContactsList(); - return contacts.get(position); - } else { - return contacts.get(position); - } + return contacts.get(position); } public long getItemId(int position) { @@ -195,11 +188,6 @@ public class SearchContactsListAdapter extends BaseAdapter { public View getView(int position, View convertView, ViewGroup parent) { View view; ViewHolder holder; - ContactAddress contact; - - do { - contact = getItem(position); - } while (contact == null); if (convertView != null) { view = convertView; @@ -210,6 +198,7 @@ public class SearchContactsListAdapter extends BaseAdapter { view.setTag(holder); } + ContactAddress contact = getItem(position); final String a = contact.getAddress(); LinphoneContact c = contact.getContact();