Package com.firebase.ui.firestore
Class FirestoreRecyclerAdapter<T,VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
- java.lang.Object
-
- androidx.recyclerview.widget.RecyclerView.Adapter<VH>
-
- com.firebase.ui.firestore.FirestoreRecyclerAdapter<T,VH>
-
- Type Parameters:
T- model class, for parsingDocumentSnapshots.VH-RecyclerView.ViewHolderclass.
- All Implemented Interfaces:
androidx.lifecycle.LifecycleObserver,com.firebase.ui.common.BaseChangeEventListener<com.google.firebase.firestore.DocumentSnapshot,com.google.firebase.firestore.FirebaseFirestoreException>,ChangeEventListener
public abstract class FirestoreRecyclerAdapter<T,VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder> extends androidx.recyclerview.widget.RecyclerView.Adapter<VH> implements ChangeEventListener, androidx.lifecycle.LifecycleObserver
RecyclerView adapter that listens to aFirestoreArrayand displays its data in real time.
-
-
Constructor Summary
Constructors Constructor Description FirestoreRecyclerAdapter(FirestoreRecyclerOptions<T> options)Create a new RecyclerView adapter that listens to a Firestore Query.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description TgetItem(int position)Gets the item at the specified position from the backing snapshot array.intgetItemCount()Gets the size of snapshots in adapter.ObservableSnapshotArray<T>getSnapshots()Returns the backingObservableSnapshotArrayused to populate this adapter.voidonBindViewHolder(VH holder, int position)protected abstract voidonBindViewHolder(VH holder, int position, T model)voidonChildChanged(com.firebase.ui.common.ChangeEventType type, com.google.firebase.firestore.DocumentSnapshot snapshot, int newIndex, int oldIndex)voidonDataChanged()voidonError(com.google.firebase.firestore.FirebaseFirestoreException e)voidstartListening()Start listening for database changes and populate the adapter.voidstopListening()Stop listening for database changes and clear all items in the adapter.voidupdateOptions(FirestoreRecyclerOptions<T> options)Re-initialize the Adapter with a new set of options.-
Methods inherited from class androidx.recyclerview.widget.RecyclerView.Adapter
bindViewHolder, createViewHolder, getItemId, getItemViewType, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onCreateViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
-
-
-
-
Constructor Detail
-
FirestoreRecyclerAdapter
public FirestoreRecyclerAdapter(@NonNull FirestoreRecyclerOptions<T> options)Create a new RecyclerView adapter that listens to a Firestore Query. SeeFirestoreRecyclerOptionsfor configuration options.
-
-
Method Detail
-
startListening
public void startListening()
Start listening for database changes and populate the adapter.
-
stopListening
public void stopListening()
Stop listening for database changes and clear all items in the adapter.
-
getSnapshots
@NonNull public ObservableSnapshotArray<T> getSnapshots()
Returns the backingObservableSnapshotArrayused to populate this adapter.- Returns:
- the backing snapshot array
-
getItem
@NonNull public T getItem(int position)
Gets the item at the specified position from the backing snapshot array.- See Also:
BaseObservableSnapshotArray.get(int)
-
getItemCount
public int getItemCount()
Gets the size of snapshots in adapter.- Specified by:
getItemCountin classandroidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>- Returns:
- the total count of snapshots in adapter.
- See Also:
BaseObservableSnapshotArray.size()
-
updateOptions
public void updateOptions(@NonNull FirestoreRecyclerOptions<T> options)Re-initialize the Adapter with a new set of options. Can be used to change the query without re-constructing the entire adapter.
-
onChildChanged
public void onChildChanged(@NonNull com.firebase.ui.common.ChangeEventType type, @NonNull com.google.firebase.firestore.DocumentSnapshot snapshot, int newIndex, int oldIndex)
-
onDataChanged
public void onDataChanged()
-
onError
public void onError(@NonNull com.google.firebase.firestore.FirebaseFirestoreException e)
-
onBindViewHolder
public void onBindViewHolder(@NonNull VH holder, int position)- Specified by:
onBindViewHolderin classandroidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
-
onBindViewHolder
protected abstract void onBindViewHolder(@NonNull VH holder, int position, @NonNull T model)- Parameters:
model- the model object containing the data that should be used to populate the view.- See Also:
onBindViewHolder(RecyclerView.ViewHolder, int)
-
-