Fixed duplicated phone numbers in contact details
This commit is contained in:
parent
1e550b5a74
commit
9b8574caad
3 changed files with 39 additions and 21 deletions
|
@ -377,6 +377,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
"data1", //Company, Phone or SIP Address
|
||||
"data2", //ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME
|
||||
"data3", //ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME
|
||||
"data4", //Normalized phone number
|
||||
};
|
||||
|
||||
private static final String SELECTION = ContactsContract.Data.DISPLAY_NAME_PRIMARY + " IS NOT NULL AND ("
|
||||
|
@ -446,6 +447,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
String data1 = c.getString(c.getColumnIndex("data1"));
|
||||
String data2 = c.getString(c.getColumnIndex("data2"));
|
||||
String data3 = c.getString(c.getColumnIndex("data3"));
|
||||
String data4 = c.getString(c.getColumnIndex("data4"));
|
||||
|
||||
nativeIds.add(id);
|
||||
boolean created = false;
|
||||
|
@ -459,7 +461,7 @@ public class ContactsManager extends ContentObserver implements FriendListListen
|
|||
}
|
||||
|
||||
if (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE.equals(mime)) {
|
||||
contact.addNumberOrAddress(new LinphoneNumberOrAddress(data1, false));
|
||||
contact.addNumberOrAddress(new LinphoneNumberOrAddress(data1, data4));
|
||||
} else if (ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE.equals(mime) || getInstance().getString(R.string.sync_mimetype).equals(mime)) {
|
||||
contact.addNumberOrAddress(new LinphoneNumberOrAddress(data1, true));
|
||||
if (!sipContacts.contains(contact)) {
|
||||
|
|
|
@ -235,8 +235,20 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
if (noa == null) return;
|
||||
if (noa.isSIPAddress()) {
|
||||
hasSipAddress = true;
|
||||
addresses.add(noa);
|
||||
} else {
|
||||
boolean found = false;
|
||||
// Check for duplicated phone numbers but with different formats
|
||||
for (LinphoneNumberOrAddress number : addresses) {
|
||||
if (!number.isSIPAddress() && noa.getNormalizedPhone().equals(number.getNormalizedPhone())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
addresses.add(noa);
|
||||
}
|
||||
}
|
||||
addresses.add(noa);
|
||||
}
|
||||
|
||||
public List<LinphoneNumberOrAddress> getNumbersOrAddresses() {
|
||||
|
@ -680,32 +692,25 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
ContentResolver resolver = LinphoneService.instance().getContentResolver();
|
||||
|
||||
String select = ContactsContract.Data.CONTACT_ID + " =? AND (" + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=? OR " + ContactsContract.Data.MIMETYPE + "=?)";
|
||||
String[] projection = new String[]{"data1", ContactsContract.Data.MIMETYPE}; // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
||||
String[] projection = new String[]{"data1", "data4", 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, ContactsManager.getInstance().getString(R.string.sync_mimetype)}, null);
|
||||
if (c != null) {
|
||||
while (c.moveToNext()) {
|
||||
String mime = c.getString(c.getColumnIndex(ContactsContract.Data.MIMETYPE));
|
||||
if (mime != null && mime.length() > 0) {
|
||||
boolean found = false;
|
||||
boolean isSIP = false;
|
||||
if (mime.equals(ContactsContract.CommonDataKinds.SipAddress.CONTENT_ITEM_TYPE) || mime.equals(ContactsManager.getInstance().getString(R.string.sync_mimetype))) {
|
||||
found = true;
|
||||
isSIP = true;
|
||||
} else if (mime.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
String number = c.getString(c.getColumnIndex("data1")); // PHONE_NUMBER == SIP_ADDRESS == "data1"...
|
||||
if (number != null && number.length() > 0) {
|
||||
if (isSIP && !number.startsWith("sip:")) {
|
||||
number = "sip:" + number;
|
||||
}
|
||||
if (isSIP && !number.contains("@")) {
|
||||
number = number + "@" + ContactsManager.getInstance().getString(R.string.default_domain);
|
||||
}
|
||||
result.add(new LinphoneNumberOrAddress(number, isSIP));
|
||||
String number = c.getString(c.getColumnIndex("data1")); // SIP_ADDRESS
|
||||
if (!number.startsWith("sip:")) {
|
||||
number = "sip:" + number;
|
||||
}
|
||||
if (!number.contains("@")) {
|
||||
number = number + "@" + ContactsManager.getInstance().getString(R.string.default_domain);
|
||||
}
|
||||
result.add(new LinphoneNumberOrAddress(number, true));
|
||||
} else if (mime.equals(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) {
|
||||
String number = c.getString(c.getColumnIndex("data1")); // PHONE_NUMBER
|
||||
String normalized_number = c.getString(c.getColumnIndex("data4")); // NORMALIZED_PHONE_NUMBER
|
||||
result.add(new LinphoneNumberOrAddress(number, normalized_number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,20 @@ public class LinphoneNumberOrAddress implements Serializable, Comparable<Linphon
|
|||
|
||||
private boolean isSIPAddress;
|
||||
private String value, oldValueForUpdatePurpose;
|
||||
private String normalizedPhone;
|
||||
|
||||
public LinphoneNumberOrAddress(String v, boolean isSIP) {
|
||||
value = v;
|
||||
isSIPAddress = isSIP;
|
||||
oldValueForUpdatePurpose = null;
|
||||
normalizedPhone = null;
|
||||
}
|
||||
|
||||
public LinphoneNumberOrAddress(String v, String normalizedV) {
|
||||
value = v;
|
||||
normalizedPhone = normalizedV != null ? normalizedV : v;
|
||||
isSIPAddress = false;
|
||||
oldValueForUpdatePurpose = null;
|
||||
}
|
||||
|
||||
public LinphoneNumberOrAddress(String v, boolean isSip, String old) {
|
||||
|
@ -74,4 +83,6 @@ public class LinphoneNumberOrAddress implements Serializable, Comparable<Linphon
|
|||
public void setValue(String v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
public String getNormalizedPhone() { return normalizedPhone; }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue