Fixed contact lookup for history & chat

This commit is contained in:
Sylvain Berfini 2016-03-17 16:17:35 +01:00 committed by Jehan Monnier
parent a75da820ed
commit 8d65fab06c
11 changed files with 16 additions and 22 deletions

View file

@ -1557,7 +1557,7 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve
} }
private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) { private void setContactInformation(TextView contactName, ImageView contactPicture, LinphoneAddress lAddress) {
LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(contactName.getContext().getContentResolver(), lAddress); LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(lAddress);
if (lContact == null) { if (lContact == null) {
contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress)); contactName.setText(LinphoneUtils.getAddressDisplayName(lAddress));
contactPicture.setImageResource(R.drawable.avatar); contactPicture.setImageResource(R.drawable.avatar);
@ -1720,7 +1720,7 @@ public class CallActivity extends Activity implements OnClickListener, SensorEve
conferenceList.setId(index + 1); conferenceList.setId(index + 1);
TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber); TextView contact = (TextView) confView.findViewById(R.id.contactNameOrNumber);
LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(),call.getRemoteAddress()); LinphoneContact lContact = ContactsManager.getInstance().findContactFromAddress(call.getRemoteAddress());
if (lContact == null) { if (lContact == null) {
contact.setText(call.getRemoteAddress().getUserName()); contact.setText(call.getRemoteAddress().getUserName());
} else { } else {

View file

@ -232,7 +232,7 @@ public class CallIncomingActivity extends Activity implements LinphoneSliderTrig
return; return;
} }
LinphoneAddress address = mCall.getRemoteAddress(); LinphoneAddress address = mCall.getRemoteAddress();
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(address);
if (contact != null) { if (contact != null) {
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri()); LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
name.setText(contact.getFullName()); name.setText(contact.getFullName());

View file

@ -143,7 +143,7 @@ public class CallOutgoingActivity extends Activity implements OnClickListener{
} }
LinphoneAddress address = mCall.getRemoteAddress(); LinphoneAddress address = mCall.getRemoteAddress();
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(address);
if (contact != null) { if (contact != null) {
LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri()); LinphoneUtils.setImagePictureFromUri(this, contactPicture, contact.getPhotoUri(), contact.getThumbnailUri());
name.setText(contact.getFullName()); name.setText(contact.getFullName());

View file

@ -459,7 +459,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
chatRoom = lc.getChatRoom(lAddress); chatRoom = lc.getChatRoom(lAddress);
chatRoom.markAsRead(); chatRoom.markAsRead();
LinphoneActivity.instance().updateMissedChatCount(); LinphoneActivity.instance().updateMissedChatCount();
contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), lAddress); contact = ContactsManager.getInstance().findContactFromAddress(lAddress);
if (chatRoom != null) { if (chatRoom != null) {
displayChatHeader(lAddress); displayChatHeader(lAddress);
dispayMessageList(); dispayMessageList();

View file

@ -348,7 +348,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
return view; return view;
} }
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), address); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(address);
String message = ""; String message = "";
Long time; Long time;

View file

@ -109,18 +109,12 @@ public class ContactsManager {
} }
public LinphoneContact findContactFromAddress(LinphoneAddress address) { public LinphoneContact findContactFromAddress(LinphoneAddress address) {
return findContactFromAddress(null, address);
}
public LinphoneContact findContactFromAddress(ContentResolver contentResolver, LinphoneAddress address) {
String sipUri = address.asStringUriOnly(); String sipUri = address.asStringUriOnly();
if (sipUri.startsWith("sip:")) { String username = address.getUserName();
sipUri = sipUri.substring(4);
}
for (LinphoneContact c: getContacts()) { for (LinphoneContact c: getContacts()) {
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) { for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
if (noa.getValue().equals(sipUri)) { if ((noa.isSIPAddress() && (noa.getValue().equals(sipUri) || noa.getValue().equals(sipUri.substring(4)))) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
return c; return c;
} }
} }

View file

@ -108,7 +108,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
if(lAddress != null) { if(lAddress != null) {
contactAddress.setText(lAddress.asStringUriOnly()); contactAddress.setText(lAddress.asStringUriOnly());
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), lAddress); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(lAddress);
if (contact != null) { if (contact != null) {
contactName.setText(contact.getFullName()); contactName.setText(contact.getFullName());
LinphoneUtils.setImagePictureFromUri(view.getContext(),contactPicture,contact.getPhotoUri(),contact.getThumbnailUri()); LinphoneUtils.setImagePictureFromUri(view.getContext(),contactPicture,contact.getPhotoUri(),contact.getThumbnailUri());

View file

@ -440,7 +440,7 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
holder.callDirection.setImageResource(R.drawable.call_status_outgoing); holder.callDirection.setImageResource(R.drawable.call_status_outgoing);
} }
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(getActivity().getContentResolver(), address); LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
String displayName = null; String displayName = null;
final String sipUri = address.asString(); final String sipUri = address.asString();
if(c != null){ if(c != null){

View file

@ -545,7 +545,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
//TODO display error message //TODO display error message
return; return;
} }
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), lAddress); LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(lAddress);
String displayName = c != null ? c.getFullName() : LinphoneUtils.getAddressDisplayName(sipUri); String displayName = c != null ? c.getFullName() : LinphoneUtils.getAddressDisplayName(sipUri);
String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null; String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
@ -670,7 +670,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
Log.e("Cannot display chat", e); Log.e("Cannot display chat", e);
return; return;
} }
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), lAddress); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(lAddress);
displayName = contact != null ? contact.getFullName() : null; displayName = contact != null ? contact.getFullName() : null;
if (contact != null && contact.getPhotoUri() != null) { if (contact != null && contact.getPhotoUri() != null) {

View file

@ -864,7 +864,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
} }
try { try {
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(mServiceContext.getContentResolver(), from); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(from);
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) { if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat_message_notification)) {
if (LinphoneActivity.isInstanciated() && !LinphoneActivity.instance().displayChatMessageNotification(from.asStringUriOnly())) { if (LinphoneActivity.isInstanciated() && !LinphoneActivity.instance().displayChatMessageNotification(from.asStringUriOnly())) {
return; return;

View file

@ -315,7 +315,7 @@ public final class LinphoneService extends Service {
LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null); LinphoneAddress address = LinphoneCoreFactory.instance().createLinphoneAddress(userName,domain,null);
address.setDisplayName(displayName); address.setDisplayName(displayName);
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), address); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(address);
Uri pictureUri = contact != null ? contact.getPhotoUri() : null; Uri pictureUri = contact != null ? contact.getPhotoUri() : null;
Bitmap bm = null; Bitmap bm = null;
try { try {
@ -393,7 +393,7 @@ public final class LinphoneService extends Service {
Uri pictureUri = null; Uri pictureUri = null;
try { try {
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(getContentResolver(), LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri)); LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
if (contact != null) if (contact != null)
pictureUri = contact.getThumbnailUri(); pictureUri = contact.getThumbnailUri();
} catch (LinphoneCoreException e1) { } catch (LinphoneCoreException e1) {