Package com.example.breeze_seas
Class UserDB
java.lang.Object
com.example.breeze_seas.UserDB
This class provides methods to create, update, delete, and retrieve users
using the device's unique ID as the primary key.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface definition for a callback to be invoked when user data is loaded or fails.static interfaceReports success or failure for user mutations that need a completion callback.static interfaceCallbacks fired by the real-time users listener. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncom.google.android.gms.tasks.Task<Void> createUser(User user) Creates a new user record in the database.voiddeleteUser(String deviceId) Deletes all trace of the user from the database except comments.voidgetUser(String deviceId, UserDB.OnUserLoadedListener listener) Fetches a user document from Firestore.voidstartUsersListen(UserDB.UsersChangedCallback callback) Starts listening to the "users" collection in real time.voidStops listener for the "users" collection.voidupdateUser(String deviceId, Map<String, Object> updates) Updates specific fields of an existing user document.voidupdateUser(String deviceId, Map<String, Object> updates, UserDB.UserMutationCallback callback) Updates specific fields of an existing user document and reports the result.
-
Constructor Details
-
UserDB
public UserDB()
-
-
Method Details
-
createUser
Creates a new user record in the database. If the document already exists, it merges the new data with existing fields. Sets thecreatedAttimestamp to the server time.- Parameters:
user- TheUserobject containing the profile data to be stored.
-
updateUser
Updates specific fields of an existing user document. Automatically appends anupdatedAtserver timestamp to the request.- Parameters:
deviceId- The unique identifier of the user to update.updates- A Map containing field names as keys and the new values to be updated.
-
updateUser
public void updateUser(String deviceId, Map<String, Object> updates, @Nullable UserDB.UserMutationCallback callback) Updates specific fields of an existing user document and reports the result.- Parameters:
deviceId- The unique identifier of the user to update.updates- A Map containing field names as keys and the new values to be updated.callback- Optional callback receiving success or failure.
-
deleteUser
Deletes all trace of the user from the database except comments.- Parameters:
deviceId- The unique identifier of the user to be deleted.
-
startUsersListen
Starts listening to the "users" collection in real time. Any add, modify, or remove on any user document will fire the appropriate callback.- Parameters:
callback- Receives individual change events or errors.
-
stopUsersListen
public void stopUsersListen()Stops listener for the "users" collection. -
getUser
Fetches a user document from Firestore. Results are returned via the providedUserDB.OnUserLoadedListener.- Parameters:
deviceId- The unique identifier of the user to fetch.listener- The callback listener to handle the retrieved data or errors.
-