Change in the contact search
This commit is contained in:
parent
3f77c02fd2
commit
b3bfd69348
2 changed files with 109 additions and 93 deletions
|
@ -58,7 +58,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
private ListView contactsList;
|
||||
private TextView noSipContact, noContact;
|
||||
private ImageView allContacts, linphoneContacts, newContact, edit, selectAll, deselectAll, delete, cancel;
|
||||
private boolean onlyDisplayLinphoneContacts, isEditMode;
|
||||
private boolean onlyDisplayLinphoneContacts, isEditMode, isSearchMode;
|
||||
private View allContactsSelected, linphoneContactsSelected;
|
||||
private LinearLayout editList, topbar;
|
||||
private int lastKnownPosition;
|
||||
|
@ -316,6 +316,8 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
}
|
||||
changeContactsToggle();
|
||||
|
||||
isSearchMode = true;
|
||||
|
||||
if (onlyDisplayLinphoneContacts) {
|
||||
contactsList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
contactsList.setAdapter(new ContactsListAdapter(ContactsManager.getInstance().getSIPContacts(search)));
|
||||
|
@ -328,6 +330,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
private void changeContactsAdapter() {
|
||||
changeContactsToggle();
|
||||
|
||||
isSearchMode = false;
|
||||
noSipContact.setVisibility(View.GONE);
|
||||
noContact.setVisibility(View.GONE);
|
||||
contactsList.setVisibility(View.VISIBLE);
|
||||
|
@ -496,6 +499,7 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
|
||||
holder.name.setText(contact.getFullName());
|
||||
|
||||
if (!isSearchMode) {
|
||||
if (getPositionForSection(getSectionForPosition(position)) != position) {
|
||||
holder.separator.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
@ -505,6 +509,9 @@ public class ContactsListFragment extends Fragment implements OnClickListener, O
|
|||
holder.separatorText.setText(String.valueOf(fullName.charAt(0)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.separator.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (contact.isInLinphoneFriendList()) {
|
||||
holder.linphoneFriend.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -117,33 +117,42 @@ public class ContactsManager extends ContentObserver {
|
|||
}
|
||||
|
||||
public synchronized List<LinphoneContact> getSIPContacts() {
|
||||
setContacts(contacts);
|
||||
return sipContacts;
|
||||
}
|
||||
|
||||
public synchronized List<LinphoneContact> getContacts(String search) {
|
||||
search = search.toLowerCase(Locale.getDefault());
|
||||
List<LinphoneContact> searchContacts = new ArrayList<LinphoneContact>();
|
||||
List<LinphoneContact> searchContactsBegin = new ArrayList<LinphoneContact>();
|
||||
List<LinphoneContact> searchContactsContain = new ArrayList<LinphoneContact>();
|
||||
for (LinphoneContact contact : contacts) {
|
||||
if (contact.getFullName() != null) {
|
||||
if (contact.getFullName().toLowerCase(Locale.getDefault()).contains(search)) {
|
||||
searchContacts.add(contact);
|
||||
if (contact.getFullName().toLowerCase(Locale.getDefault()).startsWith(search)) {
|
||||
searchContactsBegin.add(contact);
|
||||
} else if (contact.getFullName().toLowerCase(Locale.getDefault()).contains(search)) {
|
||||
searchContactsContain.add(contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
return searchContacts;
|
||||
searchContactsBegin.addAll(searchContactsContain);
|
||||
return searchContactsBegin;
|
||||
}
|
||||
|
||||
public synchronized List<LinphoneContact> getSIPContacts(String search) {
|
||||
search = search.toLowerCase(Locale.getDefault());
|
||||
List<LinphoneContact> searchContacts = new ArrayList<LinphoneContact>();
|
||||
List<LinphoneContact> searchContactsBegin = new ArrayList<LinphoneContact>();
|
||||
List<LinphoneContact> searchContactsContain = new ArrayList<LinphoneContact>();
|
||||
for (LinphoneContact contact : sipContacts) {
|
||||
if (contact.getFullName() != null) {
|
||||
if (contact.getFullName().toLowerCase(Locale.getDefault()).contains(search)) {
|
||||
searchContacts.add(contact);
|
||||
if (contact.getFullName().toLowerCase(Locale.getDefault()).startsWith(search)) {
|
||||
searchContactsBegin.add(contact);
|
||||
} else if (contact.getFullName().toLowerCase(Locale.getDefault()).contains(search)) {
|
||||
searchContactsContain.add(contact);
|
||||
}
|
||||
}
|
||||
}
|
||||
return searchContacts;
|
||||
searchContactsBegin.addAll(searchContactsContain);
|
||||
return searchContactsBegin;
|
||||
}
|
||||
|
||||
public void enableContactsAccess() {
|
||||
|
|
Loading…
Reference in a new issue