Class DBAdapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>

  • All Implemented Interfaces:
    com.google.firebase.firestore.EventListener<com.google.firebase.firestore.QuerySnapshot>
    Direct Known Subclasses:
    IngredientSearchAdapter, MealPlanAdapter, RecipeAdapter, ShoppingCartIngredientAdapter, StorageIngredientAdapter

    public abstract class DBAdapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
    extends androidx.recyclerview.widget.RecyclerView.Adapter<VH>
    implements com.google.firebase.firestore.EventListener<com.google.firebase.firestore.QuerySnapshot>
    The class DBAdapter is used to display documents from Firestore Citation: Create dynamic lists with RecyclerView. Android Developers. (n.d.). Retrieved September 26, 2022, from https://developer.android.com/develop/ui/views/layout/recyclerview
    • Constructor Summary

      Constructors 
      Constructor Description
      DBAdapter​(com.google.firebase.firestore.Query query)
      DBAdapter constructor - sets the query and registers the listener
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getItemCount()
      getItemCount - gets the number of items
      protected com.google.firebase.firestore.DocumentSnapshot getSnapshot​(int index)
      getSnapshot - gets the snapshot at the given position
      protected java.util.ArrayList<com.google.firebase.firestore.DocumentSnapshot> getSnapshots()
      getSnapshots - gets the snapshots
      protected void onDataChanged​(com.google.firebase.firestore.DocumentChange change)
      onDataChanged - called when the query is updated
      void onEvent​(com.google.firebase.firestore.QuerySnapshot documentSnapshots, com.google.firebase.firestore.FirebaseFirestoreException error)
      onEvent - called when the query is updated
      void setOnDataChangedListener​(DBAdapter.OnDataChangedListener onDataChangedListener)
      setsOnDataChangedListener - sets the listener for data changes
      void setQuery​(com.google.firebase.firestore.Query query)
      setQuery - sets the query and registers the listener
      void startListening()
      startListening - starts listening to the query
      void stopListening()
      stopListening - stops listening to the query
      • 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, 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
    • Constructor Detail

      • DBAdapter

        public DBAdapter​(com.google.firebase.firestore.Query query)
        DBAdapter constructor - sets the query and registers the listener
        Parameters:
        query - the query
    • Method Detail

      • setOnDataChangedListener

        public void setOnDataChangedListener​(DBAdapter.OnDataChangedListener onDataChangedListener)
        setsOnDataChangedListener - sets the listener for data changes
        Parameters:
        onDataChangedListener - the listener
      • setQuery

        public void setQuery​(com.google.firebase.firestore.Query query)
        setQuery - sets the query and registers the listener
        Parameters:
        query - the query
      • onEvent

        public void onEvent​(@Nullable
                            com.google.firebase.firestore.QuerySnapshot documentSnapshots,
                            @Nullable
                            com.google.firebase.firestore.FirebaseFirestoreException error)
        onEvent - called when the query is updated
        Specified by:
        onEvent in interface com.google.firebase.firestore.EventListener<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
        Parameters:
        documentSnapshots - the query snapshot
        error - the error
      • onDataChanged

        protected void onDataChanged​(com.google.firebase.firestore.DocumentChange change)
        onDataChanged - called when the query is updated
        Parameters:
        change - the document change
      • getSnapshot

        protected com.google.firebase.firestore.DocumentSnapshot getSnapshot​(int index)
        getSnapshot - gets the snapshot at the given position
        Parameters:
        index - the position
        Returns:
        the snapshot
      • startListening

        public void startListening()
        startListening - starts listening to the query
      • stopListening

        public void stopListening()
        stopListening - stops listening to the query
      • getSnapshots

        protected java.util.ArrayList<com.google.firebase.firestore.DocumentSnapshot> getSnapshots()
        getSnapshots - gets the snapshots
        Returns:
        the snapshots
      • getItemCount

        public int getItemCount()
        getItemCount - gets the number of items
        Specified by:
        getItemCount in class androidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
        Returns:
        the number of items