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