use of ca.dal.cs.athletemonitor.athletemonitor.adapters.TeamsAdapter in project SEProject by NicholasBarreyre.
the class TeamActivity method populateTeamList.
/**
* Populates the list of teams associated with the user
*/
private void populateTeamList() {
// Get the reference to the UI contents
final ListView teamListView = findViewById(R.id.teamList);
// retrieve database reference to the teams
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference teamsReference = database.getReference("teams");
teamAdapter = new TeamsAdapter(this, new ArrayList<Team>());
teamsReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue(Team.class).getTeamMembers().contains(user.getUsername())) {
if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) == -1)
teamAdapter.add(dataSnapshot.getValue(Team.class));
}
if (dataSnapshot.getValue(Team.class).getOwner().equals(user.getUsername())) {
TeamActivity.this.handleJoinRequests(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue(Team.class).getTeamMembers().contains(user.getUsername())) {
if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) == -1) {
teamAdapter.add(dataSnapshot.getValue(Team.class));
} else {
teamAdapter.remove(teamAdapter.getItem(teamAdapter.getPosition(dataSnapshot.getValue(Team.class))));
teamAdapter.add(dataSnapshot.getValue(Team.class));
}
} else if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) != -1) {
teamAdapter.remove(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue(Team.class).getTeamMembers().contains(user.getUsername())) {
if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) != -1)
teamAdapter.remove(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.d("TeamList", dataSnapshot.getValue(Team.class).getName() + "has moved locations...");
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
teamListView.setAdapter(teamAdapter);
teamListView.setOnItemClickListener(new TeamListClickListener());
}
use of ca.dal.cs.athletemonitor.athletemonitor.adapters.TeamsAdapter in project SEProject by NicholasBarreyre.
the class SearchResultsActivity method populateListWithSearchResults.
private void populateListWithSearchResults(final String query) {
// Get the reference to the UI contents
final ListView teamListView = findViewById(R.id.teamList);
// retrieve database reference to the teams
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference teamsReference = database.getReference("teams");
teamAdapter = new TeamsAdapter(this, new ArrayList<Team>());
teamsReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// TODO: Don't add teams already a member of
if (dataSnapshot.getValue(Team.class).getName().toUpperCase().contains(query.toUpperCase())) {
teamAdapter.add(dataSnapshot.getValue(Team.class));
teamAdapter.notifyDataSetChanged();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
// TODO: Don't add teams already a member of
if (dataSnapshot.getValue(Team.class).getName().toUpperCase().contains(query.toUpperCase())) {
teamAdapter.add(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) != -1) {
teamAdapter.remove(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.d("TeamList", dataSnapshot.getValue(Team.class).getName() + "has moved locations...");
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
teamListView.setAdapter(teamAdapter);
teamListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Team team = teamAdapter.getItem(position);
AlertDialog.Builder builder = new AlertDialog.Builder(SearchResultsActivity.this);
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setPositiveButton("Apply", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final AlertDialog.Builder confirmDialog = new AlertDialog.Builder(SearchResultsActivity.this);
confirmDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
confirmDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TeamManager.requestToJoinTeam(team, user);
dialog.dismiss();
finish();
}
});
confirmDialog.setTitle("Confirm Application").setMessage("Are you sure you want to apply to " + team.getName() + "?").show();
}
});
builder.setTitle("Apply To Team").setMessage("\nDo you want to apply to " + team.getName()).show();
}
});
}
Aggregations