Use vCard given/familly names + improved/fixed LinphoneFriends update/creation

This commit is contained in:
Sylvain Berfini 2016-07-21 17:16:02 +02:00
parent 3fa4b6023f
commit 4ff4d53e76
2 changed files with 70 additions and 82 deletions

View file

@ -351,25 +351,30 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
return androidId; return androidId;
} }
public void save() { private void createOrUpdateFriend() {
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) { if (!isLinphoneFriend()) {
try { friend = LinphoneCoreFactory.instance().createLinphoneFriend();
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit); friend.enableSubscribes(false);
createLinphoneTagIfNeeded(); friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
} catch (Exception e) { if (isAndroidContact()) {
Log.e(e); friend.setRefKey(getAndroidId());
} finally { }
changesToCommit = new ArrayList<ContentProviderOperation>(); }
changesToCommit2 = new ArrayList<ContentProviderOperation>(); if (isLinphoneFriend()) {
updateFriend();
} }
} }
if (isLinphoneFriend()) { private void updateFriend() {
boolean hasAddr = false; if (!isLinphoneFriend()) return;
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null) return; if (lc == null) return;
friend.edit(); friend.edit();
friend.setFamillyName(lastName);
friend.setGivenName(firstName);
for (LinphoneAddress address : friend.getAddresses()) { for (LinphoneAddress address : friend.getAddresses()) {
friend.removeAddress(address); friend.removeAddress(address);
} }
@ -382,7 +387,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
LinphoneAddress addr = lc.interpretUrl(noa.getValue()); LinphoneAddress addr = lc.interpretUrl(noa.getValue());
if (addr != null) { if (addr != null) {
friend.addAddress(addr); friend.addAddress(addr);
hasAddr = true;
} }
} catch (LinphoneCoreException e) { } catch (LinphoneCoreException e) {
Log.e(e); Log.e(e);
@ -391,9 +395,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.addPhoneNumber(noa.getValue()); friend.addPhoneNumber(noa.getValue());
} }
} }
if (hasAddr) {
friend.setName(fullName); friend.setName(fullName);
}
friend.done(); friend.done();
if (friend.getAddress() != null) { if (friend.getAddress() != null) {
@ -411,6 +413,21 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
} }
} }
} }
public void save() {
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
try {
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit);
createLinphoneTagIfNeeded();
} catch (Exception e) {
Log.e(e);
} finally {
changesToCommit = new ArrayList<ContentProviderOperation>();
changesToCommit2 = new ArrayList<ContentProviderOperation>();
}
}
createOrUpdateFriend();
} }
public void delete() { public void delete() {
@ -449,46 +466,17 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
addNumberOrAddress(noa); addNumberOrAddress(noa);
} }
if (friend == null) { createOrUpdateFriend();
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
friend.setRefKey(getAndroidId());
// Disable subscribes for now
friend.enableSubscribes(false);
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
if (hasSipAddress) {
for (LinphoneNumberOrAddress noa : addresses) {
if (noa.isSIPAddress()) {
try {
LinphoneAddress addr = LinphoneManager.getLc().interpretUrl(noa.getValue());
if (addr != null) {
friend.addAddress(addr);
}
} catch (LinphoneCoreException e) {
Log.e(e);
}
} else {
friend.addPhoneNumber(noa.getValue());
}
}
}
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null && friend.getAddress() != null) {
friend.setName(fullName);
try {
lc.addFriend(friend);
} catch (LinphoneCoreException e) {
Log.e(e);
}
}
}
} else if (isLinphoneFriend()) { } else if (isLinphoneFriend()) {
fullName = friend.getName(); fullName = friend.getName();
lastName = friend.getFamillyName();
firstName = friend.getGivenName();
thumbnailUri = null; thumbnailUri = null;
photoUri = null; photoUri = null;
LinphoneAddress addr = friend.getAddress(); LinphoneAddress addr = friend.getAddress();
if (addr != null) { if (addr != null) {
addresses.add(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true)); addNumberOrAddress(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
hasSipAddress = true;
} }
} }
} }

@ -1 +1 @@
Subproject commit a5008f43bf329434be939b60a744d60a33787e66 Subproject commit 442cd8b9db8dc29aab1c5e9952bab389dd8d478c