Package com.xffffff.wellfed.common
Class DBAdapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
- java.lang.Object
-
- androidx.recyclerview.widget.RecyclerView.Adapter<VH>
-
- com.xffffff.wellfed.common.DBAdapter<VH>
-
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DBAdapter.OnDataChangedListener
The listener for data changes
-
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 itemsprotected com.google.firebase.firestore.DocumentSnapshot
getSnapshot(int index)
getSnapshot - gets the snapshot at the given positionprotected java.util.ArrayList<com.google.firebase.firestore.DocumentSnapshot>
getSnapshots()
getSnapshots - gets the snapshotsprotected void
onDataChanged(com.google.firebase.firestore.DocumentChange change)
onDataChanged - called when the query is updatedvoid
onEvent(com.google.firebase.firestore.QuerySnapshot documentSnapshots, com.google.firebase.firestore.FirebaseFirestoreException error)
onEvent - called when the query is updatedvoid
setOnDataChangedListener(DBAdapter.OnDataChangedListener onDataChangedListener)
setsOnDataChangedListener - sets the listener for data changesvoid
setQuery(com.google.firebase.firestore.Query query)
setQuery - sets the query and registers the listenervoid
startListening()
startListening - starts listening to the queryvoid
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
-
-
-
-
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 interfacecom.google.firebase.firestore.EventListener<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
- Parameters:
documentSnapshots
- the query snapshoterror
- 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 classandroidx.recyclerview.widget.RecyclerView.Adapter<VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder>
- Returns:
- the number of items
-
-