public class RVRendererAdapter<T>
extends <any>
This class is the heart of this library. It's used to avoid the library users declare a new renderer each time they have to show information into a RecyclerView.
RVRendererAdapter has to be constructed with a LayoutInflater to inflate views, one RendererBuilder to provide Renderer to RVRendererAdapter and one AdapteeCollection to provide the elements to render.
| Constructor and Description |
|---|
RVRendererAdapter(RendererBuilder<T> rendererBuilder) |
RVRendererAdapter(RendererBuilder<T> rendererBuilder,
AdapteeCollection<T> collection) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T element)
Add an element to the AdapteeCollection.
|
boolean |
addAll(java.util.Collection<? extends T> elements)
Add a Collection of elements to the AdapteeCollection.
|
void |
clear()
Remove all elements inside the AdapteeCollection.
|
void |
diffUpdate(java.util.List<T> newList)
Provides a ready to use diff update for our adapter based on the implementation of the
standard equals method from Object.
|
protected AdapteeCollection<T> |
getCollection()
Allows the client code to access the AdapteeCollection from subtypes of RendererAdapter.
|
T |
getItem(int position) |
int |
getItemCount() |
long |
getItemId(int position) |
int |
getItemViewType(int position)
Indicate to the RecyclerView the type of Renderer used to one position using a numeric value.
|
void |
onBindViewHolder(RendererViewHolder viewHolder,
int position)
Given a RendererViewHolder passed as argument and a position renders the view using the
Renderer previously stored into the RendererViewHolder.
|
RendererViewHolder |
onCreateViewHolder(android.view.ViewGroup viewGroup,
int viewType)
One of the two main methods in this class.
|
boolean |
remove(java.lang.Object element)
Remove an element from the AdapteeCollection.
|
boolean |
removeAll(java.util.Collection<?> elements)
Remove a Collection of elements to the AdapteeCollection.
|
void |
setCollection(AdapteeCollection<T> collection) |
protected void |
updateRendererExtraValues(T content,
Renderer<T> renderer,
int position)
Empty implementation created to allow the client code to extend this class without override
getView method.
|
public RVRendererAdapter(RendererBuilder<T> rendererBuilder)
public RVRendererAdapter(RendererBuilder<T> rendererBuilder, AdapteeCollection<T> collection)
public int getItemCount()
public T getItem(int position)
public long getItemId(int position)
public void setCollection(AdapteeCollection<T> collection)
public int getItemViewType(int position)
position - to analyze.public RendererViewHolder onCreateViewHolder(android.view.ViewGroup viewGroup, int viewType)
viewGroup - used to create the ViewHolder.viewType - associated to the renderer.public void onBindViewHolder(RendererViewHolder viewHolder, int position)
viewHolder - with a Renderer class inside.position - to render.public boolean add(T element)
element - to add.public boolean remove(java.lang.Object element)
element - to remove.public boolean addAll(java.util.Collection<? extends T> elements)
elements - to add.public boolean removeAll(java.util.Collection<?> elements)
elements - to remove.public void clear()
protected AdapteeCollection<T> getCollection()
protected void updateRendererExtraValues(T content, Renderer<T> renderer, int position)
This method is called before render the Renderer and can be used in RendererAdapter extension to add extra info to the renderer created like the position in the ListView/RecyclerView.
content - to be rendered.renderer - to be used to paint the content.position - of the content.public void diffUpdate(java.util.List<T> newList)
newList - to refresh our content