/** * Define a custom Adapter which will be used in the drawer * NOTE: this is not recommender * WARNING: if you do this after adding items you will loose those! * * @param adapter the FastAdapter to use with this drawer * @return this */ public DrawerBuilder withAdapter(@NonNull FastAdapter<IDrawerItem> adapter) { this.mAdapter = adapter; //we have to rewrap as a different FastAdapter was provided adapter.addAdapter(0, mHeaderAdapter); adapter.addAdapter(1, mItemAdapter); adapter.addAdapter(2, mFooterAdapter); adapter.addExtension(mExpandableExtension); return this; }
/** * creates a new FastAdapter with the provided adapters * if adapters is null, a default ItemAdapter is defined * * @param adapter the adapters which this FastAdapter should use * @return a new FastAdapter */ @SuppressWarnings("unchecked") public static <Item extends IItem, A extends IAdapter> FastAdapter<Item> with(A adapter) { FastAdapter<Item> fastAdapter = new FastAdapter<>(); fastAdapter.addAdapter(0, adapter); return fastAdapter; }
@Test public void testAddPreviouslyFilledAdapterPropagatesPossibleTypesToParentFastAdapter() { final TestItem testItem = new TestItem("example name"); ItemAdapter<TestItem> itemAdapter = new ItemAdapter<>(); itemAdapter.add(testItem); FastAdapter<TestItem> adapter = new FastAdapter<>(); adapter.addAdapter(0, itemAdapter); final ViewGroup dummyParent = new FrameLayout(RuntimeEnvironment.application); adapter.onCreateViewHolder(dummyParent, testItem.getType()); } }