Fix username and displayname for none contact in chat group

This commit is contained in:
Erwan Croze 2018-05-24 15:13:37 +02:00
parent e97429174f
commit facac17734
4 changed files with 32 additions and 6 deletions

View file

@ -288,7 +288,11 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
private void addSelectedContactAddress(ContactAddress ca) {
View viewContact = LayoutInflater.from(LinphoneActivity.instance()).inflate(R.layout.contact_selected, null);
if (ca.getContact() != null) {
((TextView) viewContact.findViewById(R.id.sipUri)).setText(ca.getContact().getFullName());
String name = (ca.getContact().getFullName() != null && !ca.getContact().getFullName().isEmpty()) ?
ca.getContact().getFullName() : (ca.getDisplayName() != null) ?
ca.getDisplayName() : (ca.getUsername() != null) ?
ca.getUsername() : "";
((TextView) viewContact.findViewById(R.id.sipUri)).setText(name);
} else {
((TextView) viewContact.findViewById(R.id.sipUri)).setText(ca.getAddressAsDisplayableString());
}

View file

@ -85,7 +85,8 @@ public class GroupInfoAdapter extends BaseAdapter {
final LinearLayout isAdmin = view.findViewById(R.id.isAdminLayout);
final LinearLayout isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
name.setText(c.getFullName());
name.setText((c.getFullName() != null) ? c.getFullName() :
(ca.getDisplayName() != null) ? ca.getDisplayName() : ca.getUsername());
if (c.hasPhoto()) {
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), avatar, c.getThumbnailUri());
}

View file

@ -85,6 +85,26 @@ public class ContactAddress implements Serializable {
return addr;
}
public String getDisplayName() {
if (address != null) {
Address addr = Factory.instance().createAddress(address);
if (addr != null) {
return addr.getDisplayName();
}
}
return null;
}
public String getUsername() {
if (address != null) {
Address addr = Factory.instance().createAddress(address);
if (addr != null) {
return addr.getUsername();
}
}
return null;
}
public String getPhoneNumber() {
return phoneNumber;
}

View file

@ -33,6 +33,7 @@ import org.linphone.LinphoneUtils;
import org.linphone.R;
import org.linphone.activities.LinphoneActivity;
import org.linphone.core.Address;
import org.linphone.core.Factory;
import org.linphone.core.ProxyConfig;
import org.linphone.core.SearchResult;
@ -63,7 +64,6 @@ public class SearchContactsListAdapter extends BaseAdapter {
private ProgressBar progressBar;
private boolean mOnlySipContact = false;
private View.OnClickListener listener;
private int oldSize;
public List<ContactAddress> getContacts() {
return contacts;
@ -82,7 +82,6 @@ public class SearchContactsListAdapter extends BaseAdapter {
progressBar = pB;
setContactsSelectedList(null);
setContactsList(contactsList);
oldSize = 0;
}
private boolean contactIsSelected(ContactAddress ca) {
@ -172,7 +171,6 @@ public class SearchContactsListAdapter extends BaseAdapter {
if (ContactsManager.getInstance() != null) {
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
}
oldSize = 0;
return;
}
@ -213,7 +211,6 @@ public class SearchContactsListAdapter extends BaseAdapter {
}
}
oldSize = search.length();
contacts = result;
resultContactsSearch.setAdapter(this);
this.notifyDataSetChanged();
@ -256,6 +253,10 @@ public class SearchContactsListAdapter extends BaseAdapter {
holder.name.setVisibility(View.VISIBLE);
holder.name.setText(contact.getAddress().getDisplayName());
}
} else if (address != null) {
Address tmpAddr = Factory.instance().createAddress(address);
holder.name.setVisibility(View.VISIBLE);
holder.name.setText((tmpAddr.getDisplayName() != null) ? tmpAddr.getDisplayName() : tmpAddr.getUsername()) ;
} else {
holder.name.setVisibility(View.GONE);
}