Prevent duplicated contacts with different ids to show in contacts list

This commit is contained in:
Sylvain Berfini 2018-10-03 14:21:31 +02:00
parent fba1be573e
commit 08f1b48aac
3 changed files with 19 additions and 7 deletions

View file

@ -445,7 +445,7 @@ public final class LinphoneService extends Service {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
mLastNotificationId = 8; // To not interfere with other notifs ids mLastNotificationId = 8; // To not interfere with other notifs ids
mChatNotifMap = new HashMap<String, Notified>(); mChatNotifMap = new HashMap<>();
setupActivityMonitor(); setupActivityMonitor();
// In case restart after a crash. Main in LinphoneActivity // In case restart after a crash. Main in LinphoneActivity

View file

@ -75,7 +75,17 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
if (fullName.equals(contactFullName)) { if (fullName.equals(contactFullName)) {
if (getAndroidId() != null) { if (getAndroidId() != null) {
if (contact.getAndroidId() != null) { if (contact.getAndroidId() != null) {
return getAndroidId().compareTo(contact.getAndroidId()); int idComp = getAndroidId().compareTo(contact.getAndroidId());
if (idComp == 0) return 0;
List<LinphoneNumberOrAddress> noas1 = getNumbersOrAddresses();
List<LinphoneNumberOrAddress> noas2 = contact.getNumbersOrAddresses();
if (noas1.size() == noas2.size()) {
if (noas1.containsAll(noas2) && noas2.containsAll(noas1)) {
return 0;
}
return -1;
}
return ((Integer)noas1.size()).compareTo(noas2.size());
} }
return -1; return -1;
} }

View file

@ -49,13 +49,15 @@ public class LinphoneNumberOrAddress implements Serializable, Comparable<Linphon
@Override @Override
public int compareTo(LinphoneNumberOrAddress noa) { public int compareTo(LinphoneNumberOrAddress noa) {
String value = noa.getValue(); if (value != null) {
if (noa.isSIPAddress() == isSIPAddress() && value != null) { if (noa.isSIPAddress() && isSIPAddress()) {
return value.compareTo(getValue()); return value.compareTo(noa.getValue());
} else { } else if (!noa.isSIPAddress() && !isSIPAddress()) {
return isSIPAddress() ? -1 : 1; return getNormalizedPhone().compareTo(noa.getNormalizedPhone());
} }
} }
return -1;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {