Fallback mode (or forced mode) using Linphone Friends seems to be working, and mixed Android contacts and Linphone friends also seems to be working
This commit is contained in:
parent
f3a6e1c66f
commit
c96b896f73
5 changed files with 194 additions and 238 deletions
|
@ -12,7 +12,7 @@
|
|||
<bool name="orientation_portrait_only">false</bool>
|
||||
<bool name="show_statusbar_only_on_dialer">false</bool>
|
||||
<bool name="replace_assistant_with_old_interface">false</bool>
|
||||
|
||||
<bool name="force_use_of_linphone_friends">false</bool>
|
||||
|
||||
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
|
||||
|
||||
|
|
|
@ -96,7 +96,8 @@ public class ContactEditorFragment extends Fragment {
|
|||
view = inflater.inflate(R.layout.contact_edit, container, false);
|
||||
|
||||
phoneNumbersSection = (LinearLayout) view.findViewById(R.id.phone_numbers);
|
||||
if (getResources().getBoolean(R.bool.hide_phone_numbers_in_editor)) {
|
||||
if (getResources().getBoolean(R.bool.hide_phone_numbers_in_editor) || !ContactsManager.getInstance().hasContactsAccess()) {
|
||||
//Currently linphone friends don't support phone numbers, so hide them
|
||||
phoneNumbersSection.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -538,162 +539,11 @@ public class ContactEditorFragment extends Fragment {
|
|||
delete.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (contact != null) {
|
||||
contact.removeNumberOrAddress(nounoa);
|
||||
}
|
||||
numbersAndAddresses.remove(nounoa);
|
||||
view.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
controls.addView(view);
|
||||
}
|
||||
|
||||
/*class NewOrUpdatedNumberOrAddress {
|
||||
private String oldNumberOrAddress;
|
||||
private String newNumberOrAddress;
|
||||
private boolean isSipAddress;
|
||||
|
||||
public NewOrUpdatedNumberOrAddress() {
|
||||
oldNumberOrAddress = null;
|
||||
newNumberOrAddress = null;
|
||||
isSipAddress = false;
|
||||
}
|
||||
|
||||
public NewOrUpdatedNumberOrAddress(boolean isSip) {
|
||||
oldNumberOrAddress = null;
|
||||
newNumberOrAddress = null;
|
||||
isSipAddress = isSip;
|
||||
}
|
||||
|
||||
public NewOrUpdatedNumberOrAddress(String old, boolean isSip) {
|
||||
oldNumberOrAddress = old;
|
||||
newNumberOrAddress = null;
|
||||
isSipAddress = isSip;
|
||||
}
|
||||
|
||||
public NewOrUpdatedNumberOrAddress(boolean isSip, String newSip) {
|
||||
oldNumberOrAddress = null;
|
||||
newNumberOrAddress = newSip;
|
||||
isSipAddress = isSip;
|
||||
}
|
||||
|
||||
public void setNewNumberOrAddress(String newN) {
|
||||
newNumberOrAddress = newN;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (newNumberOrAddress == null || newNumberOrAddress.equals(oldNumberOrAddress))
|
||||
return;
|
||||
|
||||
if (oldNumberOrAddress == null) {
|
||||
// New number to add
|
||||
addNewNumber();
|
||||
} else {
|
||||
// Old number to update
|
||||
updateNumber();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
}
|
||||
|
||||
private void addNewNumber() {
|
||||
if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNewContact) {
|
||||
if (isSipAddress) {
|
||||
if (newNumberOrAddress.startsWith("sip:"))
|
||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||
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)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newNumberOrAddress)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.LABEL, getString(R.string.addressbook_label))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
String rawContactId = contactsManager.findRawContactID(getActivity().getContentResolver(),String.valueOf(contactID));
|
||||
if (isSipAddress) {
|
||||
if (newNumberOrAddress.startsWith("sip:"))
|
||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||
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);
|
||||
if (getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||
Compatibility.addLinphoneContactTag(getActivity(), ops, newNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
||||
}
|
||||
} else {
|
||||
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newNumberOrAddress)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.LABEL, getString(R.string.addressbook_label))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNumber() {
|
||||
if (newNumberOrAddress == null || newNumberOrAddress.length() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSipAddress) {
|
||||
if (newNumberOrAddress.startsWith("sip:"))
|
||||
newNumberOrAddress = newNumberOrAddress.substring(4);
|
||||
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));
|
||||
if (getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||
Compatibility.updateLinphoneContactTag(getActivity(), ops, newNumberOrAddress, oldNumberOrAddress, contactsManager.findRawLinphoneContactID(String.valueOf(contactID)));
|
||||
}
|
||||
} else {
|
||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND "
|
||||
+ ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND "
|
||||
+ ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
||||
String[] args = new String[] { String.valueOf(contactID), oldNumberOrAddress };
|
||||
|
||||
ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, newNumberOrAddress)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
|
@ -121,7 +121,7 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
|
||||
public boolean hasContactsAccess() {
|
||||
return hasContactAccess;
|
||||
return hasContactAccess && !context.getResources().getBoolean(R.bool.force_use_of_linphone_friends);
|
||||
}
|
||||
|
||||
public void setLinphoneContactsPrefered(boolean isPrefered) {
|
||||
|
@ -195,13 +195,12 @@ public class ContactsManager extends ContentObserver {
|
|||
|
||||
for (LinphoneFriend friend : LinphoneManager.getLc().getFriendList()) {
|
||||
LinphoneContact contact = new LinphoneContact();
|
||||
LinphoneAddress addr = friend.getAddress();
|
||||
contact.setFullName(addr.getDisplayName());
|
||||
contact.addNumberOrAddress(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||
contact.setFriend(friend);
|
||||
contact.refresh();
|
||||
contacts.add(contact);
|
||||
}
|
||||
|
||||
if (mAccount == null || !hasContactAccess) return contacts;
|
||||
if (mAccount == null || !hasContactsAccess()) return contacts;
|
||||
|
||||
Cursor c = Compatibility.getContactsCursor(contentResolver, null);
|
||||
if (c != null) {
|
||||
|
|
|
@ -23,6 +23,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneFriend;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
@ -93,7 +95,13 @@ public class LinphoneContact implements Serializable {
|
|||
|
||||
firstName = fn;
|
||||
lastName = ln;
|
||||
fullName = firstName + " " + lastName;
|
||||
if (firstName != null && lastName != null && firstName.length() > 0 && lastName.length() > 0) {
|
||||
fullName = firstName + " " + lastName;
|
||||
} else if (firstName != null && firstName.length() > 0) {
|
||||
fullName = firstName;
|
||||
} else if (lastName != null && lastName.length() > 0) {
|
||||
fullName = lastName;
|
||||
}
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
|
@ -125,20 +133,24 @@ public class LinphoneContact implements Serializable {
|
|||
}
|
||||
|
||||
public void setPhoto(byte[] photo) {
|
||||
if (isAndroidContact() && photo != null) {
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
} else {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
if (photo != null) {
|
||||
if (isAndroidContact()) {
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
} else {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||
.build());
|
||||
}
|
||||
} else if (isLinphoneFriend()) {
|
||||
//TODO: prepare photo changes in friend
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -172,70 +184,108 @@ public class LinphoneContact implements Serializable {
|
|||
}
|
||||
|
||||
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||
if (isAndroidContact() && noa.getOldValue() != null) {
|
||||
String select;
|
||||
if (noa.isSIPAddress()) {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
||||
} else {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
||||
if (noa != null && noa.getOldValue() != null) {
|
||||
if (isAndroidContact()) {
|
||||
String select;
|
||||
if (noa.isSIPAddress()) {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
||||
} else {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
||||
}
|
||||
String[] args = new String[]{ getAndroidId(), noa.getOldValue() };
|
||||
|
||||
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build());
|
||||
}
|
||||
|
||||
if (isLinphoneFriend()) {
|
||||
if (!noa.getOldValue().startsWith("sip:")) {
|
||||
noa.setOldValue("sip:" + noa.getOldValue());
|
||||
}
|
||||
LinphoneNumberOrAddress toRemove = null;
|
||||
for (LinphoneNumberOrAddress address : addresses) {
|
||||
if (noa.getOldValue().equals(address.getValue())) {
|
||||
toRemove = address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toRemove != null) {
|
||||
addresses.remove(toRemove);
|
||||
}
|
||||
}
|
||||
String[] args = new String[]{ getAndroidId(), noa.getOldValue() };
|
||||
|
||||
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
public void addOrUpdateNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||
if (isAndroidContact() && noa.getValue() != null) {
|
||||
if (noa.getOldValue() == null) {
|
||||
ContentValues values = new ContentValues();
|
||||
if (noa.isSIPAddress()) {
|
||||
values.put(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
||||
values.put(CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.TYPE_CUSTOM);
|
||||
values.put(CommonDataKinds.SipAddress.LABEL, ContactsManager.getInstance().getString(R.string.addressbook_label));
|
||||
} else {
|
||||
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.LABEL, ContactsManager.getInstance().getString(R.string.addressbook_label));
|
||||
}
|
||||
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
if (noa != null && noa.getValue() != null) {
|
||||
if (isAndroidContact()) {
|
||||
if (noa.getOldValue() == null) {
|
||||
ContentValues values = new ContentValues();
|
||||
if (noa.isSIPAddress()) {
|
||||
values.put(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
||||
values.put(CommonDataKinds.SipAddress.TYPE, CommonDataKinds.SipAddress.TYPE_CUSTOM);
|
||||
values.put(CommonDataKinds.SipAddress.LABEL, ContactsManager.getInstance().getString(R.string.addressbook_label));
|
||||
} else {
|
||||
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_CUSTOM);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.LABEL, ContactsManager.getInstance().getString(R.string.addressbook_label));
|
||||
}
|
||||
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
|
||||
.withValues(values)
|
||||
.build());
|
||||
} else {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValues(values)
|
||||
.build());
|
||||
}
|
||||
} else {
|
||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
||||
.withValues(values)
|
||||
.build());
|
||||
ContentValues values = new ContentValues();
|
||||
String select;
|
||||
String[] args = new String[] { getAndroidId(), noa.getOldValue() };
|
||||
|
||||
if (noa.isSIPAddress()) {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
||||
values.put(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
||||
} else {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
||||
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
||||
}
|
||||
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValues(values)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
String select;
|
||||
String[] args = new String[] { getAndroidId(), noa.getOldValue() };
|
||||
|
||||
if (noa.isSIPAddress()) {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
||||
values.put(ContactsContract.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
||||
}
|
||||
if (isLinphoneFriend()) {
|
||||
if (!noa.getValue().startsWith("sip:")) {
|
||||
noa.setValue("sip:" + noa.getValue());
|
||||
}
|
||||
if (noa.getOldValue() != null) {
|
||||
if (!noa.getOldValue().startsWith("sip:")) {
|
||||
noa.setOldValue("sip:" + noa.getOldValue());
|
||||
}
|
||||
for (LinphoneNumberOrAddress address : addresses) {
|
||||
if (noa.getOldValue().equals(address.getValue())) {
|
||||
address.setValue(noa.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
||||
values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
|
||||
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
||||
}
|
||||
|
||||
String rawContactId = findRawContactID(getAndroidId());
|
||||
if (rawContactId != null) {
|
||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||
.withSelection(select, args)
|
||||
.withValues(values)
|
||||
.build());
|
||||
addresses.add(noa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,9 +309,37 @@ public class LinphoneContact implements Serializable {
|
|||
changesToCommit = new ArrayList<ContentProviderOperation>();
|
||||
}
|
||||
}
|
||||
|
||||
if (isLinphoneFriend()) {
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
if (lc == null) return;
|
||||
|
||||
friend.edit();
|
||||
friend.setName(fullName);
|
||||
//TODO: handle removal of all existing SIP addresses
|
||||
for (LinphoneNumberOrAddress address : addresses) {
|
||||
try {
|
||||
// Currently we only support 1 address / friend
|
||||
LinphoneAddress addr = lc.interpretUrl(address.getValue());
|
||||
if (addr != null) {
|
||||
friend.setAddress(addr);
|
||||
}
|
||||
break;
|
||||
} catch (LinphoneCoreException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
friend.done();
|
||||
|
||||
if (!isAndroidContact() && friend.getAddress() != null) {
|
||||
if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
|
||||
try {
|
||||
lc.addFriend(friend);
|
||||
ContactsManager.getInstance().fetchContacts();
|
||||
} catch (LinphoneCoreException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,7 +350,9 @@ public class LinphoneContact implements Serializable {
|
|||
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.RawContacts.CONTENT_URI).withSelection(select, args).build());
|
||||
save();
|
||||
}
|
||||
deleteFriend();
|
||||
if (isLinphoneFriend()) {
|
||||
deleteFriend();
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteFriend() {
|
||||
|
@ -283,19 +363,18 @@ public class LinphoneContact implements Serializable {
|
|||
|
||||
public void refresh() {
|
||||
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||
if (friend != null) {
|
||||
LinphoneAddress addr = friend.getAddress();
|
||||
if (addr != null) {
|
||||
addresses.add(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||
}
|
||||
}
|
||||
hasSipAddress = false;
|
||||
|
||||
if (!isAndroidContact()) {
|
||||
if (!isAndroidContact() && isLinphoneFriend()) {
|
||||
fullName = friend.getName();
|
||||
thumbnailUri = null;
|
||||
photoUri = null;
|
||||
} else {
|
||||
hasSipAddress = false;
|
||||
LinphoneAddress addr = friend.getAddress();
|
||||
if (addr != null) {
|
||||
addresses.add(new LinphoneNumberOrAddress(addr.asStringUriOnly(), true));
|
||||
hasSipAddress = true;
|
||||
}
|
||||
} else if (isAndroidContact()) {
|
||||
String id = getAndroidId();
|
||||
fullName = getName(id);
|
||||
lastName = getContactLastName(id);
|
||||
|
@ -305,6 +384,26 @@ public class LinphoneContact implements Serializable {
|
|||
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
||||
addNumberOrAddress(noa);
|
||||
}
|
||||
|
||||
if (friend == null) {
|
||||
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
||||
friend.setRefKey(id);
|
||||
friend.setName(fullName);
|
||||
if (hasSipAddress) {
|
||||
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
||||
if (noa.isSIPAddress()) {
|
||||
try {
|
||||
LinphoneAddress addr = LinphoneManager.getLc().interpretUrl(noa.getValue());
|
||||
if (addr != null) {
|
||||
friend.setAddress(addr);
|
||||
}
|
||||
} catch (LinphoneCoreException e) {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,6 +415,10 @@ public class LinphoneContact implements Serializable {
|
|||
return friend != null;
|
||||
}
|
||||
|
||||
public void setFriend(LinphoneFriend f) {
|
||||
friend = f;
|
||||
}
|
||||
|
||||
public static LinphoneContact createContact() {
|
||||
if (ContactsManager.getInstance().hasContactsAccess()) {
|
||||
return createAndroidContact();
|
||||
|
|
|
@ -48,6 +48,10 @@ public class LinphoneNumberOrAddress implements Serializable {
|
|||
public String getOldValue() {
|
||||
return oldValueForUpdatePurpose;
|
||||
}
|
||||
|
||||
public void setOldValue(String v) {
|
||||
oldValueForUpdatePurpose = v;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
|
|
Loading…
Reference in a new issue