Update linphone submodule + Use new createFriend method
This commit is contained in:
parent
d5ee50b1f1
commit
cb10aa43c1
3 changed files with 76 additions and 76 deletions
|
@ -2,7 +2,7 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.linphone"
|
package="org.linphone"
|
||||||
|
|
||||||
android:versionCode="3213" android:versionName="3.2.1" android:installLocation="auto">
|
android:versionCode="3214" android:versionName="3.2.1" android:installLocation="auto">
|
||||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
|
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
|
||||||
|
|
||||||
<!-- Permissions for Push Notification -->
|
<!-- Permissions for Push Notification -->
|
||||||
|
|
|
@ -49,7 +49,7 @@ import android.provider.ContactsContract.CommonDataKinds;
|
||||||
|
|
||||||
public class LinphoneContact implements Serializable, Comparable<LinphoneContact> {
|
public class LinphoneContact implements Serializable, Comparable<LinphoneContact> {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 9015568163905205244L;
|
private static final long serialVersionUID = 9015568163905205244L;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
private transient ArrayList<ContentProviderOperation> changesToCommit2;
|
private transient ArrayList<ContentProviderOperation> changesToCommit2;
|
||||||
private boolean hasSipAddress;
|
private boolean hasSipAddress;
|
||||||
private transient Bitmap photoBitmap, thumbnailBitmap;
|
private transient Bitmap photoBitmap, thumbnailBitmap;
|
||||||
|
|
||||||
public LinphoneContact() {
|
public LinphoneContact() {
|
||||||
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
androidId = null;
|
androidId = null;
|
||||||
|
@ -71,7 +71,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
changesToCommit2 = new ArrayList<ContentProviderOperation>();
|
changesToCommit2 = new ArrayList<ContentProviderOperation>();
|
||||||
hasSipAddress = false;
|
hasSipAddress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
if (photoBitmap != null) {
|
if (photoBitmap != null) {
|
||||||
|
@ -84,7 +84,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
super.finalize();
|
super.finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(LinphoneContact contact) {
|
public int compareTo(LinphoneContact contact) {
|
||||||
String fullName = getFullName() != null ? getFullName() : "";
|
String fullName = getFullName() != null ? getFullName() : "";
|
||||||
|
@ -97,19 +97,19 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
public void setFullName(String name) {
|
public void setFullName(String name) {
|
||||||
fullName = name;
|
fullName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFullName() {
|
public String getFullName() {
|
||||||
return fullName;
|
return fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstNameAndLastName(String fn, String ln) {
|
public void setFirstNameAndLastName(String fn, String ln) {
|
||||||
if (fn != null && fn.length() == 0 && ln != null && ln.length() == 0) return;
|
if (fn != null && fn.length() == 0 && ln != null && ln.length() == 0) return;
|
||||||
|
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
if (firstName != null || lastName != null) {
|
if (firstName != null || lastName != null) {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE + "'";
|
||||||
String[] args = new String[]{ getAndroidId() };
|
String[] args = new String[]{ getAndroidId() };
|
||||||
|
|
||||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
@ -126,7 +126,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
firstName = fn;
|
firstName = fn;
|
||||||
lastName = ln;
|
lastName = ln;
|
||||||
if (firstName != null && lastName != null && firstName.length() > 0 && lastName.length() > 0) {
|
if (firstName != null && lastName != null && firstName.length() > 0 && lastName.length() > 0) {
|
||||||
|
@ -137,25 +137,25 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
fullName = lastName;
|
fullName = lastName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastName() {
|
public String getLastName() {
|
||||||
return lastName;
|
return lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getOrganization() {
|
public String getOrganization() {
|
||||||
return organization;
|
return organization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrganization(String org) {
|
public void setOrganization(String org) {
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
if (androidRawId != null) {
|
if (androidRawId != null) {
|
||||||
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'";
|
String select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE + "'";
|
||||||
String[] args = new String[]{ getAndroidId() };
|
String[] args = new String[]{ getAndroidId() };
|
||||||
|
|
||||||
if (organization != null) {
|
if (organization != null) {
|
||||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
|
@ -177,18 +177,18 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
organization = org;
|
organization = org;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPhoto() {
|
public boolean hasPhoto() {
|
||||||
return photoUri != null;
|
return photoUri != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhotoUri(Uri uri) {
|
public void setPhotoUri(Uri uri) {
|
||||||
if (uri.equals(photoUri)) return;
|
if (uri.equals(photoUri)) return;
|
||||||
photoUri = uri;
|
photoUri = uri;
|
||||||
|
|
||||||
if (photoBitmap != null) {
|
if (photoBitmap != null) {
|
||||||
photoBitmap.recycle();
|
photoBitmap.recycle();
|
||||||
}
|
}
|
||||||
|
@ -200,19 +200,19 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri getPhotoUri() {
|
public Uri getPhotoUri() {
|
||||||
return photoUri;
|
return photoUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getPhotoBitmap() {
|
public Bitmap getPhotoBitmap() {
|
||||||
return photoBitmap;
|
return photoBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThumbnailUri(Uri uri) {
|
public void setThumbnailUri(Uri uri) {
|
||||||
if (uri.equals(thumbnailUri)) return;
|
if (uri.equals(thumbnailUri)) return;
|
||||||
thumbnailUri = uri;
|
thumbnailUri = uri;
|
||||||
|
|
||||||
if (thumbnailBitmap != null) {
|
if (thumbnailBitmap != null) {
|
||||||
thumbnailBitmap.recycle();
|
thumbnailBitmap.recycle();
|
||||||
}
|
}
|
||||||
|
@ -228,11 +228,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
public Uri getThumbnailUri() {
|
public Uri getThumbnailUri() {
|
||||||
return thumbnailUri;
|
return thumbnailUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getThumbnailBitmap() {
|
public Bitmap getThumbnailBitmap() {
|
||||||
return thumbnailBitmap;
|
return thumbnailBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getPhoto() {
|
public Bitmap getPhoto() {
|
||||||
if (photoBitmap != null) {
|
if (photoBitmap != null) {
|
||||||
return photoBitmap;
|
return photoBitmap;
|
||||||
|
@ -241,7 +241,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhoto(byte[] photo) {
|
public void setPhoto(byte[] photo) {
|
||||||
if (photo != null) {
|
if (photo != null) {
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
|
@ -287,11 +287,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAddress() {
|
public boolean hasAddress() {
|
||||||
return hasSipAddress;
|
return hasSipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
public void removeNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||||
if (noa != null && noa.getOldValue() != null) {
|
if (noa != null && noa.getOldValue() != null) {
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
|
@ -302,11 +302,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
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() };
|
String[] args = new String[]{ getAndroidId(), noa.getOldValue() };
|
||||||
|
|
||||||
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
if (androidTagId != null && noa.isSIPAddress()) {
|
if (androidTagId != null && noa.isSIPAddress()) {
|
||||||
select = ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.DATA1 + "=?";
|
select = ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.DATA1 + "=?";
|
||||||
args = new String[] { androidTagId, noa.getOldValue() };
|
args = new String[] { androidTagId, noa.getOldValue() };
|
||||||
|
@ -316,7 +316,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLinphoneFriend()) {
|
if (isLinphoneFriend()) {
|
||||||
if (noa.isSIPAddress()) {
|
if (noa.isSIPAddress()) {
|
||||||
if (!noa.getOldValue().startsWith("sip:")) {
|
if (!noa.getOldValue().startsWith("sip:")) {
|
||||||
|
@ -336,7 +336,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addOrUpdateNumberOrAddress(LinphoneNumberOrAddress noa) {
|
public void addOrUpdateNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||||
if (noa != null && noa.getValue() != null) {
|
if (noa != null && noa.getValue() != null) {
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
|
@ -364,7 +364,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.withValues(values)
|
.withValues(values)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (noa.isSIPAddress() && LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
if (noa.isSIPAddress() && LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||||
if (androidTagId != null) {
|
if (androidTagId != null) {
|
||||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
|
@ -388,13 +388,13 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
String select;
|
String select;
|
||||||
String[] args = new String[] { getAndroidId(), noa.getOldValue() };
|
String[] args = new String[] { getAndroidId(), noa.getOldValue() };
|
||||||
|
|
||||||
if (noa.isSIPAddress()) {
|
if (noa.isSIPAddress()) {
|
||||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS + "=?";
|
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.Data.MIMETYPE, CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE);
|
||||||
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
values.put(ContactsContract.CommonDataKinds.SipAddress.DATA, noa.getValue());
|
||||||
} else {
|
} else {
|
||||||
select = ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.Phone.NUMBER + "=?";
|
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.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
|
||||||
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
values.put(ContactsContract.CommonDataKinds.Phone.NUMBER, noa.getValue());
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.withSelection(select, args)
|
.withSelection(select, args)
|
||||||
.withValues(values)
|
.withValues(values)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
if (noa.isSIPAddress() && LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
if (noa.isSIPAddress() && LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||||
if (androidTagId != null) {
|
if (androidTagId != null) {
|
||||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
|
@ -447,7 +447,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAndroidId(String id) {
|
public void setAndroidId(String id) {
|
||||||
androidId = id;
|
androidId = id;
|
||||||
}
|
}
|
||||||
|
@ -455,10 +455,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
public String getAndroidId() {
|
public String getAndroidId() {
|
||||||
return androidId;
|
return androidId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createOrUpdateFriend() {
|
private void createOrUpdateFriend() {
|
||||||
if (!isLinphoneFriend()) {
|
if (!isLinphoneFriend()) {
|
||||||
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
friend = LinphoneManager.getLc().createFriend();
|
||||||
friend.enableSubscribes(false);
|
friend.enableSubscribes(false);
|
||||||
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
|
@ -469,18 +469,18 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
updateFriend();
|
updateFriend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFriend() {
|
private void updateFriend() {
|
||||||
if (!isLinphoneFriend()) return;
|
if (!isLinphoneFriend()) return;
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
if (lc == null) return;
|
if (lc == null) return;
|
||||||
|
|
||||||
friend.edit();
|
friend.edit();
|
||||||
friend.setFamilyName(lastName);
|
friend.setFamilyName(lastName);
|
||||||
friend.setGivenName(firstName);
|
friend.setGivenName(firstName);
|
||||||
friend.setName(fullName);
|
friend.setName(fullName);
|
||||||
|
|
||||||
for (LinphoneAddress address : friend.getAddresses()) {
|
for (LinphoneAddress address : friend.getAddresses()) {
|
||||||
friend.removeAddress(address);
|
friend.removeAddress(address);
|
||||||
}
|
}
|
||||||
|
@ -505,7 +505,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
friend.done();
|
friend.done();
|
||||||
|
|
||||||
if (!friend.isAlreadyPresentInFriendList()) {
|
if (!friend.isAlreadyPresentInFriendList()) {
|
||||||
try {
|
try {
|
||||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
|
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend);
|
||||||
|
@ -513,16 +513,16 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
Log.e(e);
|
Log.e(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
if (!ContactsManager.getInstance().hasContactsAccess()) {
|
||||||
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
|
// 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
|
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
|
||||||
ContactsManager.getInstance().fetchContactsAsync();
|
ContactsManager.getInstance().fetchContactsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
if (isAndroidContact() && ContactsManager.getInstance().hasContactsAccess() && changesToCommit.size() > 0) {
|
||||||
try {
|
try {
|
||||||
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit);
|
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, changesToCommit);
|
||||||
createLinphoneTagIfNeeded();
|
createLinphoneTagIfNeeded();
|
||||||
|
@ -533,7 +533,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
changesToCommit2 = new ArrayList<ContentProviderOperation>();
|
changesToCommit2 = new ArrayList<ContentProviderOperation>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createOrUpdateFriend();
|
createOrUpdateFriend();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,22 +548,22 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
deleteFriend();
|
deleteFriend();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteFriend() {
|
public void deleteFriend() {
|
||||||
if (friend != null) {
|
if (friend != null) {
|
||||||
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);
|
LinphoneManager.getLcIfManagerNotDestroyedOrNull().removeFriend(friend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void minimalRefresh() {
|
public void minimalRefresh() {
|
||||||
hasSipAddress = false;
|
hasSipAddress = false;
|
||||||
|
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
getContactNames();
|
getContactNames();
|
||||||
setThumbnailUri(getContactThumbnailPictureUri());
|
setThumbnailUri(getContactThumbnailPictureUri());
|
||||||
setPhotoUri(getContactPictureUri());
|
setPhotoUri(getContactPictureUri());
|
||||||
getNativeContactOrganization();
|
getNativeContactOrganization();
|
||||||
|
|
||||||
if (isLinphoneFriend()) {
|
if (isLinphoneFriend()) {
|
||||||
hasSipAddress = friend.getAddress() != null;
|
hasSipAddress = friend.getAddress() != null;
|
||||||
}
|
}
|
||||||
|
@ -581,7 +581,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
hasSipAddress = false;
|
hasSipAddress = false;
|
||||||
|
|
||||||
if (isAndroidContact()) {
|
if (isAndroidContact()) {
|
||||||
getContactNames();
|
getContactNames();
|
||||||
setThumbnailUri(getContactThumbnailPictureUri());
|
setThumbnailUri(getContactThumbnailPictureUri());
|
||||||
|
@ -604,7 +604,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
firstName = friend.getGivenName();
|
firstName = friend.getGivenName();
|
||||||
thumbnailUri = null;
|
thumbnailUri = null;
|
||||||
photoUri = null;
|
photoUri = null;
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
if (lc != null && lc.isVCardSupported()) {
|
if (lc != null && lc.isVCardSupported()) {
|
||||||
for (LinphoneAddress addr : friend.getAddresses()) {
|
for (LinphoneAddress addr : friend.getAddresses()) {
|
||||||
|
@ -623,11 +623,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAndroidContact() {
|
public boolean isAndroidContact() {
|
||||||
return androidId != null;
|
return androidId != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLinphoneFriend() {
|
public boolean isLinphoneFriend() {
|
||||||
return friend != null;
|
return friend != null;
|
||||||
}
|
}
|
||||||
|
@ -670,7 +670,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(getAndroidId()));
|
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(getAndroidId()));
|
||||||
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getContactNames() {
|
private void getContactNames() {
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
String[] proj = new String[]{ ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, ContactsContract.Contacts.DISPLAY_NAME };
|
String[] proj = new String[]{ ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, ContactsContract.Contacts.DISPLAY_NAME };
|
||||||
|
@ -686,7 +686,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getNativeContactOrganization() {
|
private void getNativeContactOrganization() {
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
String[] proj = new String[]{ ContactsContract.CommonDataKinds.Organization.COMPANY };
|
String[] proj = new String[]{ ContactsContract.CommonDataKinds.Organization.COMPANY };
|
||||||
|
@ -700,12 +700,12 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findRawContactID() {
|
private String findRawContactID() {
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
String result = null;
|
String result = null;
|
||||||
String[] projection = { ContactsContract.RawContacts._ID };
|
String[] projection = { ContactsContract.RawContacts._ID };
|
||||||
|
|
||||||
String selection = ContactsContract.RawContacts.CONTACT_ID + "=?";
|
String selection = ContactsContract.RawContacts.CONTACT_ID + "=?";
|
||||||
Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, new String[]{ getAndroidId() }, null);
|
Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, new String[]{ getAndroidId() }, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
@ -716,11 +716,11 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<LinphoneNumberOrAddress> getAddressesAndNumbersForAndroidContact() {
|
private List<LinphoneNumberOrAddress> getAddressesAndNumbersForAndroidContact() {
|
||||||
List<LinphoneNumberOrAddress> result = new ArrayList<LinphoneNumberOrAddress>();
|
List<LinphoneNumberOrAddress> result = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
|
|
||||||
String select = ContactsContract.Data.CONTACT_ID + " =? AND (" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)";
|
String select = ContactsContract.Data.CONTACT_ID + " =? AND (" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)";
|
||||||
String[] projection = new String[] { ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, ContactsContract.Data.MIMETYPE }; // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
String[] projection = new String[] { ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS, ContactsContract.Data.MIMETYPE }; // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
||||||
Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, projection, select, new String[]{ getAndroidId(), ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE }, null);
|
Cursor c = resolver.query(ContactsContract.Data.CONTENT_URI, projection, select, new String[]{ getAndroidId(), ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE }, null);
|
||||||
|
@ -736,7 +736,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
} else if (mime.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
|
} else if (mime.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
String number = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS)); // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
String number = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.SipAddress.SIP_ADDRESS)); // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
||||||
if (number != null && number.length() > 0) {
|
if (number != null && number.length() > 0) {
|
||||||
|
@ -759,32 +759,32 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
|
|
||||||
private static LinphoneContact createAndroidContact() {
|
private static LinphoneContact createAndroidContact() {
|
||||||
LinphoneContact contact = new LinphoneContact();
|
LinphoneContact contact = new LinphoneContact();
|
||||||
|
|
||||||
contact.changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
contact.changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
||||||
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
||||||
.build());
|
.build());
|
||||||
contact.setAndroidId("0");
|
contact.setAndroidId("0");
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LinphoneContact createLinphoneFriend() {
|
private static LinphoneContact createLinphoneFriend() {
|
||||||
LinphoneContact contact = new LinphoneContact();
|
LinphoneContact contact = new LinphoneContact();
|
||||||
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
LinphoneFriend friend = LinphoneManager.getLc().createFriend();
|
||||||
// Disable subscribes for now
|
// Disable subscribes for now
|
||||||
friend.enableSubscribes(false);
|
friend.enableSubscribes(false);
|
||||||
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
friend.setIncSubscribePolicy(SubscribePolicy.SPDeny);
|
||||||
contact.friend = friend;
|
contact.friend = friend;
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String findLinphoneRawContactId() {
|
private String findLinphoneRawContactId() {
|
||||||
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
ContentResolver resolver = ContactsManager.getInstance().getContentResolver();
|
||||||
String result = null;
|
String result = null;
|
||||||
String[] projection = { ContactsContract.RawContacts._ID };
|
String[] projection = { ContactsContract.RawContacts._ID };
|
||||||
|
|
||||||
String selection = ContactsContract.RawContacts.CONTACT_ID + "=? AND " + ContactsContract.RawContacts.ACCOUNT_TYPE + "=?";
|
String selection = ContactsContract.RawContacts.CONTACT_ID + "=? AND " + ContactsContract.RawContacts.ACCOUNT_TYPE + "=?";
|
||||||
Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, new String[] { getAndroidId(), ContactsManager.getInstance().getString(R.string.sync_account_type) }, null);
|
Cursor c = resolver.query(ContactsContract.RawContacts.CONTENT_URI, projection, selection, new String[] { getAndroidId(), ContactsManager.getInstance().getString(R.string.sync_account_type) }, null);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
@ -795,7 +795,7 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLinphoneTagIfNeeded() {
|
private void createLinphoneTagIfNeeded() {
|
||||||
if (LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
if (LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||||
if (androidTagId == null && findLinphoneRawContactId() == null) {
|
if (androidTagId == null && findLinphoneRawContactId() == null) {
|
||||||
|
@ -803,10 +803,10 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLinphoneContactTag() {
|
private void createLinphoneContactTag() {
|
||||||
ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>();
|
ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>();
|
||||||
|
|
||||||
batch.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
batch.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsManager.getInstance().getString(R.string.sync_account_type))
|
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsManager.getInstance().getString(R.string.sync_account_type))
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, ContactsManager.getInstance().getString(R.string.sync_account_name))
|
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, ContactsManager.getInstance().getString(R.string.sync_account_name))
|
||||||
|
@ -824,13 +824,13 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
||||||
.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID1, androidRawId)
|
.withValue(ContactsContract.AggregationExceptions.RAW_CONTACT_ID1, androidRawId)
|
||||||
.withValueBackReference(ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
|
.withValueBackReference(ContactsContract.AggregationExceptions.RAW_CONTACT_ID2, 0)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
if (changesToCommit2.size() > 0) {
|
if (changesToCommit2.size() > 0) {
|
||||||
for(ContentProviderOperation cpo : changesToCommit2) {
|
for(ContentProviderOperation cpo : changesToCommit2) {
|
||||||
batch.add(cpo);
|
batch.add(cpo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, batch);
|
ContactsManager.getInstance().getContentResolver().applyBatch(ContactsContract.AUTHORITY, batch);
|
||||||
androidTagId = findLinphoneRawContactId();
|
androidTagId = findLinphoneRawContactId();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1b8f370bc785ef64eb23e1cb45f509c9b98aab85
|
Subproject commit a87a9ecd454616d04baa9e04e9e1ffa9ff36c375
|
Loading…
Reference in a new issue