From 371a29863646c0e45853028baf59b0d27767483e Mon Sep 17 00:00:00 2001 From: joaomiranda Date: Tue, 27 Jan 2026 17:12:17 +0000 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20da=20lista=20de=20clubes?= =?UTF-8?q?=20e=20jogadores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/google-services.json | 1 + app/src/main/AndroidManifest.xml | 1 + .../vdcscore/data/FirebaseRepository.java | 6 ++--- .../com/example/vdcscore/models/Club.java | 26 +++++++++---------- .../com/example/vdcscore/models/Player.java | 8 +++--- .../vdcscore/ui/clubs/ClubDetailFragment.java | 2 +- .../vdcscore/ui/clubs/ClubsFragment.java | 2 +- .../vdcscore/ui/clubs/PlayerAdapter.java | 4 ++- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/google-services.json b/app/google-services.json index b06f18e..f8adbd3 100644 --- a/app/google-services.json +++ b/app/google-services.json @@ -1,6 +1,7 @@ { "project_info": { "project_number": "89853204936", + "firebase_url": "https://vdcscore-default-rtdb.firebaseio.com", "project_id": "vdcscore", "storage_bucket": "vdcscore.firebasestorage.app" }, diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 279b3a2..db92be1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + diff --git a/app/src/main/java/com/example/vdcscore/data/FirebaseRepository.java b/app/src/main/java/com/example/vdcscore/data/FirebaseRepository.java index 95526c4..8ec0ba7 100644 --- a/app/src/main/java/com/example/vdcscore/data/FirebaseRepository.java +++ b/app/src/main/java/com/example/vdcscore/data/FirebaseRepository.java @@ -33,10 +33,10 @@ public class FirebaseRepository { // --- Clubs --- public void addClub(Club club, OnCompleteListener onCompleteListener) { - String key = club.getId(); + String key = String.valueOf(club.getId()); if (key == null || key.isEmpty()) { key = mDatabase.child("clubs").push().getKey(); - club.setId(key); + club.setId(Integer.parseInt(key)); } mDatabase.child("clubs").child(key).setValue(club).addOnCompleteListener(onCompleteListener); } @@ -49,7 +49,7 @@ public class FirebaseRepository { for (DataSnapshot postSnapshot : snapshot.getChildren()) { Club club = postSnapshot.getValue(Club.class); if (club != null) { - club.setId(postSnapshot.getKey()); + club.setId(Integer.parseInt(postSnapshot.getKey())); clubs.add(club); } } diff --git a/app/src/main/java/com/example/vdcscore/models/Club.java b/app/src/main/java/com/example/vdcscore/models/Club.java index d28fbdc..3267f48 100644 --- a/app/src/main/java/com/example/vdcscore/models/Club.java +++ b/app/src/main/java/com/example/vdcscore/models/Club.java @@ -8,7 +8,7 @@ import java.util.Map; public class Club { @PropertyName("id") - private String id; + private int id; @PropertyName("nome") private String name; @@ -20,7 +20,7 @@ public class Club { private String stadium; @PropertyName("ano fundacao") - private String foundationYear; + private int foundationYear; @PropertyName("morada") private String address; @@ -29,14 +29,14 @@ public class Club { private String president; @PropertyName("jogadores") - private Map players; + private ArrayList players; public Club() { // Default constructor for Firebase - players = new HashMap<>(); + players = new ArrayList<>(); } - public Club(String id, String name, String logoUrl, String stadium, String foundationYear, String address, + public Club(int id, String name, String logoUrl, String stadium, int foundationYear, String address, String president) { this.id = id; this.name = name; @@ -45,16 +45,16 @@ public class Club { this.foundationYear = foundationYear; this.address = address; this.president = president; - this.players = new HashMap<>(); + this.players = new ArrayList<>(); } @PropertyName("id") - public String getId() { + public int getId() { return id; } @PropertyName("id") - public void setId(String id) { + public void setId(int id) { this.id = id; } @@ -89,12 +89,12 @@ public class Club { } @PropertyName("ano fundacao") - public String getFoundationYear() { + public int getFoundationYear() { return foundationYear; } @PropertyName("ano fundacao") - public void setFoundationYear(String foundationYear) { + public void setFoundationYear(int foundationYear) { this.foundationYear = foundationYear; } @@ -119,18 +119,18 @@ public class Club { } @PropertyName("jogadores") - public Map getPlayersMap() { + public ArrayList getPlayersMap() { return players; } @PropertyName("jogadores") - public void setPlayersMap(Map players) { + public void setPlayersMap(ArrayList players) { this.players = players; } public List getPlayersList() { if (players == null) return new ArrayList<>(); - return new ArrayList<>(players.values()); + return new ArrayList<>(players); } } diff --git a/app/src/main/java/com/example/vdcscore/models/Player.java b/app/src/main/java/com/example/vdcscore/models/Player.java index eff04d3..d710eff 100644 --- a/app/src/main/java/com/example/vdcscore/models/Player.java +++ b/app/src/main/java/com/example/vdcscore/models/Player.java @@ -4,7 +4,7 @@ import com.google.firebase.database.PropertyName; public class Player { @PropertyName("id") - private String id; + private int id; @PropertyName("nome") private String nome; @@ -13,18 +13,18 @@ public class Player { // Default constructor required for calls to DataSnapshot.getValue(Player.class) } - public Player(String id, String nome) { + public Player(int id, String nome) { this.id = id; this.nome = nome; } @PropertyName("id") - public String getId() { + public int getId() { return id; } @PropertyName("id") - public void setId(String id) { + public void setId(int id) { this.id = id; } diff --git a/app/src/main/java/com/example/vdcscore/ui/clubs/ClubDetailFragment.java b/app/src/main/java/com/example/vdcscore/ui/clubs/ClubDetailFragment.java index 37aa261..a184ab4 100644 --- a/app/src/main/java/com/example/vdcscore/ui/clubs/ClubDetailFragment.java +++ b/app/src/main/java/com/example/vdcscore/ui/clubs/ClubDetailFragment.java @@ -65,7 +65,7 @@ public class ClubDetailFragment extends Fragment { Club club = snapshot.getValue(Club.class); if (club != null) { binding.textDetailClubName.setText(club.getName()); - binding.textDetailFoundation.setText(club.getFoundationYear()); + binding.textDetailFoundation.setText(String.valueOf(club.getFoundationYear())); binding.textDetailPresident.setText(club.getPresident()); binding.textDetailStadium.setText(club.getStadium()); binding.textDetailAddress.setText(club.getAddress()); diff --git a/app/src/main/java/com/example/vdcscore/ui/clubs/ClubsFragment.java b/app/src/main/java/com/example/vdcscore/ui/clubs/ClubsFragment.java index de86f55..a2d4f77 100644 --- a/app/src/main/java/com/example/vdcscore/ui/clubs/ClubsFragment.java +++ b/app/src/main/java/com/example/vdcscore/ui/clubs/ClubsFragment.java @@ -58,7 +58,7 @@ public class ClubsFragment extends Fragment { } ClubAdapter adapter = new ClubAdapter(clubs, club -> { Bundle bundle = new Bundle(); - bundle.putString("clubId", club.getId()); + bundle.putString("clubId", String.valueOf(club.getId())); androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this) .navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle); }); diff --git a/app/src/main/java/com/example/vdcscore/ui/clubs/PlayerAdapter.java b/app/src/main/java/com/example/vdcscore/ui/clubs/PlayerAdapter.java index 0132de3..ba40a94 100644 --- a/app/src/main/java/com/example/vdcscore/ui/clubs/PlayerAdapter.java +++ b/app/src/main/java/com/example/vdcscore/ui/clubs/PlayerAdapter.java @@ -49,7 +49,9 @@ public class PlayerAdapter extends RecyclerView.Adapter