/** * Registers all of the contents in the specified type pool. If you have registered a * class, it will override the original binder(s). Note that the method is non-thread-safe * so that you should not use it in concurrent operation. * <p> * Note that the method should not be called after * {@link RecyclerView#setAdapter(RecyclerView.Adapter)}, or you have to call the setAdapter * again. * </p> * * @param pool type pool containing contents to be added to this adapter inner pool * @see #register(Class, ItemViewBinder) * @see #register(Class) */ public void registerAll(@NonNull final TypePool pool) { checkNotNull(pool); final int size = pool.size(); for (int i = 0; i < size; i++) { registerWithoutChecking( pool.getClass(i), pool.getItemViewBinder(i), pool.getLinker(i) ); } }
@Test public void shouldOverrideRegisteredBinder() { MultiTypeAdapter adapter = new MultiTypeAdapter(); adapter.register(TestItem.class, itemViewBinder); assertEquals(1, adapter.getTypePool().size()); assertEquals(itemViewBinder, adapter.getTypePool().getItemViewBinder(0)); TestItemViewBinder newBinder = new TestItemViewBinder(); adapter.register(TestItem.class, newBinder); assertEquals(newBinder, adapter.getTypePool().getItemViewBinder(0)); }