use of com.google.firebase.database.FirebaseDatabase 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);
}
use of com.google.firebase.database.FirebaseDatabase in project SEProject by NicholasBarreyre.
the class AccountManager method isLoggedIn.
/**
* Check if a user is logged in
*
* @param user User to be removed
*
* @param booleanResultListener Callback to be called on completion
*/
public static void isLoggedIn(final User user, final BooleanResultListener booleanResultListener) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("online_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
booleanResultListener.onResult(dataSnapshot.hasChild(user.getUsername()));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.database.FirebaseDatabase in project SEProject by NicholasBarreyre.
the class TeamDetailActivity method populateMemberList.
/**
* Populates the list of teams associated with the user
*/
private void populateMemberList() {
final ListView teamMemberListView = findViewById(R.id.memberList);
// retrieve database reference to the team members
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference teamsReference = database.getReference("teams/" + team.getId() + "/teamMembers");
teamMemberAdapter = new TeamMembersAdapter(this, new ArrayList<String>());
teamsReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
teamMemberAdapter.add(dataSnapshot.getValue(String.class));
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
teamMemberAdapter.remove(dataSnapshot.getValue(String.class));
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
teamMemberListView.setAdapter(teamMemberAdapter);
teamMemberListView.setOnItemClickListener(new TeamDetailActivity.TeamMemberListClickListener());
}
use of com.google.firebase.database.FirebaseDatabase in project SEProject by NicholasBarreyre.
the class TeamManager method removeMemberFromTeam.
/**
* Removes the user from the specified team.
*
* @param team Team that user belongs to
* @param user User to be removed
*/
public static void removeMemberFromTeam(Team team, final User user) {
// retrieve database reference to the teams
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference teamsReference = database.getReference("teams/" + team.getId() + "/teamMembers");
teamsReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
Iterable<DataSnapshot> members = dataSnapshot.getChildren();
for (DataSnapshot member : members) {
if (((String) member.getValue()).equals(user.getUsername())) {
teamsReference.child(member.getKey()).removeValue();
break;
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.database.FirebaseDatabase in project SEProject by NicholasBarreyre.
the class TeamManager method updateTeam.
public static void updateTeam(Team team, final BooleanResultListener listener) {
if (AccountManager.isOnline()) {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference usersReference = database.getReference("teams/" + team.getId());
usersReference.setValue(team, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
listener.onResult(databaseError == null);
}
});
} else {
listener.onResult(false);
}
}
Aggregations