add default proxy config domain to contact if domain is not specified

This commit is contained in:
Margaux Clerc 2015-04-15 15:43:44 +02:00
parent 69950b81ef
commit 8bfcafa9a3
2 changed files with 36 additions and 12 deletions

View file

@ -300,7 +300,7 @@ public class ContactsManager {
public boolean isContactHasAddress(Contact contact, String address){
if(contact != null) {
contact.refresh(contentResolver);
if (contact.getNumbersOrAddresses().contains(address)) {
if (contact.getNumbersOrAddresses().contains(address) || contact.getNumbersOrAddresses().contains("sip:"+ address)) {
return true;
} else {
return false;

View file

@ -4,6 +4,7 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Version;
import org.linphone.ui.AvatarWithShadow;
import android.annotation.SuppressLint;
@ -399,6 +400,7 @@ public class EditContactFragment extends Fragment {
contactsManager.createNewFriend(c, numberOrAddress.newNumberOrAddress);
}
} else {
if (!contactsManager.isContactHasAddress(contact, numberOrAddress.newNumberOrAddress)){
if (numberOrAddress.oldNumberOrAddress == null) {
contactsManager.createNewFriend(contact, numberOrAddress.newNumberOrAddress);
} else {
@ -409,6 +411,7 @@ public class EditContactFragment extends Fragment {
}
}
}
}
class NewOrUpdatedNumberOrAddress {
private String oldNumberOrAddress;
@ -486,8 +489,15 @@ public class EditContactFragment extends Fragment {
if (isSipAddress) {
if (newNumberOrAddress.startsWith("sip:"))
newNumberOrAddress = newNumberOrAddress.substring(4);
if(!newNumberOrAddress.contains("@"))
if(!newNumberOrAddress.contains("@")) {
//Use default proxy config domain if it exists
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if(lpc != null){
newNumberOrAddress = newNumberOrAddress + "@" + lpc.getDomain();
} else {
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
}
}
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress);
} else {
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
@ -504,8 +514,15 @@ public class EditContactFragment extends Fragment {
if (isSipAddress) {
if (newNumberOrAddress.startsWith("sip:"))
newNumberOrAddress = newNumberOrAddress.substring(4);
if(!newNumberOrAddress.contains("@"))
if(!newNumberOrAddress.contains("@")) {
//Use default proxy config domain if it exists
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if(lpc != null){
newNumberOrAddress = newNumberOrAddress + "@" + lpc.getDomain();
} else {
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
}
}
Compatibility.addSipAddressToContact(getActivity(), ops, newNumberOrAddress, rawContactId);
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
@ -530,8 +547,15 @@ public class EditContactFragment extends Fragment {
if (isSipAddress) {
if (newNumberOrAddress.startsWith("sip:"))
newNumberOrAddress = newNumberOrAddress.substring(4);
if(!newNumberOrAddress.contains("@"))
if(!newNumberOrAddress.contains("@")) {
//Use default proxy config domain if it exists
LinphoneProxyConfig lpc = LinphoneManager.getLc().getDefaultProxyConfig();
if(lpc != null){
newNumberOrAddress = newNumberOrAddress + "@" + lpc.getDomain();
} else {
newNumberOrAddress = newNumberOrAddress + "@" + getResources().getString(R.string.default_domain);
}
}
Compatibility.updateSipAddressForContact(ops, oldNumberOrAddress, newNumberOrAddress, String.valueOf(contactID));
Compatibility.updateLinphoneContactTag(getActivity(), ops, newNumberOrAddress, oldNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
} else {