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