aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com
diff options
context:
space:
mode:
authorzeapo <mohamed@zenadi.com>2014-12-06 01:55:21 +0100
committerzeapo <mohamed@zenadi.com>2014-12-06 01:55:21 +0100
commitc0b0ec10fc450b8abc4513132b81a81d94e9213d (patch)
tree6b594efa83985011ab07e6ed4afff15fb6632c00 /app/src/main/java/com
parent1d2398ef85a475d50939b891b8b66bfda8d7237b (diff)
Filter the passwords recursively, useful to search through the passwords from the root
fixes #40
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java42
1 files changed, 29 insertions, 13 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index 2262b7d3..67fe79a6 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -150,25 +150,41 @@ public class PasswordFragment extends Fragment{
PasswordRepository.getPasswords(pathStack.peek()));
}
+ /**
+ * filters the list adapter
+ * @param filter the filter to apply
+ */
public void filterAdapter(String filter) {
Log.d("FRAG", "filter: " + filter);
if (filter.isEmpty()) {
refreshAdapter();
} else {
- // on the root the pathStack is empty
- List<PasswordItem> passwordItems = pathStack.isEmpty() ?
- PasswordRepository.getPasswords() :
- PasswordRepository.getPasswords(pathStack.peek());
-
- for (PasswordItem item : passwordItems) {
- boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase());
- boolean inAdapter = recyclerAdapter.getValues().contains(item);
- if (matches && !inAdapter) {
- recyclerAdapter.add(item);
- } else if (!matches && inAdapter) {
- recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item));
- }
+ recursiveFilter(filter, pathStack.isEmpty() ? null : pathStack.peek());
+ }
+ }
+
+ /**
+ * recursively filters a directory and extract all the matching items
+ * @param filter the filter to apply
+ * @param dir the directory to filter
+ */
+ private void recursiveFilter(String filter, File dir) {
+ // on the root the pathStack is empty
+ ArrayList<PasswordItem> passwordItems = dir == null ?
+ PasswordRepository.getPasswords() :
+ PasswordRepository.getPasswords(dir);
+
+ for (PasswordItem item : passwordItems) {
+ if (item.getType() == PasswordItem.TYPE_CATEGORY) {
+ recursiveFilter(filter, item.getFile());
+ }
+ boolean matches = item.toString().toLowerCase().contains(filter.toLowerCase());
+ boolean inAdapter = recyclerAdapter.getValues().contains(item);
+ if (matches && !inAdapter) {
+ recyclerAdapter.add(item);
+ } else if (!matches && inAdapter) {
+ recyclerAdapter.remove(recyclerAdapter.getValues().indexOf(item));
}
}
}