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,6 +351,69 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
return androidId;
|
return androidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createOrUpdateFriend() {
|
||||||
|
if (!isLinphoneFriend()) {
|
||||||
|
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
||||||
|
friend.enableSubscribes(false);
|
||||||
|
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
||||||
|
if (isAndroidContact()) {
|
||||||
|
friend.setRefKey(getAndroidId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isLinphoneFriend()) {
|
||||||
|
updateFriend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
for (String phone : friend.getPhoneNumbers()) {
|
||||||
|
friend.removePhoneNumber(phone);
|
||||||
|
}
|
||||||
|
for (LinphoneNumberOrAddress noa : addresses) {
|
||||||
|
if (noa.isSIPAddress()) {
|
||||||
|
try {
|
||||||
|
LinphoneAddress addr = lc.interpretUrl(noa.getValue());
|
||||||
|
if (addr != null) {
|
||||||
|
friend.addAddress(addr);
|
||||||
|
}
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
Log.e(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
friend.addPhoneNumber(noa.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
friend.setName(fullName);
|
||||||
|
friend.done();
|
||||||
|
|
||||||
|
if (friend.getAddress() != null) {
|
||||||
|
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
|
||||||
|
try {
|
||||||
|
lc.addFriend(friend);
|
||||||
|
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
||||||
|
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
||||||
|
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
|
||||||
|
ContactsManager.getInstance().fetchContactsAsync();
|
||||||
|
}
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
Log.e(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
||||||
try {
|
try {
|
||||||
|
@ -364,53 +427,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLinphoneFriend()) {
|
createOrUpdateFriend();
|
||||||
boolean hasAddr = false;
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
|
||||||
if (lc == null) return;
|
|
||||||
|
|
||||||
friend.edit();
|
|
||||||
for (LinphoneAddress address : friend.getAddresses()) {
|
|
||||||
friend.removeAddress(address);
|
|
||||||
}
|
|
||||||
for (String phone : friend.getPhoneNumbers()) {
|
|
||||||
friend.removePhoneNumber(phone);
|
|
||||||
}
|
|
||||||
for (LinphoneNumberOrAddress noa : addresses) {
|
|
||||||
if (noa.isSIPAddress()) {
|
|
||||||
try {
|
|
||||||
LinphoneAddress addr = lc.interpretUrl(noa.getValue());
|
|
||||||
if (addr != null) {
|
|
||||||
friend.addAddress(addr);
|
|
||||||
hasAddr = true;
|
|
||||||
}
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
Log.e(e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
friend.addPhoneNumber(noa.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasAddr) {
|
|
||||||
friend.setName(fullName);
|
|
||||||
}
|
|
||||||
friend.done();
|
|
||||||
|
|
||||||
if (friend.getAddress() != null) {
|
|
||||||
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
|
|
||||||
try {
|
|
||||||
lc.addFriend(friend);
|
|
||||||
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
|
||||||
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
|
||||||
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
|
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
|
||||||
}
|
|
||||||
} catch (LinphoneCoreException e) {
|
|
||||||
Log.e(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
Loading…
Reference in a new issue