Added back sip contacts filter
This commit is contained in:
parent
4956bed080
commit
6b5b2b9075
3 changed files with 56 additions and 48 deletions
|
@ -132,7 +132,7 @@ public class ContactEditorFragment extends Fragment {
|
||||||
getFragmentManager().popBackStackImmediate();
|
getFragmentManager().popBackStackImmediate();
|
||||||
return;
|
return;
|
||||||
}*/
|
}*/
|
||||||
contact = LinphoneContact.createAndroidContact();
|
contact = LinphoneContact.createContact();
|
||||||
}
|
}
|
||||||
contact.setFirstNameAndLastName(firstName.getText().toString(), lastName.getText().toString());
|
contact.setFirstNameAndLastName(firstName.getText().toString(), lastName.getText().toString());
|
||||||
if (photoToAdd != null) {
|
if (photoToAdd != null) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
private static final int CONTACTS_UPDATED = 543;
|
private static final int CONTACTS_UPDATED = 543;
|
||||||
|
|
||||||
private static ContactsManager instance;
|
private static ContactsManager instance;
|
||||||
private List<LinphoneContact> contacts;
|
private List<LinphoneContact> contacts, sipContacts;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
|
@ -112,7 +112,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<LinphoneContact> getSIPContacts() {
|
public synchronized List<LinphoneContact> getSIPContacts() {
|
||||||
return contacts;
|
return sipContacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableContactsAccess() {
|
public void enableContactsAccess() {
|
||||||
|
@ -176,6 +176,12 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
public synchronized void setContacts(List<LinphoneContact> c) {
|
public synchronized void setContacts(List<LinphoneContact> c) {
|
||||||
contacts = c;
|
contacts = c;
|
||||||
|
sipContacts = new ArrayList<LinphoneContact>();
|
||||||
|
for (LinphoneContact contact : contacts) {
|
||||||
|
if (contact.hasAddress()) {
|
||||||
|
sipContacts.add(contact);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void fetchContacts() {
|
public synchronized void fetchContacts() {
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class LinphoneContact implements Serializable {
|
||||||
private transient Uri photoUri, thumbnailUri;
|
private transient Uri photoUri, thumbnailUri;
|
||||||
private List<LinphoneNumberOrAddress> addresses;
|
private List<LinphoneNumberOrAddress> addresses;
|
||||||
private transient ArrayList<ContentProviderOperation> changesToCommit;
|
private transient ArrayList<ContentProviderOperation> changesToCommit;
|
||||||
|
private boolean hasSipAddress;
|
||||||
|
|
||||||
public LinphoneContact() {
|
public LinphoneContact() {
|
||||||
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||||
|
@ -52,6 +53,7 @@ public class LinphoneContact implements Serializable {
|
||||||
thumbnailUri = null;
|
thumbnailUri = null;
|
||||||
photoUri = null;
|
photoUri = null;
|
||||||
changesToCommit = new ArrayList<ContentProviderOperation>();
|
changesToCommit = new ArrayList<ContentProviderOperation>();
|
||||||
|
hasSipAddress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFullName(String name) {
|
public void setFullName(String name) {
|
||||||
|
@ -86,6 +88,7 @@ public class LinphoneContact implements Serializable {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
firstName = fn;
|
firstName = fn;
|
||||||
lastName = ln;
|
lastName = ln;
|
||||||
fullName = firstName + " " + lastName;
|
fullName = firstName + " " + lastName;
|
||||||
|
@ -121,11 +124,18 @@ public class LinphoneContact implements Serializable {
|
||||||
|
|
||||||
public void setPhoto(byte[] photo) {
|
public void setPhoto(byte[] photo) {
|
||||||
if (isAndroidContact() && photo != null) {
|
if (isAndroidContact() && photo != null) {
|
||||||
if (!hasPhoto()) {
|
String id = findDataId(getAndroidId());
|
||||||
|
if (id != null) {
|
||||||
|
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
||||||
|
.withSelection(ContactsContract.Data._ID + "= ?", new String[] { id })
|
||||||
|
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||||
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||||
|
.build());
|
||||||
|
} else {
|
||||||
String rawContactId = findRawContactID(getAndroidId());
|
String rawContactId = findRawContactID(getAndroidId());
|
||||||
if (rawContactId != null) {
|
if (rawContactId != null) {
|
||||||
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
||||||
.withSelection(ContactsContract.Data.RAW_CONTACT_ID + "= ?", new String[] { rawContactId })
|
.withValue(ContactsContract.Data.RAW_CONTACT_ID, new String[] { rawContactId })
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
||||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||||
.build());
|
.build());
|
||||||
|
@ -136,21 +146,15 @@ public class LinphoneContact implements Serializable {
|
||||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
String id = findDataId(getAndroidId());
|
|
||||||
if (id != null) {
|
|
||||||
changesToCommit.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
|
|
||||||
.withSelection(ContactsContract.Data._ID + "= ?", new String[] { id })
|
|
||||||
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
|
|
||||||
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, photo)
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNumberOrAddress(LinphoneNumberOrAddress noa) {
|
public void addNumberOrAddress(LinphoneNumberOrAddress noa) {
|
||||||
if (noa == null) return;
|
if (noa == null) return;
|
||||||
|
if (noa.isSIPAddress()) {
|
||||||
|
hasSipAddress = true;
|
||||||
|
}
|
||||||
addresses.add(noa);
|
addresses.add(noa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,12 +175,7 @@ public class LinphoneContact implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasAddress() {
|
public boolean hasAddress() {
|
||||||
for (LinphoneNumberOrAddress noa : getNumbersOrAddresses()) {
|
return hasSipAddress;
|
||||||
if (noa.isSIPAddress()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAndroidId(String id) {
|
public void setAndroidId(String id) {
|
||||||
|
@ -196,10 +195,9 @@ public class LinphoneContact implements Serializable {
|
||||||
} finally {
|
} finally {
|
||||||
changesToCommit = new ArrayList<ContentProviderOperation>();
|
changesToCommit = new ArrayList<ContentProviderOperation>();
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
if (friend == null) {
|
|
||||||
friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
if (isLinphoneFriend()) {
|
||||||
}
|
|
||||||
friend.setName(fullName);
|
friend.setName(fullName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,6 +232,7 @@ public class LinphoneContact implements Serializable {
|
||||||
thumbnailUri = null;
|
thumbnailUri = null;
|
||||||
photoUri = null;
|
photoUri = null;
|
||||||
} else {
|
} else {
|
||||||
|
hasSipAddress = false;
|
||||||
String id = getAndroidId();
|
String id = getAndroidId();
|
||||||
fullName = getName(id);
|
fullName = getName(id);
|
||||||
lastName = getContactLastName(id);
|
lastName = getContactLastName(id);
|
||||||
|
@ -241,7 +240,7 @@ public class LinphoneContact implements Serializable {
|
||||||
setThumbnailUri(getContactPictureUri(id));
|
setThumbnailUri(getContactPictureUri(id));
|
||||||
setPhotoUri(getContactPhotoUri(id));
|
setPhotoUri(getContactPhotoUri(id));
|
||||||
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
for (LinphoneNumberOrAddress noa : getAddressesAndNumbersForAndroidContact(id)) {
|
||||||
addresses.add(noa);
|
addNumberOrAddress(noa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -249,31 +248,16 @@ public class LinphoneContact implements Serializable {
|
||||||
public boolean isAndroidContact() {
|
public boolean isAndroidContact() {
|
||||||
return androidId != null;
|
return androidId != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinphoneContact createLinphoneFriend(String name, String address) {
|
public boolean isLinphoneFriend() {
|
||||||
LinphoneContact contact = new LinphoneContact();
|
return friend != null;
|
||||||
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
|
||||||
contact.friend = friend;
|
|
||||||
|
|
||||||
if (name != null) {
|
|
||||||
contact.setFullName(name);
|
|
||||||
}
|
|
||||||
if (address != null) {
|
|
||||||
contact.addNumberOrAddress(new LinphoneNumberOrAddress(address, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return contact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LinphoneContact createAndroidContact() {
|
public static LinphoneContact createContact() {
|
||||||
LinphoneContact contact = new LinphoneContact();
|
if (ContactsManager.getInstance().hasContactsAccess()) {
|
||||||
contact.changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
return createAndroidContact();
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
}
|
||||||
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
return createLinphoneFriend();
|
||||||
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
|
||||||
.build());
|
|
||||||
contact.setAndroidId("0");
|
|
||||||
return contact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uri getContactUri(String id) {
|
private Uri getContactUri(String id) {
|
||||||
|
@ -391,4 +375,22 @@ public class LinphoneContact implements Serializable {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LinphoneContact createAndroidContact() {
|
||||||
|
LinphoneContact contact = new LinphoneContact();
|
||||||
|
contact.changesToCommit.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
||||||
|
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
||||||
|
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
||||||
|
.withValue(ContactsContract.RawContacts.AGGREGATION_MODE, ContactsContract.RawContacts.AGGREGATION_MODE_DEFAULT)
|
||||||
|
.build());
|
||||||
|
contact.setAndroidId("0");
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LinphoneContact createLinphoneFriend() {
|
||||||
|
LinphoneContact contact = new LinphoneContact();
|
||||||
|
LinphoneFriend friend = LinphoneCoreFactory.instance().createLinphoneFriend();
|
||||||
|
contact.friend = friend;
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue