/** * Generates a `Item` based on it's `Model` using the interceptor * * @param model the `Model` which will be used to create the `Item` * @return the generated `Item` */ @Nullable public Item intercept(Model model) { return mInterceptor.intercept(model); }
@Override public void onNewItems(@NonNull List<Model> newItems, int page) { int size = newItems.size(); List<Item> iitems = new ArrayList<>(size); for (int i = 0; i < size; i++) { iitems.add(mItemFactory.intercept(newItems.get(i))); } mItemAdapter.addInternal(iitems); } }
/** * the ModelAdapter does not keep a list of input model's to get retrieve them a `reverseInterceptor` is required * usually it is used to get the `Model` from a `IModelItem` * * @return a List of initial Model's */ public List<Model> getModels() { ArrayList<Model> list = new ArrayList<>(mItems.size()); for (Item item : mItems.getItems()) { if (mReverseInterceptor != null) { list.add(mReverseInterceptor.intercept(item)); } else if (item instanceof IModelItem) { list.add((Model) ((IModelItem) item).getModel()); } else { throw new RuntimeException("to get the list of models, the item either needs to implement `IModelItem` or you have to provide a `reverseInterceptor`"); } } return list; }