Skip to content

Commit

Permalink
query the score once for completed matches
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardpepa committed Jun 19, 2022
1 parent a8e9920 commit 3337faa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
10 changes: 5 additions & 5 deletions WeBall-Statistics-Mobile/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,30 @@ public void onCancelled(@NonNull DatabaseError error) {
databaseReference.addValueEventListener(listenerForPlayer);
}

//
public void setPoints(Fragment fragment, TextView textView, int matchId, int teamId1, int teamId2) {
get(matchId).addOnSuccessListener(new OnSuccessListener<DataSnapshot>() {
@Override
public void onSuccess(DataSnapshot dataSnapshot) {
TeamLiveStatistics team1 = dataSnapshot.child("team_id: " + teamId1).getValue(TeamLiveStatistics.class);
TeamLiveStatistics team2 = dataSnapshot.child("team_id: " + teamId2).getValue(TeamLiveStatistics.class);

int scoreTeam1 = 0;
int scoreTeam2 = 0;

if (team1 != null) {
scoreTeam1 = team1.getSuccessful_threepointer() * 3 + team1.getSuccessful_twopointer() * 2 + team1.getSuccessful_freethrow();
}

if (team2 != null) {
scoreTeam2 = team2.getSuccessful_threepointer() * 3 + team2.getSuccessful_twopointer() * 2 + team2.getSuccessful_freethrow();
}

UIHandler.updateScore(fragment, textView, scoreTeam1, scoreTeam2);

}
});
}

public void setListenerForPoints(Fragment fragment, TextView textView, int matchId, int teamId1, int teamId2) {
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void run() {
View viewMatch = getLayoutInflater().inflate(R.layout.matches_previous_layout, null);
TextView dateView = viewMatch.findViewById(R.id.match_start_date2);
dateView.setText("Week " + liveMatches.get(i).getDate());
DAOLiveMatchService.getInstance().setListenerForPoints(PreviousMatches.this,
DAOLiveMatchService.getInstance().setPoints(PreviousMatches.this,
viewMatch.findViewById(R.id.score_text),
liveMatches.get(i).getId(),
liveMatches.get(i).getTeamLandlord_id(),
Expand Down Expand Up @@ -195,7 +195,7 @@ public void callback(Team returnedObject) {
navigate(viewMatch, liveMatches.get(finalI).getId());
} catch (InterruptedException e) {
e.printStackTrace();
}finally {
} finally {

}

Expand Down

0 comments on commit 3337faa

Please sign in to comment.