use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class TestingHelper method resetTestUserGoals.
/**
* Test helper to reset the testuser's goals list
*/
public static void resetTestUserGoals() {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users/testuser");
usersReference.child("userGoals").setValue(null);
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class AccountManager method setUserLoginState.
/**
* Sets whether a user is marked as being online or not. Users are tagged as online will
* have a node in the online_users branch of the database
*
* @param username Name of user to tag online/offline
* @param online Online state of user. True if online, False if offline
*/
public static void setUserLoginState(String username, boolean online) {
// retrieve a reference to the online users node
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("online_users/");
// otherwise, delete any existing entry
if (online) {
usersReference.child(username).setValue(true);
} else {
usersReference.child(username).removeValue();
}
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class AccountManager method userExists.
/**
* Determines whether or not the specified user exists in the database
*
* @param username Name of the user to look up
*/
public static void userExists(final String username, @NonNull final UserExistsListener listener) {
Objects.requireNonNull(listener, "Null value for UserExistsListener is not valid.");
// retrieve a reference to the users node
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users/");
// attach a listener for data changes of the users reference. this will occur when
// the reference is populated
usersReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// if the username is a child of the users node then fire the user exists event
// indicating true, otherwise, fire event with false outcome
listener.onUserExists(dataSnapshot.hasChild(username));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class AccountManager method deleteUser.
/**
* Delete a user account from the database
*
* @param user User to be removed
*
* @param booleanResultListener Callback to be called on completion
*/
public static void deleteUser(User user, final BooleanResultListener booleanResultListener) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users/" + user.getUsername());
usersReference.removeValue(new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
// early exit condition, no one is listening for the result
if (booleanResultListener == null)
return;
// if there are no reported errors, delete succeeded
if (databaseError == null) {
booleanResultListener.onResult(true);
} else {
booleanResultListener.onResult(false);
}
}
});
}
use of com.google.firebase.database.DatabaseReference in project SEProject by NicholasBarreyre.
the class AccountManager method createUser.
/**
* Creates a new user account
*
* @param newUser User details
*/
public static void createUser(final User newUser) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("users");
usersReference.child(newUser.getUsername()).setValue(newUser, null);
}
Aggregations