Create friend for Android contact is it has a SIP address

This commit is contained in:
Sylvain Berfini 2016-03-22 16:54:36 +01:00 committed by Jehan Monnier
parent acf9d87867
commit 8c885640fc
2 changed files with 42 additions and 15 deletions

View file

@ -193,25 +193,44 @@ public class ContactsManager extends ContentObserver {
public List<LinphoneContact> fetchContactsAsync() {
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
LinphoneContact contact = new LinphoneContact();
contact.setFriend(friend);
contact.refresh();
contacts.add(contact);
if (mAccount != null && hasContactsAccess()) {
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
if (c != null) {
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
LinphoneContact contact = new LinphoneContact();
contact.setAndroidId(id);
contacts.add(contact);
}
c.close();
}
}
if (mAccount == null || !hasContactsAccess()) return contacts;
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
if (c != null) {
while (c.moveToNext()) {
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
String refkey = friend.getRefKey();
if (refkey != null) {
boolean found = false;
for (LinphoneContact contact : contacts) {
if (refkey.equals(contact.getAndroidId())) {
contact.setFriend(friend);
found = true;
break;
}
}
if (!found) {
LinphoneContact contact = new LinphoneContact();
contact.setFriend(friend);
contacts.add(contact);
}
} else {
LinphoneContact contact = new LinphoneContact();
contact.setAndroidId(id);
contact.refresh();
contact.setFriend(friend);
contacts.add(contact);
}
c.close();
}
for (LinphoneContact contact : contacts) {
contact.refresh();
}
return contacts;

View file

@ -331,7 +331,7 @@ public class LinphoneContact implements Serializable {
}
friend.done();
if (!isAndroidContact() && friend.getAddress() != null) {
if (friend.getAddress() != null) {
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
try {
lc.addFriend(friend);
@ -404,6 +404,14 @@ public class LinphoneContact implements Serializable {
}
}
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) {
try {
lc.addFriend(friend);
} catch (LinphoneCoreException e) {
Log.e(e);
}
}
}
}
}