Implemented quick addressbook display feature
This commit is contained in:
parent
b8109c898d
commit
9e4d31d370
2 changed files with 97 additions and 68 deletions
|
@ -19,7 +19,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
package org.linphone;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
@ -50,8 +52,6 @@ interface ContactsUpdatedListener {
|
|||
}
|
||||
|
||||
public class ContactsManager extends ContentObserver {
|
||||
private static final int CONTACTS_UPDATED = 543;
|
||||
|
||||
private static ContactsManager instance;
|
||||
private List<LinphoneContact> contacts, sipContacts;
|
||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true, hasContactAccess = false;
|
||||
|
@ -67,16 +67,9 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
|
||||
private static Handler handler = new Handler() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage (Message msg) {
|
||||
if (msg.what == CONTACTS_UPDATED && msg.obj instanceof List<?>) {
|
||||
List<LinphoneContact> c = (List<LinphoneContact>) msg.obj;
|
||||
ContactsManager.getInstance().setContacts(c);
|
||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||
listener.onContactsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -225,7 +218,10 @@ public class ContactsManager extends ContentObserver {
|
|||
new ContactsFetchTask().execute();
|
||||
}
|
||||
|
||||
public List<LinphoneContact> fetchContactsSync() {
|
||||
|
||||
private class ContactsFetchTask extends AsyncTask<Void, List<LinphoneContact>, List<LinphoneContact>> {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected List<LinphoneContact> doInBackground(Void... params) {
|
||||
List<LinphoneContact> contacts = new ArrayList<LinphoneContact>();
|
||||
|
||||
if (hasContactsAccess()) {
|
||||
|
@ -273,16 +269,27 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
|
||||
for (LinphoneContact contact : contacts) {
|
||||
contact.refresh();
|
||||
// This will only get name & picture informations to be able to quickly display contacts list
|
||||
contact.minimalRefresh();
|
||||
}
|
||||
Collections.sort(contacts);
|
||||
|
||||
// Public the current list of contacts without all the informations populated
|
||||
publishProgress(contacts);
|
||||
|
||||
for (LinphoneContact contact : contacts) {
|
||||
// This time fetch all informations including phone numbers and SIP addresses
|
||||
contact.refresh();
|
||||
}
|
||||
|
||||
return contacts;
|
||||
}
|
||||
|
||||
private class ContactsFetchTask extends AsyncTask<Void, Void, List<LinphoneContact>> {
|
||||
protected List<LinphoneContact> doInBackground(Void... params) {
|
||||
return fetchContactsSync();
|
||||
protected void onProgressUpdate(List<LinphoneContact>... result) {
|
||||
setContacts(result[0]);
|
||||
for (ContactsUpdatedListener listener : contactsUpdatedListeners) {
|
||||
listener.onContactsUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(List<LinphoneContact> result) {
|
||||
|
|
|
@ -448,14 +448,36 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
}
|
||||
}
|
||||
|
||||
public void minimalRefresh() {
|
||||
hasSipAddress = false;
|
||||
|
||||
if (isAndroidContact()) {
|
||||
getContactNames();
|
||||
setThumbnailUri(getContactThumbnailPictureUri());
|
||||
setPhotoUri(getContactPictureUri());
|
||||
|
||||
if (isLinphoneFriend()) {
|
||||
hasSipAddress = friend.getAddress() != null;
|
||||
}
|
||||
} else if (isLinphoneFriend()) {
|
||||
fullName = friend.getName();
|
||||
lastName = friend.getFamillyName();
|
||||
firstName = friend.getGivenName();
|
||||
thumbnailUri = null;
|
||||
photoUri = null;
|
||||
hasSipAddress = friend.getAddress() != null;
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
addresses = new ArrayList<LinphoneNumberOrAddress>();
|
||||
hasSipAddress = false;
|
||||
|
||||
if (isAndroidContact()) {
|
||||
getContactNames();
|
||||
setThumbnailUri(getContactPictureUri());
|
||||
setPhotoUri(getContactPhotoUri());
|
||||
setThumbnailUri(getContactThumbnailPictureUri());
|
||||
setPhotoUri(getContactPictureUri());
|
||||
|
||||
androidRawId = findRawContactID();
|
||||
|
||||
if (LinphoneManager.getInstance().getContext().getResources().getBoolean(R.bool.use_linphone_tag)) {
|
||||
|
@ -513,12 +535,12 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
|
|||
return firstLetter.compareTo(contactfirstLetter);
|
||||
}
|
||||
|
||||
private Uri getContactPictureUri() {
|
||||
private Uri getContactThumbnailPictureUri() {
|
||||
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(getAndroidId()));
|
||||
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
|
||||
}
|
||||
|
||||
private Uri getContactPhotoUri() {
|
||||
private Uri getContactPictureUri() {
|
||||
Uri person = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(getAndroidId()));
|
||||
return Uri.withAppendedPath(person, ContactsContract.Contacts.Photo.DISPLAY_PHOTO);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue