Package com.kernelcrew.moodapp.ui
Class MoodHistoryAdapter
java.lang.Object
androidx.recyclerview.widget.RecyclerView.Adapter<MoodHistoryAdapter.MoodViewHolder>
com.kernelcrew.moodapp.ui.MoodHistoryAdapter
public class MoodHistoryAdapter
extends androidx.recyclerview.widget.RecyclerView.Adapter<MoodHistoryAdapter.MoodViewHolder>
Adapter class for binding mood event data to the RecyclerView in the mood history screen.
This adapter manages the display of mood events in a list format. It shows the date
and sequential numbering of each mood event. It also handles click events on items
through the MoodHistoryAdapter.OnItemClickListener
interface.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
ViewHolder class for mood event items.static interface
Interface for handling click events on mood items in the RecyclerView. -
Constructor Summary
ConstructorsConstructorDescriptionMoodHistoryAdapter
(List<MoodEvent> moods, MoodHistoryAdapter.OnItemClickListener listener) Constructs a new MoodHistoryAdapter with the specified data and listener. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the total number of items in the data set.getItems()
Returns a copy of the current list of mood events.void
onBindViewHolder
(MoodHistoryAdapter.MoodViewHolder holder, int position) Binds data to the ViewHolder at the specified position.onCreateViewHolder
(ViewGroup parent, int viewType) Creates a new ViewHolder when needed by the RecyclerView.void
Updates the adapter's data set with a new list of mood events.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, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
-
Constructor Details
-
MoodHistoryAdapter
Constructs a new MoodHistoryAdapter with the specified data and listener.- Parameters:
moods
- List of mood events to display; if null, an empty list is usedlistener
- Callback for item click events
-
-
Method Details
-
setMoods
Updates the adapter's data set with a new list of mood events.Replaces the existing list of mood events and notifies the adapter to refresh the RecyclerView.
- Parameters:
moods
- New list of mood events to display
-
onCreateViewHolder
@NonNull public MoodHistoryAdapter.MoodViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) Creates a new ViewHolder when needed by the RecyclerView.Inflates the mood item layout and wraps it in a ViewHolder.
- Specified by:
onCreateViewHolder
in classandroidx.recyclerview.widget.RecyclerView.Adapter<MoodHistoryAdapter.MoodViewHolder>
- Parameters:
parent
- The ViewGroup into which the new View will be addedviewType
- The view type of the new View- Returns:
- A new ViewHolder that holds the View for each mood item
-
onBindViewHolder
Binds data to the ViewHolder at the specified position.Sets the date and event number text, and configures the click listener for the item view.
- Specified by:
onBindViewHolder
in classandroidx.recyclerview.widget.RecyclerView.Adapter<MoodHistoryAdapter.MoodViewHolder>
- Parameters:
holder
- The ViewHolder to bind data toposition
- The position of the item in the data set
-
getItemCount
public int getItemCount()Returns the total number of items in the data set.- Specified by:
getItemCount
in classandroidx.recyclerview.widget.RecyclerView.Adapter<MoodHistoryAdapter.MoodViewHolder>
- Returns:
- The number of mood events in the list
-
getItems
Returns a copy of the current list of mood events.Creates a new ArrayList to avoid exposing the internal list to modification.
- Returns:
- A copy of the current list of mood events
-