From 9fe95d13a59e60c7f57e28f80302950b6dbd5b4f Mon Sep 17 00:00:00 2001 From: "DESKTOP-I3LOKU1\\leop" Date: Sun, 19 Jun 2022 19:47:01 +0300 Subject: [PATCH] fixed error with live update --- .../.idea/deploymentTargetDropDown.xml | 4 ++-- .../Service/DAOLiveMatchService.java | 14 +++++++++++++- .../Statistics/LivePlayerStatistics.java | 9 ++++++--- .../weball_statistics/configuration/Config.java | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/WeBall-Statistics-Mobile/.idea/deploymentTargetDropDown.xml b/WeBall-Statistics-Mobile/.idea/deploymentTargetDropDown.xml index 42315690..15582914 100644 --- a/WeBall-Statistics-Mobile/.idea/deploymentTargetDropDown.xml +++ b/WeBall-Statistics-Mobile/.idea/deploymentTargetDropDown.xml @@ -7,11 +7,11 @@ - + - + \ No newline at end of file diff --git a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/Service/DAOLiveMatchService.java b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/Service/DAOLiveMatchService.java index b2c901b7..47094f88 100644 --- a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/Service/DAOLiveMatchService.java +++ b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/Service/DAOLiveMatchService.java @@ -32,6 +32,7 @@ public class DAOLiveMatchService implements DAOCRUDService { public static DAOLiveMatchService instance; private final DatabaseReference databaseReference; + private boolean listenerForTeam = true; private DAOLiveMatchService() { FirebaseDatabase db = FirebaseDatabase.getInstance(); @@ -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() { @@ -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) { @@ -183,6 +192,9 @@ public void onDataChange(@NonNull DataSnapshot snapshot) { if (team == null) { return; } + if (teamSelected != listenerForTeam) { + return; + } HashMap mapof = fragment.getMapOfStatistics(); for (LiveStatisticsEnum statistic : LiveStatisticsEnum.values()) { diff --git a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/UI_Controller/LiveController/Statistics/LivePlayerStatistics.java b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/UI_Controller/LiveController/Statistics/LivePlayerStatistics.java index 08cdf7de..e432deb9 100644 --- a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/UI_Controller/LiveController/Statistics/LivePlayerStatistics.java +++ b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/UI_Controller/LiveController/Statistics/LivePlayerStatistics.java @@ -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() { @@ -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(); @@ -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); diff --git a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/configuration/Config.java b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/configuration/Config.java index 07547fd8..df09f00b 100644 --- a/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/configuration/Config.java +++ b/WeBall-Statistics-Mobile/app/src/main/java/uom/team2/weball_statistics/configuration/Config.java @@ -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";