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);
return view;
}
Contact lContact = ContactsManager.getInstance().findContactWithAddress(address);
Contact lContact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String message = "";
if (useNativeAPI) {

View file

@ -150,6 +150,7 @@ public class ContactsManager {
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend(sipUri);
if (friend != null) {
friend.edit();
friend.enableSubscribes(false);
friend.setRefKey(contact.getID());
friend.done();
try {
@ -230,7 +231,7 @@ public class ContactsManager {
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 selection = new StringBuilder()
.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;
if (c != null) {
@ -320,7 +321,7 @@ public class ContactsManager {
}
if(contactFound){
Contact contact = getContact(c.getString(c.getColumnIndex(columnId)));
Contact contact = getContact(c.getString(c.getColumnIndex(columnId)), contentResolver);
c.close();
return contact;
}
@ -330,7 +331,7 @@ public class ContactsManager {
return null;
}
public Contact findContactWithAddress(LinphoneAddress address){
public Contact findContactWithAddress(ContentResolver contentResolver, LinphoneAddress address){
String sipUri = address.asStringUriOnly();
if (sipUri.startsWith("sip:"))
sipUri = sipUri.substring(4);
@ -338,7 +339,7 @@ public class ContactsManager {
if(LinphoneManager.getLc().getFriendList() != null && LinphoneManager.getLc().getFriendList().length > 0) {
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
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()));
projection = new String[] {ContactsContract.PhoneLookup._ID,ContactsContract.PhoneLookup.NUMBER,ContactsContract.PhoneLookup.DISPLAY_NAME };
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) {
return contact;

View file

@ -112,7 +112,7 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
LinphoneAddress lAddress;
try {
lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress);
Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), lAddress);
if (contact != null) {
LinphoneUtils.setImagePictureFromUri(view.getContext(), contactPicture.getView(),contact.getPhotoUri(), R.drawable.unknown_small);
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();
}
Contact contact = ContactsManager.getInstance().findContactWithAddress(address);
Contact contact = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String sipUri = address.asStringUriOnly();
if (contact == null) {
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);
}
Contact c = ContactsManager.getInstance().findContactWithAddress(address);
Contact c = ContactsManager.getInstance().findContactWithAddress(getActivity().getContentResolver(), address);
String displayName = null;
final String sipUri = address.asStringUriOnly();
if(c != null){

View file

@ -1299,7 +1299,7 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
// Image Row
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) {
displayOrHideContactPicture(imageView, contact.getPhotoUri(), false);
} else {
@ -1326,7 +1326,7 @@ public class InCallActivity extends FragmentActivity implements OnClickListener
private void setContactName(LinearLayout callView, LinphoneAddress lAddress, String sipUri, Resources resources) {
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 (resources.getBoolean(R.bool.only_display_username_if_unknown) && LinphoneUtils.isSipAddress(sipUri)) {
contact.setText(lAddress.getUserName());

View file

@ -124,7 +124,7 @@ public class IncomingCallActivity extends Activity implements LinphoneSliderTrig
}
LinphoneAddress address = mCall.getRemoteAddress();
// 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);
// 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);
return;
}
Contact c = ContactsManager.getInstance().findContactWithAddress(lAddress);
Contact c = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
String displayName = c != null ? c.getName() : 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);
return;
}
Contact contact = ContactsManager.getInstance().findContactWithAddress(lAddress);
Contact contact = ContactsManager.getInstance().findContactWithAddress(getContentResolver(), lAddress);
String displayName = contact != null ? contact.getName() : null;
String pictureUri = contact != null && contact.getPhotoUri() != null ? contact.getPhotoUri().toString() : null;

View file

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