/** * Generates a List of Item based on it's List of Model using the interceptor * * @param models the List of Model which will be used to create the List of Item * @return the generated List of Item */ public List<Item> intercept(List<Model> models) { List<Item> items = new ArrayList<>(models.size()); Item item; for (Model model : models) { item = intercept(model); if (item == null) continue; items.add(item); } return items; }
/** * add a list of items at the given position within the existing items * * @param position the global position * @param list the items to add */ public ModelAdapter<Model, Item> add(int position, List<Model> list) { List<Item> items = intercept(list); return addInternal(position, items); }
/** * sets an item at the given position, overwriting the previous item * * @param position the global position * @param element the item to set */ public ModelAdapter<Model, Item> set(int position, Model element) { Item item = intercept(element); if (item == null) return this; return setInternal(position, item); }
/** * add a list of items to the end of the existing items * * @param list the items to add */ public ModelAdapter<Model, Item> add(List<Model> list) { List<Item> items = intercept(list); return addInternal(items); }
protected ModelAdapter<Model, Item> set(List<Model> list, boolean resetFilter) { List<Item> items = intercept(list); return setInternal(items, resetFilter, null); }
/** * set a new list of model items and apply it to the existing list (clear - add) for this adapter * NOTE may consider using setNewList if the items list is a reference to the list which is used inside the adapter * * @param list the items to set * @param resetFilter `true` if the filter should get reset * @param adapterNotifier a `IAdapterNotifier` allowing to modify the notify logic for the adapter (keep null for default) * @return this */ public ModelAdapter<Model, Item> set(List<Model> list, boolean resetFilter, @Nullable IAdapterNotifier adapterNotifier) { List<Item> items = intercept(list); return setInternal(items, resetFilter, adapterNotifier); }
/** * sets a complete new list of items onto this adapter, using the new list. Calls notifyDataSetChanged * * @param list the new items to set * @param retainFilter set to true if you want to keep the filter applied * @return this */ public ModelAdapter<Model, Item> setNewList(List<Model> list, boolean retainFilter) { List<Item> items = intercept(list); if (mUseIdDistributor) { getIdDistributor().checkIds(items); } //reset the filter CharSequence filter = null; if (getItemFilter().getConstraint() != null) { filter = getItemFilter().getConstraint(); getItemFilter().performFiltering(null); } mapPossibleTypes(items); boolean publishResults = filter != null && retainFilter; if (publishResults) { getItemFilter().publishResults(filter, getItemFilter().performFiltering(filter)); } mItems.setNewList(items, !publishResults); return this; }