Fix possibly a duplicate of contacts
This commit is contained in:
parent
0d16e8d7b7
commit
88fe4dd3f8
1 changed files with 15 additions and 15 deletions
|
@ -59,7 +59,7 @@ interface ContactsUpdatedListener {
|
||||||
|
|
||||||
public class ContactsManager extends ContentObserver {
|
public class ContactsManager extends ContentObserver {
|
||||||
private static ContactsManager instance;
|
private static ContactsManager instance;
|
||||||
|
|
||||||
private List<LinphoneContact> contacts, sipContacts;
|
private List<LinphoneContact> contacts, sipContacts;
|
||||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
|
@ -245,7 +245,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
public synchronized void setSipContacts(List<LinphoneContact> c) {
|
public synchronized void setSipContacts(List<LinphoneContact> c) {
|
||||||
sipContacts = c;
|
sipContacts = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void refreshSipContact(LinphoneFriend lf) {
|
public synchronized void refreshSipContact(LinphoneFriend lf) {
|
||||||
LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData();
|
LinphoneContact contact = (LinphoneContact)((LinphoneFriendImpl)lf).getUserData();
|
||||||
if (contact != null && !sipContacts.contains(contact)) {
|
if (contact != null && !sipContacts.contains(contact)) {
|
||||||
|
@ -256,7 +256,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fetchContactsAsync() {
|
public void fetchContactsAsync() {
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -270,7 +270,8 @@ public class ContactsManager extends ContentObserver {
|
||||||
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
|
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
|
||||||
List<LinphoneContact> sipContacts = new ArrayList<LinphoneContact>();
|
List<LinphoneContact> sipContacts = new ArrayList<LinphoneContact>();
|
||||||
Date contactsTime = new Date();
|
Date contactsTime = new Date();
|
||||||
|
androidContactsCache.clear();
|
||||||
|
|
||||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||||
if (lc != null) {
|
if (lc != null) {
|
||||||
for (LinphoneFriend friend : lc.getFriendList()) {
|
for (LinphoneFriend friend : lc.getFriendList()) {
|
||||||
|
@ -297,7 +298,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
long timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
||||||
String time = String.format("%02d:%02d",
|
String time = String.format("%02d:%02d",
|
||||||
TimeUnit.MILLISECONDS.toMinutes(timeElapsed),
|
TimeUnit.MILLISECONDS.toMinutes(timeElapsed),
|
||||||
|
@ -306,14 +307,13 @@ public class ContactsManager extends ContentObserver {
|
||||||
Log.i("[ContactsManager] Step 0 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
Log.i("[ContactsManager] Step 0 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
||||||
|
|
||||||
if (hasContactsAccess()) {
|
if (hasContactsAccess()) {
|
||||||
androidContactsCache.clear();
|
|
||||||
List<String> nativeIds = new ArrayList<String>();
|
List<String> nativeIds = new ArrayList<String>();
|
||||||
Cursor c = getContactsCursor(contentResolver);
|
Cursor c = getContactsCursor(contentResolver);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
|
String id = c.getString(c.getColumnIndex(Data.CONTACT_ID));
|
||||||
String displayName = c.getString(c.getColumnIndex(Data.DISPLAY_NAME_PRIMARY));
|
String displayName = c.getString(c.getColumnIndex(Data.DISPLAY_NAME_PRIMARY));
|
||||||
|
|
||||||
nativeIds.add(id);
|
nativeIds.add(id);
|
||||||
boolean created = false;
|
boolean created = false;
|
||||||
LinphoneContact contact = androidContactsCache.get(id);
|
LinphoneContact contact = androidContactsCache.get(id);
|
||||||
|
@ -348,7 +348,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
c.close();
|
c.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (LinphoneContact contact : androidContactsCache.values()) {
|
for (LinphoneContact contact : androidContactsCache.values()) {
|
||||||
String id = contact.getAndroidId();
|
String id = contact.getAndroidId();
|
||||||
if (id != null && !nativeIds.contains(id)) {
|
if (id != null && !nativeIds.contains(id)) {
|
||||||
|
@ -358,14 +358,14 @@ public class ContactsManager extends ContentObserver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nativeIds.clear();
|
nativeIds.clear();
|
||||||
|
|
||||||
timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
timeElapsed = (new Date()).getTime() - contactsTime.getTime();
|
||||||
time = String.format("%02d:%02d",
|
time = String.format("%02d:%02d",
|
||||||
TimeUnit.MILLISECONDS.toMinutes(timeElapsed),
|
TimeUnit.MILLISECONDS.toMinutes(timeElapsed),
|
||||||
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
||||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
||||||
Log.i("[ContactsManager] Step 1 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
Log.i("[ContactsManager] Step 1 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
||||||
|
|
||||||
c = getPhonesCursor(contentResolver);
|
c = getPhonesCursor(contentResolver);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
while (c.moveToNext()) {
|
while (c.moveToNext()) {
|
||||||
|
@ -400,7 +400,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
||||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
||||||
Log.i("[ContactsManager] Step 2 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
Log.i("[ContactsManager] Step 2 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
||||||
|
|
||||||
for (LinphoneContact contact : contacts) {
|
for (LinphoneContact contact : contacts) {
|
||||||
// Create the LinphoneFriends matching the native contacts
|
// Create the LinphoneFriends matching the native contacts
|
||||||
contact.createOrUpdateLinphoneFriendFromNativeContact();
|
contact.createOrUpdateLinphoneFriendFromNativeContact();
|
||||||
|
@ -411,17 +411,17 @@ public class ContactsManager extends ContentObserver {
|
||||||
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
TimeUnit.MILLISECONDS.toSeconds(timeElapsed) -
|
||||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeElapsed)));
|
||||||
Log.i("[ContactsManager] Step 3 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
Log.i("[ContactsManager] Step 3 for " + contacts.size() + " contacts: " + time + " elapsed since starting");
|
||||||
|
|
||||||
androidContactsCache.clear();
|
androidContactsCache.clear();
|
||||||
} else {
|
} else {
|
||||||
Log.w("[Permission] Read contacts permission wasn't granted, only fetch LinphoneFriends");
|
Log.w("[Permission] Read contacts permission wasn't granted, only fetch LinphoneFriends");
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(contacts);
|
Collections.sort(contacts);
|
||||||
Collections.sort(sipContacts);
|
Collections.sort(sipContacts);
|
||||||
setContacts(contacts);
|
setContacts(contacts);
|
||||||
setSipContacts(sipContacts);
|
setSipContacts(sipContacts);
|
||||||
|
|
||||||
LinphoneManager.getLc().getFriendLists()[0].updateSubscriptions();
|
LinphoneManager.getLc().getFriendLists()[0].updateSubscriptions();
|
||||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||||
listener.onContactsUpdated();
|
listener.onContactsUpdated();
|
||||||
|
@ -518,7 +518,7 @@ public class ContactsManager extends ContentObserver {
|
||||||
|
|
||||||
private Cursor getPhonesCursor(ContentResolver cr) {
|
private Cursor getPhonesCursor(ContentResolver cr) {
|
||||||
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||||
new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.CONTACT_ID },
|
new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.CONTACT_ID },
|
||||||
null, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " ASC");
|
null, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " ASC");
|
||||||
return cursor;
|
return cursor;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue