Class FirestoreRecyclerAdapter<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>

  • Type Parameters:
    T - model class, for parsing DocumentSnapshots.
    VH - RecyclerView.ViewHolder class.
    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 a FirestoreArray and displays its data in real time.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      T getItem​(int position)
      Gets the item at the specified position from the backing snapshot array.
      int getItemCount()
      Gets the size of snapshots in adapter.
      ObservableSnapshotArray<T> getSnapshots()
      Returns the backing ObservableSnapshotArray used to populate this adapter.
      void onBindViewHolder​(VH holder, int position)  
      protected abstract void onBindViewHolder​(VH holder, int position, T model)  
      void onChildChanged​(com.firebase.ui.common.ChangeEventType type, com.google.firebase.firestore.DocumentSnapshot snapshot, int newIndex, int oldIndex)  
      void onDataChanged()  
      void onError​(com.google.firebase.firestore.FirebaseFirestoreException e)  
      void startListening()
      Start listening for database changes and populate the adapter.
      void stopListening()
      Stop listening for database changes and clear all items in the adapter.
      void updateOptions​(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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
      • 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:
        getItemCount in class androidx.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)
        Specified by:
        onChildChanged in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onDataChanged

        public void onDataChanged()
        Specified by:
        onDataChanged in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onError

        public void onError​(@NonNull
                            com.google.firebase.firestore.FirebaseFirestoreException e)
        Specified by:
        onError in interface com.firebase.ui.common.BaseChangeEventListener<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
      • onBindViewHolder

        public void onBindViewHolder​(@NonNull
                                     VH holder,
                                     int position)
        Specified by:
        onBindViewHolder in class androidx.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)