Removed java cache for contacts, use the one in the library
This commit is contained in:
parent
234983f0af
commit
b4e5b5c0d7
2 changed files with 18 additions and 53 deletions
|
@ -18,7 +18,6 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -42,7 +41,6 @@ import org.linphone.core.LinphoneCore;
|
||||||
import org.linphone.core.LinphoneCoreFactory;
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LinphoneCoreListenerBase;
|
import org.linphone.core.LinphoneCoreListenerBase;
|
||||||
import org.linphone.mediastream.Log;
|
import org.linphone.mediastream.Log;
|
||||||
import org.linphone.ui.AddressText;
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
|
|
@ -31,6 +31,8 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.linphone.core.LinphoneAddress;
|
import org.linphone.core.LinphoneAddress;
|
||||||
import org.linphone.core.LinphoneCore;
|
import org.linphone.core.LinphoneCore;
|
||||||
|
import org.linphone.core.LinphoneCoreException;
|
||||||
|
import org.linphone.core.LinphoneCoreFactory;
|
||||||
import org.linphone.core.LinphoneFriend;
|
import org.linphone.core.LinphoneFriend;
|
||||||
import org.linphone.core.LinphoneFriendImpl;
|
import org.linphone.core.LinphoneFriendImpl;
|
||||||
import org.linphone.core.LinphoneProxyConfig;
|
import org.linphone.core.LinphoneProxyConfig;
|
||||||
|
@ -65,9 +67,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
private Context context;
|
private Context context;
|
||||||
private HashMap<String, LinphoneContact> contactsCache;
|
|
||||||
private HashMap<String, LinphoneContact> androidContactsCache;
|
private HashMap<String, LinphoneContact> androidContactsCache;
|
||||||
private LinphoneContact contactNotFound;
|
|
||||||
private Bitmap defaultAvatar;
|
private Bitmap defaultAvatar;
|
||||||
|
|
||||||
private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners;
|
private static ArrayList<ContactsUpdatedListener> contactsUpdatedListeners;
|
||||||
|
@ -88,8 +88,6 @@ public class ContactsManager extends ContentObserver {
|
||||||
private ContactsManager(Handler handler) {
|
private ContactsManager(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
defaultAvatar = BitmapFactory.decodeResource(LinphoneService.instance().getResources(), R.drawable.avatar);
|
defaultAvatar = BitmapFactory.decodeResource(LinphoneService.instance().getResources(), R.drawable.avatar);
|
||||||
contactNotFound = new LinphoneContact();
|
|
||||||
contactsCache = new HashMap<String, LinphoneContact>();
|
|
||||||
androidContactsCache = new HashMap<String, LinphoneContact>();
|
androidContactsCache = new HashMap<String, LinphoneContact>();
|
||||||
contactsUpdatedListeners = new ArrayList<ContactsUpdatedListener>();
|
contactsUpdatedListeners = new ArrayList<ContactsUpdatedListener>();
|
||||||
contacts = new ArrayList<LinphoneContact>();
|
contacts = new ArrayList<LinphoneContact>();
|
||||||
|
@ -223,64 +221,34 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
public LinphoneContact findContactFromAddress(LinphoneAddress address) {
|
public LinphoneContact findContactFromAddress(LinphoneAddress address) {
|
||||||
String sipUri = address.asStringUriOnly();
|
String sipUri = address.asStringUriOnly();
|
||||||
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;
|
LinphoneFriend lf = lc.findFriendByAddress(sipUri);
|
||||||
if (lc != null) {
|
if (lf != null) {
|
||||||
lpc = lc.getDefaultProxyConfig();
|
LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData();
|
||||||
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LinphoneContact c: getContacts()) {
|
|
||||||
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
|
|
||||||
String normalized = null;
|
|
||||||
if (lpc != null) {
|
|
||||||
normalized = lpc.normalizePhoneNumber(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))) {
|
|
||||||
contactsCache.put(sipUri, 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) {
|
||||||
lpc = lc.getDefaultProxyConfig();
|
lpc = lc.getDefaultProxyConfig();
|
||||||
}
|
}
|
||||||
|
String normalized = lpc.normalizePhoneNumber(phoneNumber);
|
||||||
|
LinphoneAddress addr = null;
|
||||||
|
try {
|
||||||
|
addr = LinphoneCoreFactory.instance().createLinphoneAddress(normalized);
|
||||||
|
} catch (LinphoneCoreException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (LinphoneContact c: getContacts()) {
|
LinphoneFriend lf = lc.findFriendByAddress(addr.asStringUriOnly());
|
||||||
for (LinphoneNumberOrAddress noa: c.getNumbersOrAddresses()) {
|
if (lf != null) {
|
||||||
String normalized = null;
|
LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData();
|
||||||
if (lpc != null) {
|
return contact;
|
||||||
normalized = lpc.normalizePhoneNumber(noa.getValue());
|
|
||||||
}
|
}
|
||||||
if (noa.getValue().equals(phoneNumber) || (normalized != null && normalized.equals(phoneNumber))) {
|
|
||||||
contactsCache.put(phoneNumber, c);
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contactsCache.put(phoneNumber, contactNotFound);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +418,6 @@ public class ContactsManager extends ContentObserver {
|
||||||
Collections.sort(sipContacts);
|
Collections.sort(sipContacts);
|
||||||
setContacts(contacts);
|
setContacts(contacts);
|
||||||
setSipContacts(sipContacts);
|
setSipContacts(sipContacts);
|
||||||
contactsCache.clear();
|
|
||||||
|
|
||||||
LinphoneManager.getLc().getFriendLists()[0].updateSubscriptions();
|
LinphoneManager.getLc().getFriendLists()[0].updateSubscriptions();
|
||||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||||
|
|
Loading…
Reference in a new issue