/** * @param identifiers the set of identifiers to deselect */ public void deselectByIdentifiers(final Set<Long> identifiers) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (identifiers.contains(item.getIdentifier())) { deselect(item, position, null); } return false; } }, false); }
/** * @param items the set of items to deselect. They require a identifier. */ public void deselectByItems(final Set<Item> items) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (items.contains(item)) { deselect(item, position, null); } return false; } }, false); }
/** * @param identifiers the set of identifiers to select * @param fireEvent true if the onClick listener should be called * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void selectByIdentifiers(final Set<Long> identifiers, final boolean fireEvent, final boolean considerSelectableFlag) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (identifiers.contains(item.getIdentifier())) { select(lastParentAdapter, item, position, fireEvent, considerSelectableFlag); } return false; } }, false); }
/** * selects an item by it's identifier * * @param identifier the identifier of the item to deselect */ public void deselectByIdentifier(final long identifier) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (item.getIdentifier() == identifier) { deselect(item, position, null); return true; } return false; } }, true); }
/** * selects an item by it's identifier * * @param identifier the identifier of the item to select * @param fireEvent true if the onClick listener should be called * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void selectByIdentifier(final long identifier, final boolean fireEvent, final boolean considerSelectableFlag) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (item.getIdentifier() == identifier) { select(lastParentAdapter, item, position, fireEvent, considerSelectableFlag); return true; } return false; } }, true); }
/** * util function which recursively iterates over all items and subItems of the given adapter. * It executes the given `predicate` on every item and will either stop if that function returns true, or continue (if stopOnMatch is false) * * @param predicate the predicate to run on every item, to check for a match or do some changes (e.g. select) * @param stopOnMatch defines if we should stop iterating after the first match * @return Triple<Boolean, IItem, Integer> The first value is true (it is always not null), the second contains the item and the third the position (if the item is visible) if we had a match, (always false and null and null in case of stopOnMatch == false) */ @NonNull public Triple<Boolean, Item, Integer> recursive(AdapterPredicate<Item> predicate, boolean stopOnMatch) { return recursive(predicate, 0, stopOnMatch); }
/** * deselects all items including all subitems * * @param adapter the adapter instance * @deprecated See {@link SelectExtension#deselect()} ()} */ @Deprecated @SuppressWarnings("unchecked") public static void deselect(final FastAdapter adapter) { adapter.recursive(new AdapterPredicate() { @Override public boolean apply(@NonNull IAdapter lastParentAdapter, int lastParentPosition, @NonNull IItem item, int position) { if (position != -1) { SelectExtension extension = (SelectExtension) adapter.getExtension(SelectExtension.class); if (extension != null) { extension.deselect(position); } } else { item.withSetSelected(false); } return true; } }, false); }
@SuppressWarnings("unchecked") public static boolean selectItem(final FastAdapter adapter, final long identifier, final boolean select) { Triple<Boolean, IItem, Integer> res = adapter.recursive(new AdapterPredicate() { @Override public boolean apply(@NonNull IAdapter lastParentAdapter, int lastParentPosition, @NonNull IItem item, int position) {
/** * deselects all selections */ public void deselect() { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { deselect(item); return false; } }, false); mFastAdapter.notifyDataSetChanged(); }
/** * select all items * * @param considerSelectableFlag true if the select method should not select an item if its not selectable */ public void select(final boolean considerSelectableFlag) { mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { select(lastParentAdapter, item, -1, false, considerSelectableFlag); return false; } }, false); mFastAdapter.notifyDataSetChanged(); }
/** * @return a set with all items which are currently selected (includes subitems) */ public Set<Item> getSelectedItems() { final Set<Item> items = new ArraySet<>(); mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) { if (item.isSelected()) { items.add(item); } return false; } }, false); return items; }
/** * gets the IItem given an identifier, from all registered adapters * * @param identifier the identifier of the searched item * @return the found Pair<IItem, Integer> (the found item, and it's global position if it is currently displayed) or null */ @SuppressWarnings("unchecked") public Pair<Item, Integer> getItemById(final long identifier) { if (identifier == -1) { return null; } Triple result = recursive(new AdapterPredicate() { @Override public boolean apply(@NonNull IAdapter lastParentAdapter, int lastParentPosition, @NonNull IItem item, int position) { return item.getIdentifier() == identifier; } }, true); if (result.second == null) { return null; } else { return new Pair(result.second, result.third); } }
mFastAdapter.recursive(new AdapterPredicate<Item>() { @Override public boolean apply(@NonNull IAdapter<Item> lastParentAdapter, int lastParentPosition, Item item, int position) {
mFastAdapter.recursive(new AdapterPredicate<Item>() { ArraySet<IItem> allowedParents = new ArraySet<>();