Fix filtering when loosening query
This commit is contained in:
parent
df1109cde5
commit
ac57d0d6d4
1 changed files with 9 additions and 7 deletions
|
@ -129,13 +129,15 @@ public class PasswordFragment extends Fragment{
|
||||||
public void filterAdapter(String filter) {
|
public void filterAdapter(String filter) {
|
||||||
if (filter.isEmpty()) {
|
if (filter.isEmpty()) {
|
||||||
updateAdapter();
|
updateAdapter();
|
||||||
return;
|
} else {
|
||||||
}
|
for (PasswordItem item : PasswordRepository.getPasswords()) {
|
||||||
for (int i=0; i<recyclerAdapter.getItemCount(); i++) {
|
|
||||||
PasswordItem item = recyclerAdapter.getValues().get(i);
|
|
||||||
boolean matches = item.getName().toLowerCase().contains(filter);
|
boolean matches = item.getName().toLowerCase().contains(filter);
|
||||||
if (!matches) {
|
boolean inAdapter = recyclerAdapter.getValues().contains(item);
|
||||||
recyclerAdapter.remove(i);
|
if (matches && !inAdapter) {
|
||||||
|
recyclerAdapter.add(item);
|
||||||
|
} else if (!matches && inAdapter) {
|
||||||
|
recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue