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

  • All Implemented Interfaces:
    androidx.lifecycle.LifecycleObserver

    public abstract class FirestorePagingAdapter<T,​VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
    extends androidx.paging.PagedListAdapter<com.google.firebase.firestore.DocumentSnapshot,​VH>
    implements androidx.lifecycle.LifecycleObserver
    Paginated RecyclerView Adapter for a Cloud Firestore query. Configured with FirestorePagingOptions.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void onBindViewHolder​(VH holder, int position)  
      protected abstract void onBindViewHolder​(VH holder, int position, T model)  
      protected void onError​(java.lang.Exception e)
      Called whenever the Exception is caught.
      protected void onLoadingStateChanged​(LoadingState state)
      Called whenever the loading state of the adapter changes.
      void refresh()
      To attempt to refresh the list.
      void retry()
      If onLoadingStateChanged(LoadingState) indicates error state, call this method to attempt to retry the most recent failure.
      void startListening()
      Start listening to paging / scrolling events and populating adapter data.
      void stopListening()
      Unsubscribe from paging / scrolling events, no more data will be populated, but the existing data will remain.
      void updateOptions​(FirestorePagingOptions<T> options)
      Re-initialize the Adapter with a new set of options.
      • Methods inherited from class androidx.paging.PagedListAdapter

        getCurrentList, getItem, getItemCount, onCurrentListChanged, onCurrentListChanged, submitList, submitList
      • 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

      • refresh

        public void refresh()
        To attempt to refresh the list. It will reload the list from beginning.
      • updateOptions

        public void updateOptions​(@NonNull
                                  FirestorePagingOptions<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.
      • startListening

        public void startListening()
        Start listening to paging / scrolling events and populating adapter data.
      • stopListening

        public void stopListening()
        Unsubscribe from paging / scrolling events, no more data will be populated, but the existing data will remain.
      • 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)
      • onLoadingStateChanged

        protected void onLoadingStateChanged​(@NonNull
                                             LoadingState state)
        Called whenever the loading state of the adapter changes.

        When the state is LoadingState.ERROR the adapter will stop loading any data unless retry() is called.

      • onError

        protected void onError​(@NonNull
                               java.lang.Exception e)
        Called whenever the Exception is caught.

        When Exception is caught the adapter will stop loading any data