Skip to content

Commit

Permalink
fixed error with live update
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardpepa committed Jun 19, 2022
1 parent c8e9c73 commit 9fe95d1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 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 @@ -32,6 +32,7 @@
public class DAOLiveMatchService implements DAOCRUDService<TeamLiveStatistics> {
public static DAOLiveMatchService instance;
private final DatabaseReference databaseReference;
private boolean listenerForTeam = true;

private DAOLiveMatchService() {
FirebaseDatabase db = FirebaseDatabase.getInstance();
Expand All @@ -45,6 +46,14 @@ public static DAOLiveMatchService getInstance() {
return instance;
}

public boolean isListenerForTeam() {
return listenerForTeam;
}

public void setListenerForTeam(boolean listenerForTeam) {
this.listenerForTeam = listenerForTeam;
}

public void setChronometerTime(int matchId, Fragment fragment, Chronometer chronometer) {

get(matchId).addOnSuccessListener(new OnSuccessListener<DataSnapshot>() {
Expand Down Expand Up @@ -170,7 +179,7 @@ public void onCancelled(@NonNull DatabaseError error) {
});
}

public void setDataListenerForPlayer(LivePlayerStatistics fragment, int matchId, int teamId1) {
public void setDataListenerForPlayer(LivePlayerStatistics fragment, int matchId, int teamId1, boolean teamSelected) {
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
Expand All @@ -183,6 +192,9 @@ public void onDataChange(@NonNull DataSnapshot snapshot) {
if (team == null) {
return;
}
if (teamSelected != listenerForTeam) {
return;
}
HashMap<String, View> mapof = fragment.getMapOfStatistics();

for (LiveStatisticsEnum statistic : LiveStatisticsEnum.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ public void loadInitialTeamsPlayers() {
createPlayers(teamLandlordPlayers, teamLandlordPlayerViews);
autoSelectPlayer(teamLandlordPlayers.get(0));

DAOLiveMatchService.getInstance().setListenerForTeam(true);
DAOLivePlayerStatistics.getInstance().setDataChangeListener(LivePlayerStatistics.this, matchId, teamLandlordId, teamLandlordPlayers.get(0).getId());
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, matchId, teamLandlordId);
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, matchId, teamLandlordId, true);

if (LivePlayerStatistics.this.getActivity() != null && LivePlayerStatistics.this.isAdded()) {
LivePlayerStatistics.this.requireActivity().runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -248,8 +249,9 @@ public void autoSelectPlayer(Player player) {
int playerSelectedId = teamSelected ? teamLandlordPlayers.get(index).getId() : teamGuestPlayers.get(index).getId();
int teamSelectedId = teamSelected ? teamLandlordId : teamGuestId;

DAOLiveMatchService.getInstance().setListenerForTeam(teamSelected);
DAOLivePlayerStatistics.getInstance().setDataChangeListener(LivePlayerStatistics.this, matchId, teamSelectedId, playerSelectedId);
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, matchId, teamSelectedId);
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, matchId, teamSelectedId, teamSelected);

String fullName = player.getName().toUpperCase(Locale.ROOT).charAt(0) + ". " + player.getSurname();

Expand Down Expand Up @@ -282,8 +284,9 @@ public void onClick(View view) {

int teamSelectedId = teamSelected ? teamLandlordId : teamGuestId;

DAOLiveMatchService.getInstance().setListenerForTeam(teamSelected);
DAOLivePlayerStatistics.getInstance().setDataChangeListener(LivePlayerStatistics.this, match.getId(), teamSelectedId, playerSelectedId);
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, match.getId(), teamSelectedId);
DAOLiveMatchService.getInstance().setDataListenerForPlayer(LivePlayerStatistics.this, match.getId(), teamSelectedId, teamSelected);

Utils.changeBackgroundColorInView(getContext(), playerView, R.color.alt_blue);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Config {

public static final String IP = "192.168.56.1";
public static final String IP = "192.168.0.119";
public static final String API_URL = "http://" + IP + "/WeBall_Statistics-Backend/API/";
public static final String MATCHES_API = "http://" + IP + "/weBall_Statistics-Backend/API/match.php";
public static final String API_REFEREE = "referee.php";
Expand Down

0 comments on commit 9fe95d1

Please sign in to comment.