diff --git a/src/org/linphone/ContactsManager.java b/src/org/linphone/ContactsManager.java index 1852ef93b..9fbc50d84 100644 --- a/src/org/linphone/ContactsManager.java +++ b/src/org/linphone/ContactsManager.java @@ -548,7 +548,7 @@ public class ContactsManager { //Remove linphone contact tag if the contact has no sip address if (LinphoneActivity.isInstanciated() && LinphoneActivity.instance().getResources().getBoolean(R.bool.use_linphone_tag)) { - if (removeContactTagIsNeeded(contact) && isContactHasLinphoneTag(contact, contentResolver)) { + if (removeContactTagIsNeeded(contact) && findRawLinphoneContactID(contact.getID()) != null) { removeLinphoneContactTag(contact); } } diff --git a/src/org/linphone/EditContactFragment.java b/src/org/linphone/EditContactFragment.java index eed7b0f70..b63bd5cad 100644 --- a/src/org/linphone/EditContactFragment.java +++ b/src/org/linphone/EditContactFragment.java @@ -102,6 +102,7 @@ public class EditContactFragment extends Fragment { try { getActivity().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); addLinphoneFriendIfNeeded(); + removeLinphoneTagIfNeeded(); contactsManager.prepareContactsInBackground(); } catch (Exception e) { e.printStackTrace(); @@ -415,6 +416,21 @@ public class EditContactFragment extends Fragment { } } } + + private void removeLinphoneTagIfNeeded(){ + if(!isNewContact) { + boolean areAllSipFielsEmpty = true; + for (NewOrUpdatedNumberOrAddress nounoa : numbersAndAddresses) { + if (!nounoa.isSipAddress && (nounoa.oldNumberOrAddress != null && !nounoa.oldNumberOrAddress.equals("") || nounoa.newNumberOrAddress != null && !nounoa.newNumberOrAddress.equals(""))) { + areAllSipFielsEmpty = false; + break; + } + } + if (areAllSipFielsEmpty && contactsManager.findRawLinphoneContactID(contact.getID()) != null) { + contactsManager.removeLinphoneContactTag(contact); + } + } + } class NewOrUpdatedNumberOrAddress { private String oldNumberOrAddress;