@Override public boolean onTouch(View v, MotionEvent event, int position, FastAdapter<Item> fastAdapter, Item item) { boolean consumed = false; // handle our extensions for (IAdapterExtension<Item> ext : fastAdapter.mExtensions.values()) { if (!consumed) { consumed = ext.onTouch(v, event, position, fastAdapter, item); } else { break; } } if (fastAdapter.mOnTouchListener != null) { IAdapter<Item> adapter = fastAdapter.getAdapter(position); if (adapter != null) { return fastAdapter.mOnTouchListener.onTouch(v, event, adapter, item, position); } } return consumed; } };
@Override public boolean onLongClick(View v, int pos, FastAdapter<Item> fastAdapter, Item item) { boolean consumed = false; IAdapter<Item> adapter = fastAdapter.getAdapter(pos); if (adapter != null && item != null && item.isEnabled()) { //first call the OnPreLongClickListener which would allow to prevent executing of any following code, including selection if (fastAdapter.mOnPreLongClickListener != null) { consumed = fastAdapter.mOnPreLongClickListener.onLongClick(v, adapter, item, pos); } // handle our extensions for (IAdapterExtension<Item> ext : fastAdapter.mExtensions.values()) { if (!consumed) { consumed = ext.onLongClick(v, pos, fastAdapter, item); } else { break; } } //call the normal long click listener after selection was handled if (!consumed && fastAdapter.mOnLongClickListener != null) { consumed = fastAdapter.mOnLongClickListener.onLongClick(v, adapter, item, pos); } } return consumed; } };
@Test public void getAdapter() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); itemAdapter.set(items); assertThat(adapter.getAdapter(40)).isEqualTo(itemAdapter); }
/** * notifies the fastAdapter about new / removed items within a sub hierarchy * NOTE this currently only works for sub items with only 1 level * * @param position the global position of the parent item * @param previousCount the previous count of sub items * @return the new count of subItems */ public int notifyAdapterSubItemsChanged(int position, int previousCount) { Item item = mFastAdapter.getItem(position); if (item != null && item instanceof IExpandable) { IExpandable expandable = (IExpandable) item; IAdapter adapter = mFastAdapter.getAdapter(position); if (adapter != null && adapter instanceof IItemAdapter) { ((IItemAdapter) adapter).removeRange(position + 1, previousCount); ((IItemAdapter) adapter).add(position + 1, expandable.getSubItems()); } return expandable.getSubItems().size(); } return 0; }
@Test public void getAdapter() throws Exception { List<TestItem> items = TestDataGenerator.genTestItemList(100); itemAdapter.set(items); assertThat(adapter.getAdapter(40)).isEqualTo(itemAdapter); }
IAdapter adapter = fastAdapter.getAdapter(pos); boolean success = false; if (adapter instanceof IItemAdapter) {
IAdapter adapter = fastAdapter.getAdapter(pos); boolean success = false; if (adapter instanceof IItemAdapter) {
/** * opens the expandable item at the given position * * @param position the global position * @param notifyItemChanged true if we need to call notifyItemChanged. DEFAULT: false */ public void expand(int position, boolean notifyItemChanged) { Item item = mFastAdapter.getItem(position); if (item != null && item instanceof IExpandable) { IExpandable expandable = (IExpandable) item; //if this item is not already expanded and has sub items we go on if (!expandable.isExpanded() && expandable.getSubItems() != null && expandable.getSubItems().size() > 0) { IAdapter<Item> adapter = mFastAdapter.getAdapter(position); if (adapter != null && adapter instanceof IItemAdapter) { ((IItemAdapter<?, Item>) adapter).addInternal(position + 1, expandable.getSubItems()); } //remember that this item is now opened (not collapsed) expandable.withIsExpanded(true); //we need to notify to get the correct drawable if there is one showing the current state if (notifyItemChanged) { mFastAdapter.notifyItemChanged(position); } } } }
IAdapter adapter = mFastAdapter.getAdapter(position); if (adapter != null && adapter instanceof IItemAdapter) { ((IItemAdapter) adapter).removeRange(position + 1, expandedItemsCount[0]);
@Override public void onClick(View v, int pos, FastAdapter<Item> fastAdapter, Item item) { IAdapter<Item> adapter = fastAdapter.getAdapter(pos); if (adapter != null && item != null && item.isEnabled()) { boolean consumed = false;