public class RepositoryAdapter
extends android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>
implements com.google.android.agera.Updatable
RecyclerView.Adapter that presents the data from a sequence of
Repositories, mixed with optional static items and static layouts. The
sequence is static but each repository can be presented in zero or more item views as specified
by their associated RepositoryPresenters.
Updates from the repositories are individually monitored and translated to adapter events by
the presenters using RepositoryPresenter.getUpdates(T, T, android.support.v7.util.ListUpdateCallback). This adapter is also an
Updatable for observing any additional Observables; updates from these
observables cause this adapter to go through all presenters to translate the changes to adapter
events. On any failure to translate the changes to fine-grained adapter events, a
data set changed event will be used as the fallback.
The adapter will only be observing the repositories and additional observables when it is
active -- between the calls to startObserving() and stopObserving().
Typically startObserving() is called in Activity.onStart() and
stopObserving() in Activity.onStop(). Calls to startObserving() and
stopObserving() has to be paired. If stopObserving() is not called the
RepositoryAdapter will stay active and will potentially leak memory or be unnecessarily
wasteful with system resources.
This adapter can be subclassed to handle special requirements, such as creating custom view holders, handling item view lifecycle events, and implementing additional interfaces.
| Modifier and Type | Class and Description |
|---|---|
static class |
RepositoryAdapter.Builder
Builds a
RepositoryAdapter. |
| Constructor and Description |
|---|
RepositoryAdapter(RepositoryAdapter.Builder builder) |
| Modifier and Type | Method and Description |
|---|---|
int |
getItemCount() |
long |
getItemId(int position) |
int |
getItemViewType(int position) |
void |
onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position) |
android.support.v7.widget.RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int layoutResourceId)
Creates a new view holder holding the view inflated from the provided
layoutResourceId. |
boolean |
onFailedToRecycleView(android.support.v7.widget.RecyclerView.ViewHolder holder) |
void |
onViewRecycled(android.support.v7.widget.RecyclerView.ViewHolder holder) |
static RepositoryAdapter.Builder |
repositoryAdapter()
Builds a
RepositoryAdapter. |
void |
startObserving()
Starts observing any
Repository and additional Observables added. |
void |
stopObserving()
Stops observing any
Repository and additional Observables added. |
void |
update()
Goes through all
RepositoryAdapters associated with any added Repository to
discover and notify of any data changes. |
bindViewHolder, createViewHolder, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onViewAttachedToWindow, onViewDetachedFromWindow, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserverpublic RepositoryAdapter(@NonNull
RepositoryAdapter.Builder builder)
@NonNull public static RepositoryAdapter.Builder repositoryAdapter()
RepositoryAdapter.public final void startObserving()
Repository and additional Observables added. Calls to this
method must be paired with calls to stopObserving().public final void stopObserving()
Repository and additional Observables added. Calls to this
method must be paired with calls to startObserving().public final void update()
RepositoryAdapters associated with any added Repository to
discover and notify of any data changes.update in interface com.google.android.agera.UpdatableRepositoryPresenter.getUpdates(T, T, android.support.v7.util.ListUpdateCallback)public final int getItemCount()
getItemCount in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public final int getItemViewType(int position)
getItemViewType in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public final long getItemId(int position)
getItemId in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public android.support.v7.widget.RecyclerView.ViewHolder onCreateViewHolder(android.view.ViewGroup parent,
int layoutResourceId)
layoutResourceId.
This implementation inflates the view using the parent's context and creates a holder
that adds no value to the base class RecyclerView.ViewHolder. Override this method for
any special requirements.onCreateViewHolder in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public final void onBindViewHolder(android.support.v7.widget.RecyclerView.ViewHolder holder,
int position)
onBindViewHolder in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public boolean onFailedToRecycleView(android.support.v7.widget.RecyclerView.ViewHolder holder)
onFailedToRecycleView in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>public void onViewRecycled(android.support.v7.widget.RecyclerView.ViewHolder holder)
onViewRecycled in class android.support.v7.widget.RecyclerView.Adapter<android.support.v7.widget.RecyclerView.ViewHolder>