Fixed presence issue in contacts list after contact has been added, removed or edited

This commit is contained in:
Sylvain Berfini 2018-09-12 12:37:56 +02:00
parent 339d58e51f
commit 9ff8d854ae
2 changed files with 15 additions and 13 deletions

View file

@ -34,6 +34,7 @@ import android.widget.TextView;
import org.linphone.LinphoneUtils; import org.linphone.LinphoneUtils;
import org.linphone.R; import org.linphone.R;
import org.linphone.activities.LinphoneActivity; import org.linphone.activities.LinphoneActivity;
import org.linphone.mediastream.Log;
import org.linphone.ui.SelectableAdapter; import org.linphone.ui.SelectableAdapter;
import org.linphone.ui.SelectableHelper; import org.linphone.ui.SelectableHelper;

View file

@ -414,8 +414,8 @@ public class ContactsManager extends ContentObserver implements FriendListListen
LinphoneContact contact = (LinphoneContact) friend.getUserData(); LinphoneContact contact = (LinphoneContact) friend.getUserData();
if (contact != null) { if (contact != null) {
contact.clearAddresses(); contact.clearAddresses();
contacts.add(contact);
if (contact.getAndroidId() != null) { if (contact.getAndroidId() != null) {
contacts.add(contact);
mAndroidContactsCache.put(contact.getAndroidId(), contact); mAndroidContactsCache.put(contact.getAndroidId(), contact);
} }
} else { } else {
@ -428,14 +428,14 @@ public class ContactsManager extends ContentObserver implements FriendListListen
contact.setFriend(friend); contact.setFriend(friend);
contact.refresh(); contact.refresh();
contacts.add(contact); contacts.add(contact);
} if (contact.hasAddress()) {
}
if (contact != null && contact.hasAddress()) {
sipContacts.add(contact); sipContacts.add(contact);
} }
} }
} }
} }
}
}
if (c != null) { if (c != null) {
List<String> nativeIds = new ArrayList<>(); List<String> nativeIds = new ArrayList<>();
@ -447,14 +447,13 @@ public class ContactsManager extends ContentObserver implements FriendListListen
String data2 = c.getString(c.getColumnIndex("data2")); String data2 = c.getString(c.getColumnIndex("data2"));
String data3 = c.getString(c.getColumnIndex("data3")); String data3 = c.getString(c.getColumnIndex("data3"));
nativeIds.add(id);
boolean created = false; boolean created = false;
LinphoneContact contact = mAndroidContactsCache.get(id); LinphoneContact contact = mAndroidContactsCache.get(id);
if (contact == null) { if (contact == null) {
created = true; created = true;
contact = new LinphoneContact(); contact = new LinphoneContact();
contact.setAndroidId(id); contact.setAndroidId(id);
nativeIds.add(id);
contact.setFullName(displayName); contact.setFullName(displayName);
mAndroidContactsCache.put(id, contact); mAndroidContactsCache.put(id, contact);
} }
@ -477,16 +476,18 @@ public class ContactsManager extends ContentObserver implements FriendListListen
} }
} }
for (LinphoneContact contact : mAndroidContactsCache.values()) { for (FriendList list : lc.getFriendsLists()) {
for (Friend friend : list.getFriends()) {
LinphoneContact contact = (LinphoneContact) friend.getUserData();
if (contact != null && contact.isAndroidContact()) {
String id = contact.getAndroidId(); String id = contact.getAndroidId();
if (id != null && !nativeIds.contains(id)) { if (id != null && !nativeIds.contains(id)) {
// Has been removed since last fetch // Has been removed since last fetch
for (FriendList list : lc.getFriendsLists()) {
list.removeFriend(contact.getFriend());
}
contacts.remove(contact); contacts.remove(contact);
} }
} }
}
}
nativeIds.clear(); nativeIds.clear();
} }