Use vCard given/familly names + improved/fixed LinphoneFriends update/creation
This commit is contained in:
parent
3fa4b6023f
commit
4ff4d53e76
2 changed files with 70 additions and 82 deletions
|
@ -351,25 +351,30 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
return androidId;
|
||||
}
|
||||
|
||||
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>();
|
||||
private void createOrUpdateFriend() {
|
||||
if (!isLinphoneFriend()) {
|
||||
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
||||
friend.enableSubscribes(false);
|
||||
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
||||
if (isAndroidContact()) {
|
||||
friend.setRefKey(getAndroidId());
|
||||
}
|
||||
}
|
||||
if (isLinphoneFriend()) {
|
||||
updateFriend();
|
||||
}
|
||||
}
|
||||
|
||||
if (isLinphoneFriend()) {
|
||||
boolean hasAddr = false;
|
||||
private void updateFriend() {
|
||||
if (!isLinphoneFriend()) return;
|
||||
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc == null) return;
|
||||
|
||||
friend.edit();
|
||||
friend.setFamillyName(lastName);
|
||||
friend.setGivenName(firstName);
|
||||
|
||||
for (LinphoneAddress address : friend.getAddresses()) {
|
||||
friend.removeAddress(address);
|
||||
}
|
||||
|
@ -382,7 +387,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
LinphoneAddress addr = lc.interpretUrl(noa.getValue());
|
||||
if (addr != null) {
|
||||
friend.addAddress(addr);
|
||||
hasAddr = true;
|
||||
}
|
||||
} catch (LinphoneCoreException e) {
|
||||
Log.e(e);
|
||||
|
@ -391,9 +395,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
friend.addPhoneNumber(noa.getValue());
|
||||
}
|
||||
}
|
||||
if (hasAddr) {
|
||||
friend.setName(fullName);
|
||||
}
|
||||
friend.done();
|
||||
|
||||
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() {
|
||||
|
@ -449,46 +466,17 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
addNumberOrAddress(noa);
|
||||
}
|
||||
|
||||
if (friend == null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
createOrUpdateFriend();
|
||||
} else if (isLinphoneFriend()) {
|
||||
fullName = friend.getName();
|
||||
lastName = friend.getFamillyName();
|
||||
firstName = friend.getGivenName();
|
||||
thumbnailUri = null;
|
||||
photoUri = null;
|
||||
|
||||
LinphoneAddress addr = friend.getAddress();
|
||||
if (addr != null) {
|
||||
addresses.add(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||
hasSipAddress = true;
|
||||
addNumberOrAddress(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a5008f43bf329434be939b60a744d60a33787e66
|
||||
Subproject commit 442cd8b9db8dc29aab1c5e9952bab389dd8d478c
|
Loading…
Reference in a new issue