Fix find contact again

This commit is contained in:
Margaux Clerc 2015-04-20 18:15:25 +02:00
parent b2893a4d20
commit 82173a8985
10 changed files with 19 additions and 18 deletions

View file

@ -356,7 +356,7 @@ public class ChatListFragment extends Fragment implements OnClickListener, OnIte
Log.e("Chat view cannot parse address",e); Log.e("Chat view cannot parse address",e);
return view; return view;
} }
Contact lContact = ContactsManager.getInstance().findContactWithAddress(address); Contact lContact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String message = ""; String message = "";
if (useNativeAPI) { if (useNativeAPI) {

View file

@ -150,6 +150,7 @@ public class ContactsManager {
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri); LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
if (friend != null) { if (friend != null) {
friend.edit(); friend.edit();
friend.enableSubscribes(false);
friend.setRefKey(contact.getID()); friend.setRefKey(contact.getID());
friend.done(); friend.done();
try { try {
@ -230,7 +231,7 @@ public class ContactsManager {
return null; return null;
} }
public Contact getContact(String id){ public Contact getContact(String id, ContentResolver contentResolver){
String[] projection = {ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME}; String[] projection = {ContactsContract.Data.CONTACT_ID, ContactsContract.Data.DISPLAY_NAME};
String selection = new StringBuilder() String selection = new StringBuilder()
.append(ContactsContract.Data.CONTACT_ID) .append(ContactsContract.Data.CONTACT_ID)
@ -296,7 +297,7 @@ public class ContactsManager {
} }
} }
private Contact checkPhoneQueryResult(Cursor c, String columnPhone, String columnId, String username) { private Contact checkPhoneQueryResult(ContentResolver contentResolver, Cursor c, String columnPhone, String columnId, String username) {
boolean contactFound = false; boolean contactFound = false;
if (c != null) { if (c != null) {
@ -320,7 +321,7 @@ public class ContactsManager {
} }
if(contactFound){ if(contactFound){
Contact contact = getContact(c.getString(c.getColumnIndex(columnId))); Contact contact = getContact(c.getString(c.getColumnIndex(columnId)), contentResolver);
c.close(); c.close();
return contact; return contact;
} }
@ -330,7 +331,7 @@ public class ContactsManager {
return null; return null;
} }
public Contact findContactWithAddress(LinphoneAddress address){ public Contact findContactWithAddress(ContentResolver contentResolver, LinphoneAddress address){
String sipUri = address.asStringUriOnly(); String sipUri = address.asStringUriOnly();
if (sipUri.startsWith("sip:")) if (sipUri.startsWith("sip:"))
sipUri = sipUri.substring(4); sipUri = sipUri.substring(4);
@ -338,7 +339,7 @@ public class ContactsManager {
if(LinphoneManager.getLc().getFriendList() != null && LinphoneManager.getLc().getFriendList().length > 0) { if(LinphoneManager.getLc().getFriendList() != null && LinphoneManager.getLc().getFriendList().length > 0) {
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) { for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
if (friend.getAddress().equals(address)) { if (friend.getAddress().equals(address)) {
return getContact(friend.getRefKey()); return getContact(friend.getRefKey(), contentResolver);
} }
} }
} }
@ -368,7 +369,7 @@ public class ContactsManager {
Uri lookupUri = Uri.withAppendedPath(android.provider.ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address.getUserName())); Uri lookupUri = Uri.withAppendedPath(android.provider.ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address.getUserName()));
projection = new String[] {ContactsContract.PhoneLookup._ID,ContactsContract.PhoneLookup.NUMBER,ContactsContract.PhoneLookup.DISPLAY_NAME }; projection = new String[] {ContactsContract.PhoneLookup._ID,ContactsContract.PhoneLookup.NUMBER,ContactsContract.PhoneLookup.DISPLAY_NAME };
Cursor c = contentResolver.query(lookupUri, projection, null, null, null); Cursor c = contentResolver.query(lookupUri, projection, null, null, null);
contact = checkPhoneQueryResult(c, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup._ID, address.getUserName()); contact = checkPhoneQueryResult(contentResolver, c, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup._ID, address.getUserName());
if (contact != null) { if (contact != null) {
return contact; return contact;

View file

@ -112,7 +112,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
LinphoneAddress lAddress; LinphoneAddress lAddress;
try { try {
lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri); lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress); Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
if (contact != null) { if (contact != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(),contact.getPhotoUri(), R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(),contact.getPhotoUri(), R.drawable.unknown_small);
view.findViewById(R.id.addContactRow).setVisibility(View.GONE); view.findViewById(R.id.addContactRow).setVisibility(View.GONE);

View file

@ -178,7 +178,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnChil
address = log.getTo(); address = log.getTo();
} }
Contact contact = ContactsManager.getInstance().findContactWithAddress(address); Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String sipUri = address.asStringUriOnly(); String sipUri = address.asStringUriOnly();
if (contact == null) { if (contact == null) {
if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { if (getResources().getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {

View file

@ -392,7 +392,7 @@ public class HistorySimpleFragment extends Fragment implements OnClickListener,
callDirection.setImageBitmap(outgoingCall); callDirection.setImageBitmap(outgoingCall);
} }
Contact c = ContactsManager.getInstance().findContactWithAddress(address); Contact c = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String displayName = null; String displayName = null;
final String sipUri = address.asStringUriOnly(); final String sipUri = address.asStringUriOnly();
if(c != null){ if(c != null){

View file

@ -1299,7 +1299,7 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
// Image Row // Image Row
LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false); LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress); Contact contact = ContactsManager.getInstance().findContactWithAddress(imageView.getContext().getContentResolver(), lAddress);
if(contact != null) { if(contact != null) {
displayOrHideContactPicture(imageView, contact.getPhotoUri(), false); displayOrHideContactPicture(imageView, contact.getPhotoUri(), false);
} else { } else {
@ -1326,7 +1326,7 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
private void setContactName(LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) { private void setContactName(LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) {
TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber); TextView contact = (TextView) callView.findViewById(R.id.contactNameOrNumber);
Contact lContact = ContactsManager.getInstance().findContactWithAddress(lAddress); Contact lContact = ContactsManager.getInstance().findContactWithAddress(callView.getContext().getContentResolver(), lAddress);
if (lContact == null) { if (lContact == null) {
if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) { if (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
contact.setText(lAddress.getUserName()); contact.setText(lAddress.getUserName());

View file

@ -124,7 +124,7 @@ public class IncomingCallActivity extends Activity implements LinphoneSliderTrig
} }
LinphoneAddress address = mCall.getRemoteAddress(); LinphoneAddress address = mCall.getRemoteAddress();
// May be greatly sped up using a drawable cache // May be greatly sped up using a drawable cache
Contact contact = ContactsManager.getInstance().findContactWithAddress(address); Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), contact != null ? contact.getPhotoUri() : null, R.drawable.unknown_small); LinphoneUtils.setImagePictureFromUri(this, mPictureView.getView(), contact != null ? contact.getPhotoUri() : null, R.drawable.unknown_small);
// To be done after findUriPictureOfContactAndSetDisplayName called // To be done after findUriPictureOfContactAndSetDisplayName called

View file

@ -518,7 +518,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
Log.e("Cannot display history details",e); Log.e("Cannot display history details",e);
return; return;
} }
Contact c = ContactsManager.getInstance().findContactWithAddress(lAddress); Contact c = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
String displayName = c != null ? c.getName() : null; String displayName = c != null ? c.getName() : null;
String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null; String pictureUri = c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
@ -611,7 +611,7 @@ public class LinphoneActivity extends FragmentActivity implements OnClickListene
Log.e("Cannot display chat",e); Log.e("Cannot display chat",e);
return; return;
} }
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress); Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
String displayName = contact != null ? contact.getName() : null; String displayName = contact != null ? contact.getName() : null;
String pictureUri = contact != null && contact.getPhotoUri() != null ? contact.getPhotoUri().toString() : null; String pictureUri = contact != null && contact.getPhotoUri() != null ? contact.getPhotoUri().toString() : null;

View file

@ -715,7 +715,7 @@ public class LinphoneManager implements LinphoneCoreListener {
} }
try { try {
Contact contact = ContactsManager.getInstance().findContactWithAddress(from); Contact contact = ContactsManager.getInstance().findContactWithAddress(mServiceContext.getContentResolver(),from);
if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat__message_notification)) { if (!mServiceContext.getResources().getBoolean(R.bool.disable_chat__message_notification)) {
if(contact != null) { if(contact != null) {
LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getName(), textMessage); LinphoneService.instance().displayMessageNotification(from.asStringUriOnly(), contact.getName(), textMessage);

View file

@ -312,7 +312,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);
Contact contact = ContactsManager.getInstance().findContactWithAddress(address); Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), address);
Uri pictureUri = contact != null ? contact.getPhotoUri() : null; Uri pictureUri = contact != null ? contact.getPhotoUri() : null;
Bitmap bm = null; Bitmap bm = null;
try { try {
@ -390,7 +390,7 @@ public final class LinphoneService extends Service {
Uri pictureUri = null; Uri pictureUri = null;
try { try {
Contact contact = ContactsManager.getInstance().findContactWithAddress(LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri)); Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), LinphoneCoreFactory.instance().createLinphoneAddress(fromSipUri));
if (contact != null) if (contact != null)
pictureUri = contact.getPhotoUri(); pictureUri = contact.getPhotoUri();
} catch (LinphoneCoreException e1) { } catch (LinphoneCoreException e1) {