/** * selects an item and remembers its position in the selections list * * @param position the global position * @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 select(int position, boolean fireEvent, boolean considerSelectableFlag) { FastAdapter.RelativeInfo<Item> relativeInfo = mFastAdapter.getRelativeInfo(position); if (relativeInfo == null || relativeInfo.item == null) { return; } select(relativeInfo.adapter, relativeInfo.item, position, fireEvent, considerSelectableFlag); }
@Test public void getRelativeInfo() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); TestItem item = items.get(40); itemAdapter.set(items); assertThat(adapter.getRelativeInfo(40).item).isEqualTo(item); assertThat(adapter.getRelativeInfo(40).adapter).isEqualTo(itemAdapter); assertThat(adapter.getRelativeInfo(40).position).isEqualTo(40); assertThat(adapter.getRelativeInfo(0).position).isEqualTo(0); assertThat(adapter.getRelativeInfo(100).item).isEqualTo(null); }
@Test public void getRelativeInfo() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); TestItem item = items.get(40); itemAdapter.set(items); assertThat(adapter.getRelativeInfo(40).item).isEqualTo(item); assertThat(adapter.getRelativeInfo(40).adapter).isEqualTo(itemAdapter); assertThat(adapter.getRelativeInfo(40).position).isEqualTo(40); }
FastAdapter.RelativeInfo<Item> ri = mFastAdapter.getRelativeInfo(positions.get(i)); if (ri.item != null && ri.item.isSelected()) { //double verify if (ri.adapter != null && ri.adapter instanceof IItemAdapter) {
/** * 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 globalStartPosition the start position at which we star tto recursively iterate over the items. (This will not stop at the end of a sub hierarchy!) * @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, int globalStartPosition, boolean stopOnMatch) { for (int i = globalStartPosition; i < getItemCount(); i++) { //retrieve the item + it's adapter RelativeInfo<Item> relativeInfo = getRelativeInfo(i); Item item = relativeInfo.item; if (predicate.apply(relativeInfo.adapter, i, item, i) && stopOnMatch) { return new Triple<>(true, item, i); } if (item instanceof IExpandable) { Triple<Boolean, Item, Integer> res = FastAdapter.recursiveSub(relativeInfo.adapter, i, (IExpandable) item, predicate, stopOnMatch); if (res.first && stopOnMatch) { return res; } } } return new Triple<>(false, null, null); }
history.action = ACTION_REMOVE; for (int position : positions) { history.items.add(mAdapter.getRelativeInfo(position));
FastAdapter.RelativeInfo<Item> relativeInfo = getFastAdapter().getRelativeInfo(globalPosition); Item item = relativeInfo.item;