Skip to content

Commit

Permalink
Resolved #362 - Filter items with optional originalList (works with m…
Browse files Browse the repository at this point in the history
…ulti level)
  • Loading branch information
davideas committed May 11, 2017
1 parent dbbe6c0 commit 6f0cf2b
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4142,12 +4142,16 @@ public boolean isFiltering() {
* @since 5.0.0-b1
*/
private boolean filterObject(T item, List<T> values) {
// Stop filter task if cancelled
if (mFilterAsyncTask != null && mFilterAsyncTask.isCancelled()) return false;
// Skip already filtered items (it happens when internal originalList)
if (values.contains(item)) return false;
// Start to compose the filteredItems to maintain the order of addition
// It will be discarded if no subItem will be filtered
List<T> filteredItems = new ArrayList<>();
filteredItems.add(item);
// Filter subItems
boolean filtered = filterSubItems(item, filteredItems);
boolean filtered = filterSubObjects(item, filteredItems);
// If no subItem was filtered, fallback to Normal filter
if (!filtered) {
filtered = filterObject(item, getSearchText());
Expand All @@ -4165,7 +4169,7 @@ private boolean filterObject(T item, List<T> values) {
return filtered;
}

private boolean filterSubItems(T item, List<T> filteredItems) {
private boolean filterSubObjects(T item, List<T> filteredItems) {
// Reset expansion flag
boolean filtered = false;
// Is item an expandable?
Expand All @@ -4177,7 +4181,7 @@ private boolean filterSubItems(T item, List<T> filteredItems) {
mExpandedFilterFlags = new HashSet<>();
mExpandedFilterFlags.add(expandable);
}
// Children scan filter
// SubItems scan filter
for (T subItem : getCurrentChildren(expandable)) {
if (subItem instanceof IExpandable && filterObject(subItem, filteredItems)) {
filtered = true;
Expand All @@ -4186,9 +4190,7 @@ private boolean filterSubItems(T item, List<T> filteredItems) {
subItem.setHidden(!filterObject(subItem, getSearchText()));
if (!subItem.isHidden()) {
filtered = true;
if (mOriginalList == null || (mOriginalList != null && !expandable.isExpanded())) {
filteredItems.add(subItem);
}
filteredItems.add(subItem);
}
}
}
Expand Down

0 comments on commit 6f0cf2b

Please sign in to comment.