Started MagicSearchBar
This commit is contained in:
parent
fc41d8e58a
commit
c0856ecd4c
4 changed files with 52 additions and 22 deletions
|
@ -127,7 +127,9 @@ public class ChatCreationFragment extends Fragment implements View.OnClickListen
|
|||
mSearchField.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
if (before > count) {
|
||||
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,11 +23,13 @@ import android.view.View;
|
|||
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Factory;
|
||||
import org.linphone.core.SearchResult;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class ContactAddress implements Serializable {
|
||||
private LinphoneContact contact;
|
||||
private SearchResult result;
|
||||
private String address;
|
||||
private boolean isLinphoneContact;
|
||||
private boolean isSelect = false;
|
||||
|
@ -58,6 +60,14 @@ public class ContactAddress implements Serializable {
|
|||
return contact;
|
||||
}
|
||||
|
||||
public SearchResult getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(SearchResult result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public String getAddressAsDisplayableString() {
|
||||
return address;
|
||||
}
|
||||
|
|
|
@ -42,8 +42,10 @@ import org.linphone.LinphoneService;
|
|||
import org.linphone.R;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Core;
|
||||
import org.linphone.core.Factory;
|
||||
import org.linphone.core.Friend;
|
||||
import org.linphone.core.FriendList;
|
||||
import org.linphone.core.MagicSearch;
|
||||
import org.linphone.core.ProxyConfig;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
|
@ -61,6 +63,7 @@ public class ContactsManager extends ContentObserver {
|
|||
private static ContactsManager instance;
|
||||
|
||||
private List<LinphoneContact> contacts, sipContacts;
|
||||
private MagicSearch magicSearch;
|
||||
private boolean preferLinphoneContacts = false, isContactPresenceDisabled = true;
|
||||
private ContentResolver contentResolver;
|
||||
private Context context;
|
||||
|
@ -84,6 +87,9 @@ public class ContactsManager extends ContentObserver {
|
|||
contactsUpdatedListeners = new ArrayList<ContactsUpdatedListener>();
|
||||
contacts = new ArrayList<LinphoneContact>();
|
||||
sipContacts = new ArrayList<LinphoneContact>();
|
||||
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) {
|
||||
magicSearch = LinphoneManager.getLcIfManagerNotDestroyedOrNull().createMagicSearch();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
|
@ -91,6 +97,10 @@ public class ContactsManager extends ContentObserver {
|
|||
instance = null;
|
||||
}
|
||||
|
||||
public MagicSearch getMagicSearch() {
|
||||
return magicSearch;
|
||||
}
|
||||
|
||||
public boolean contactsFetchedOnce() {
|
||||
return contacts.size() > 0;
|
||||
}
|
||||
|
@ -220,6 +230,7 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
|
||||
public synchronized LinphoneContact findContactFromAddress(Address address) {
|
||||
if (address == null) return null;
|
||||
Core lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
Friend lf = lc.findFriend(address);
|
||||
if (lf != null) {
|
||||
|
@ -301,6 +312,9 @@ public class ContactsManager extends ContentObserver {
|
|||
LinphoneContact contact = (LinphoneContact) friend.getUserData();
|
||||
if (contact != null) {
|
||||
contact.clearAddresses();
|
||||
if (contact.hasAddress()) {
|
||||
sipContacts.add(contact);
|
||||
}
|
||||
contacts.add(contact);
|
||||
if (contact.getAndroidId() != null) {
|
||||
androidContactsCache.put(contact.getAndroidId(), contact);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.linphone.LinphoneUtils;
|
|||
import org.linphone.R;
|
||||
import org.linphone.activities.LinphoneActivity;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.SearchResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -156,6 +157,9 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
if (search == null || search.length() == 0 || search.trim().length() == 0) {
|
||||
contacts = getContactsList();
|
||||
resultContactsSearch.setAdapter(this);
|
||||
if (ContactsManager.getInstance() != null) {
|
||||
ContactsManager.getInstance().getMagicSearch().resetSearchCache();
|
||||
}
|
||||
oldSize = 0;
|
||||
return;
|
||||
}
|
||||
|
@ -163,29 +167,29 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
search = search.trim();
|
||||
List<ContactAddress> result = new ArrayList<>();
|
||||
|
||||
String searchAddress = "sip:" + search + "@" + LinphoneManager.getLc().getDefaultProxyConfig().getDomain();
|
||||
if (search.contains("@") || search.startsWith("sip:")) {
|
||||
searchAddress = search;
|
||||
}
|
||||
|
||||
boolean searchFound = false;
|
||||
if (search != null) {
|
||||
for (ContactAddress c : (search.length() < oldSize) ? getContactsList() : getContacts()) {
|
||||
String address = c.getAddressAsDisplayableString();
|
||||
if (address.equals(searchAddress)) searchFound = true;
|
||||
if (address.startsWith("sip:")) address = address.substring(4);
|
||||
if (c.getContact() != null && c.getContact().getFullName() != null
|
||||
&& c.getContact().getFullName().toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))
|
||||
|| address.toLowerCase(Locale.getDefault()).startsWith(search.toLowerCase(Locale.getDefault()))) {
|
||||
result.add(c);
|
||||
SearchResult[] results = ContactsManager.getInstance().getMagicSearch().getContactListFromFilter(search, "");
|
||||
for (SearchResult sr : results) {
|
||||
LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(sr.getAddress());
|
||||
if (contact == null) {
|
||||
contact = new LinphoneContact();
|
||||
if (sr.getFriend() != null) {
|
||||
contact.setFriend(sr.getFriend());
|
||||
contact.refresh();
|
||||
}
|
||||
}
|
||||
if (sr.getAddress() != null) {
|
||||
boolean found = false;
|
||||
for (ContactAddress ca : result) {
|
||||
if (ca.getAddress().asStringUriOnly().equals(sr.getAddress().asStringUriOnly())) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
result.add(new ContactAddress(contact, sr.getAddress().asStringUriOnly(), contact.isFriend()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!searchFound) {
|
||||
LinphoneContact searchContact = new LinphoneContact();
|
||||
searchContact.setFullName(search);
|
||||
result.add(new ContactAddress(searchContact, searchAddress, false));
|
||||
}
|
||||
|
||||
oldSize = search.length();
|
||||
contacts = result;
|
||||
|
@ -217,7 +221,7 @@ public class SearchContactsListAdapter extends BaseAdapter {
|
|||
}
|
||||
|
||||
String address = null;
|
||||
if (c != null) {
|
||||
if (c != null && c.getFullName() != null) {
|
||||
address = c.getPresenceModelForUriOrTel(a);
|
||||
holder.name.setVisibility(View.VISIBLE);
|
||||
holder.name.setText(c.getFullName());
|
||||
|
|
Loading…
Reference in a new issue