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() { public List<LinphoneContact> fetchContactsAsync() {
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>(); List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) { if (mAccount != null && hasContactsAccess()) {
LinphoneContact contact = new LinphoneContact(); Cursor c = Compatibility.getContactsCursor(contentResolver, null);
contact.setFriend(friend); if (c != null) {
contact.refresh(); while (c.moveToNext()) {
contacts.add(contact); 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; for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
String refkey = friend.getRefKey();
Cursor c = Compatibility.getContactsCursor(contentResolver, null); if (refkey != null) {
if (c != null) { boolean found = false;
while (c.moveToNext()) { for (LinphoneContact contact : contacts) {
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID)); 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(); LinphoneContact contact = new LinphoneContact();
contact.setAndroidId(id); contact.setFriend(friend);
contact.refresh();
contacts.add(contact); contacts.add(contact);
} }
c.close(); }
for (LinphoneContact contact : contacts) {
contact.refresh();
} }
return contacts; return contacts;

View file

@ -331,7 +331,7 @@ public class LinphoneContact implements Serializable {
} }
friend.done(); friend.done();
if (!isAndroidContact() && friend.getAddress() != null) { if (friend.getAddress() != null) {
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) { if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
try { try {
lc.addFriend(friend); 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);
}
}
} }
} }
} }