Search in sources :

Example 96 with DatabaseReference

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);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 97 with DatabaseReference

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();
    }
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 98 with DatabaseReference

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) {
        }
    });
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 99 with DatabaseReference

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);
            }
        }
    });
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 100 with DatabaseReference

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);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Aggregations

DatabaseReference (com.google.firebase.database.DatabaseReference)157 DatabaseError (com.google.firebase.database.DatabaseError)95 DataSnapshot (com.google.firebase.database.DataSnapshot)87 ValueEventListener (com.google.firebase.database.ValueEventListener)61 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)50 HashMap (java.util.HashMap)24 View (android.view.View)18 MutableData (com.google.firebase.database.MutableData)17 Transaction (com.google.firebase.database.Transaction)17 Intent (android.content.Intent)16 FirebaseUser (com.google.firebase.auth.FirebaseUser)13 ArrayList (java.util.ArrayList)12 TextView (android.widget.TextView)11 Query (com.google.firebase.database.Query)11 Map (java.util.Map)11 ProgressDialog (android.app.ProgressDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ChildEventListener (com.google.firebase.database.ChildEventListener)9 SharedPreferences (android.content.SharedPreferences)8 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8