Added contacts cache to improve scrolling smoothness on history and chat list
This commit is contained in:
parent
47a488738a
commit
c58b999552
1 changed files with 22 additions and 0 deletions
|
@ -21,6 +21,7 @@ package org.linphone;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -59,6 +60,8 @@ public class ContactsManager extends ContentObserver {
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
private Context context;
|
private Context context;
|
||||||
private ContactsFetchTask contactsFetchTask;
|
private ContactsFetchTask contactsFetchTask;
|
||||||
|
private HashMap<String, LinphoneContact> contactsCache;
|
||||||
|
private LinphoneContact contactNotFound;
|
||||||
|
|
||||||
private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners;
|
private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners;
|
||||||
public static void addContactsListener(ContactsUpdatedListener listener) {
|
public static void addContactsListener(ContactsUpdatedListener listener) {
|
||||||
|
@ -77,6 +80,8 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
private ContactsManager(Handler handler) {
|
private ContactsManager(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
|
contactNotFound = new LinphoneContact();
|
||||||
|
contactsCache = new HashMap<String, LinphoneContact>();
|
||||||
contactsUpdatedListeners = new ArrayList<ContactsUpdatedListener>();
|
contactsUpdatedListeners = new ArrayList<ContactsUpdatedListener>();
|
||||||
contacts = new ArrayList<LinphoneContact>();
|
contacts = new ArrayList<LinphoneContact>();
|
||||||
sipContacts = new ArrayList<LinphoneContact>();
|
sipContacts = new ArrayList<LinphoneContact>();
|
||||||
|
@ -204,6 +209,12 @@ public class ContactsManager extends ContentObserver {
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
String username = address.getUserName();
|
String username = address.getUserName();
|
||||||
|
|
||||||
|
LinphoneContact cache = contactsCache.get(sipUri);
|
||||||
|
if (cache != null) {
|
||||||
|
if (cache == contactNotFound) return null;
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
LinphoneProxyConfig lpc = null;
|
LinphoneProxyConfig lpc = null;
|
||||||
if (lc != null) {
|
if (lc != null) {
|
||||||
|
@ -219,14 +230,22 @@ public class ContactsManager extends ContentObserver {
|
||||||
String alias = c.getPresenceModelForUri(noa.getValue());
|
String alias = c.getPresenceModelForUri(noa.getValue());
|
||||||
|
|
||||||
if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (alias != null && alias.equals(sipUri)) || (normalized != null && !noa.isSIPAddress() && normalized.equals(username)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
|
if ((noa.isSIPAddress() && noa.getValue().equals(sipUri)) || (alias != null && alias.equals(sipUri)) || (normalized != null && !noa.isSIPAddress() && normalized.equals(username)) || (!noa.isSIPAddress() && noa.getValue().equals(username))) {
|
||||||
|
contactsCache.put(sipUri, c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
contactsCache.put(sipUri, contactNotFound);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinphoneContact findContactFromPhoneNumber(String phoneNumber) {
|
public LinphoneContact findContactFromPhoneNumber(String phoneNumber) {
|
||||||
|
LinphoneContact cache = contactsCache.get(phoneNumber);
|
||||||
|
if (cache != null) {
|
||||||
|
if (cache == contactNotFound) return null;
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
LinphoneProxyConfig lpc = null;
|
LinphoneProxyConfig lpc = null;
|
||||||
if (lc != null) {
|
if (lc != null) {
|
||||||
|
@ -240,10 +259,12 @@ public class ContactsManager extends ContentObserver {
|
||||||
normalized = lpc.normalizePhoneNumber(noa.getValue());
|
normalized = lpc.normalizePhoneNumber(noa.getValue());
|
||||||
}
|
}
|
||||||
if (noa.getValue().equals(phoneNumber) || (normalized != null && normalized.equals(phoneNumber))) {
|
if (noa.getValue().equals(phoneNumber) || (normalized != null && normalized.equals(phoneNumber))) {
|
||||||
|
contactsCache.put(phoneNumber, c);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
contactsCache.put(phoneNumber, contactNotFound);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,6 +366,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
protected void onPostExecute(List<LinphoneContact> result) {
|
protected void onPostExecute(List<LinphoneContact> result) {
|
||||||
setContacts(result);
|
setContacts(result);
|
||||||
|
contactsCache.clear();
|
||||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||||
listener.onContactsUpdated();
|
listener.onContactsUpdated();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue