Package com.example.breeze_seas
Class NotificationService
java.lang.Object
com.example.breeze_seas.NotificationService
Handles sending and fetching of notifications to the database.
TODO: Add push notifications
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface definition for a callback to be invoked when user data is loaded or fails. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildNotificationData(Notification notification) Builds the shared Firestore payload used for notification documents.voidGet all notificationsvoidgetNotifications(String userId, NotificationService.OnNotificationLoadedListener listener) Gets the notifications that were meant for a specific user from the database.com.google.android.gms.tasks.Task<Void> markNotificationSeen(String notificationId) Marks one notification as seen.com.google.firebase.firestore.DocumentReferenceReturns a fresh notification document reference for callers that need to include a notification write inside a larger Firestore transaction.com.google.android.gms.tasks.Task<Void> sendNotification(Notification notification) Writes the notification to the database.com.google.android.gms.tasks.Task<Void> sendNotification(Notification notification, com.google.firebase.firestore.DocumentReference documentReference) Writes the notification to a caller-provided document reference.voidstartNotificationsListen(String userId, NotificationService.OnNotificationLoadedListener listener) Starts a realtime listener for one user's inbox.voidStops the active realtime inbox listener.
-
Constructor Details
-
NotificationService
public NotificationService()
-
-
Method Details
-
newNotificationDocument
@NonNull public com.google.firebase.firestore.DocumentReference newNotificationDocument()Returns a fresh notification document reference for callers that need to include a notification write inside a larger Firestore transaction.- Returns:
- Empty notification document reference in the shared notifications collection.
-
sendNotification
Writes the notification to the database.- Parameters:
notification- the notification that is sent to the database.
-
buildNotificationData
Builds the shared Firestore payload used for notification documents.- Parameters:
notification- Notification being serialized for Firestore.- Returns:
- Map matching the existing notification collection schema.
-
sendNotification
public com.google.android.gms.tasks.Task<Void> sendNotification(@NonNull Notification notification, @NonNull com.google.firebase.firestore.DocumentReference documentReference) Writes the notification to a caller-provided document reference.- Parameters:
notification- Notification being serialized.documentReference- Destination notification document.- Returns:
- Firestore task for the write.
-
getNotifications
public void getNotifications(String userId, NotificationService.OnNotificationLoadedListener listener) Gets the notifications that were meant for a specific user from the database.- Parameters:
userId- This user id is for filtering in the query.listener- this makes sure that data is actually received by the program.
-
getAllNotifications
Get all notifications- Parameters:
listener- Callback to handle the retrieved data or errors.
-
startNotificationsListen
public void startNotificationsListen(String userId, NotificationService.OnNotificationLoadedListener listener) Starts a realtime listener for one user's inbox.- Parameters:
userId- Device identifier for the current user.listener- Callback receiving the current inbox snapshot.
-
stopNotificationsListen
public void stopNotificationsListen()Stops the active realtime inbox listener. -
markNotificationSeen
Marks one notification as seen.- Parameters:
notificationId- Notification document id.- Returns:
- Firestore task for the update.
-