Package com.example.breeze_seas
Class EventHandler
java.lang.Object
com.example.breeze_seas.EventHandler
Class to help manage a list of events with realtime updates and search filters.
-
Constructor Summary
ConstructorsConstructorDescriptionEventHandler(android.app.Activity activity, android.content.Context context, com.google.firebase.firestore.Query q, String userId, boolean hideCoOrganizerEvents, boolean showRegistrableEventsOnly, boolean enableSearchFilter) Creates EventHandler based on passed query. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all advanced Explore filters and refreshes the list.findEventById(String eventId) Helper method to find and return event object based on eventId.intReturns the number of advanced Explore filters that are currently active.Returns the currently selected availability end.Returns the currently selected availability start.Returns the list of event to be shown in the adapter.androidx.lifecycle.MutableLiveData<Event> Gets the eventShown.Returns the selected maximum event capacity filter.Returns the selected minimum event capacity filter.booleanReturns whether any advanced Explore filter is active.voidsetAdvancedFilters(Long availabilityStartMillis, Long availabilityEndMillis, Integer minCapacityFilter, Integer maxCapacityFilter) Applies the advanced Explore filters and refreshes the filtered event list.voidSets the eventShown.voidsetKeywordString(String keywordString) Takes the passed string and updates the filteredListOfEvents.voidStarts listeners to get realtime updates of the event list.voidStop fetching realtime updates of event list.
-
Constructor Details
-
EventHandler
public EventHandler(android.app.Activity activity, android.content.Context context, com.google.firebase.firestore.Query q, String userId, boolean hideCoOrganizerEvents, boolean showRegistrableEventsOnly, boolean enableSearchFilter) Creates EventHandler based on passed query.- Parameters:
activity- Activity object. Used for exiting out of the app when firebase listener fails.context- Context object used for displaying toast messages.q- Query to generate events from.userId- DeviceId of current user. Used for co organizer checks.hideCoOrganizerEvents- Boolean dictating whether coOrganized Events should be displayed or not.showRegistrableEventsOnly- Boolean dictating to only compute on Events that are currently registrable.enableSearchFilter- Boolean dictating whether filter computations should be enabled or not.
-
-
Method Details
-
setEventShown
Sets the eventShown. This is used to allow other fragments to observe this for event updates.- Parameters:
e- The event object.
-
getEventShown
Gets the eventShown. Other fragments may set up an observer in order to receive realtime updates.- Returns:
- MutableLiveData encapsulating the event.
-
setKeywordString
Takes the passed string and updates the filteredListOfEvents.- Parameters:
keywordString- Keyword search string.
-
setAdvancedFilters
public void setAdvancedFilters(@Nullable Long availabilityStartMillis, @Nullable Long availabilityEndMillis, @Nullable Integer minCapacityFilter, @Nullable Integer maxCapacityFilter) Applies the advanced Explore filters and refreshes the filtered event list.- Parameters:
availabilityStartMillis- Start of the selected availability window, or null.availabilityEndMillis- End of the selected availability window, or null.minCapacityFilter- Minimum capacity filter, or null.maxCapacityFilter- Maximum capacity filter, or null.
-
clearAdvancedFilters
public void clearAdvancedFilters()Clears all advanced Explore filters and refreshes the list. -
getAvailabilityStartMillis
Returns the currently selected availability start.- Returns:
- Start of the selected availability window, or null.
-
getAvailabilityEndMillis
Returns the currently selected availability end.- Returns:
- End of the selected availability window, or null.
-
getMinCapacityFilter
Returns the selected minimum event capacity filter.- Returns:
- Minimum capacity filter, or null.
-
getMaxCapacityFilter
Returns the selected maximum event capacity filter.- Returns:
- Maximum capacity filter, or null.
-
hasAdvancedFilters
public boolean hasAdvancedFilters()Returns whether any advanced Explore filter is active.- Returns:
- true if at least one advanced filter is set.
-
getActiveFilterCount
public int getActiveFilterCount()Returns the number of advanced Explore filters that are currently active. Date range counts as a single filter pill.- Returns:
- Number of active advanced filters.
-
getEvents
Returns the list of event to be shown in the adapter. Use case is for callers to set up observers and update whenever the list changes.- Returns:
- MutableLiveData wrapping an ArrayList of events.
-
findEventById
Helper method to find and return event object based on eventId.- Parameters:
eventId- String to identify the event object by.- Returns:
- Event object if present in query hashmap, otherwise null.
-
startListen
public void startListen()Starts listeners to get realtime updates of the event list. -
stopListen
public void stopListen()Stop fetching realtime updates of event list.
-