Correção da lista de clubes e jogadores

This commit is contained in:
2026-01-27 17:12:17 +00:00
parent cd527224bf
commit 371a298636
8 changed files with 27 additions and 23 deletions

View File

@@ -1,6 +1,7 @@
{ {
"project_info": { "project_info": {
"project_number": "89853204936", "project_number": "89853204936",
"firebase_url": "https://vdcscore-default-rtdb.firebaseio.com",
"project_id": "vdcscore", "project_id": "vdcscore",
"storage_bucket": "vdcscore.firebasestorage.app" "storage_bucket": "vdcscore.firebasestorage.app"
}, },

View File

@@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" /> <uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />

View File

@@ -33,10 +33,10 @@ public class FirebaseRepository {
// --- Clubs --- // --- Clubs ---
public void addClub(Club club, OnCompleteListener<Void> onCompleteListener) { public void addClub(Club club, OnCompleteListener<Void> onCompleteListener) {
String key = club.getId(); String key = String.valueOf(club.getId());
if (key == null || key.isEmpty()) { if (key == null || key.isEmpty()) {
key = mDatabase.child("clubs").push().getKey(); key = mDatabase.child("clubs").push().getKey();
club.setId(key); club.setId(Integer.parseInt(key));
} }
mDatabase.child("clubs").child(key).setValue(club).addOnCompleteListener(onCompleteListener); mDatabase.child("clubs").child(key).setValue(club).addOnCompleteListener(onCompleteListener);
} }
@@ -49,7 +49,7 @@ public class FirebaseRepository {
for (DataSnapshot postSnapshot : snapshot.getChildren()) { for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Club club = postSnapshot.getValue(Club.class); Club club = postSnapshot.getValue(Club.class);
if (club != null) { if (club != null) {
club.setId(postSnapshot.getKey()); club.setId(Integer.parseInt(postSnapshot.getKey()));
clubs.add(club); clubs.add(club);
} }
} }

View File

@@ -8,7 +8,7 @@ import java.util.Map;
public class Club { public class Club {
@PropertyName("id") @PropertyName("id")
private String id; private int id;
@PropertyName("nome") @PropertyName("nome")
private String name; private String name;
@@ -20,7 +20,7 @@ public class Club {
private String stadium; private String stadium;
@PropertyName("ano fundacao") @PropertyName("ano fundacao")
private String foundationYear; private int foundationYear;
@PropertyName("morada") @PropertyName("morada")
private String address; private String address;
@@ -29,14 +29,14 @@ public class Club {
private String president; private String president;
@PropertyName("jogadores") @PropertyName("jogadores")
private Map<String, Player> players; private ArrayList<Player> players;
public Club() { public Club() {
// Default constructor for Firebase // 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) { String president) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@@ -45,16 +45,16 @@ public class Club {
this.foundationYear = foundationYear; this.foundationYear = foundationYear;
this.address = address; this.address = address;
this.president = president; this.president = president;
this.players = new HashMap<>(); this.players = new ArrayList<>();
} }
@PropertyName("id") @PropertyName("id")
public String getId() { public int getId() {
return id; return id;
} }
@PropertyName("id") @PropertyName("id")
public void setId(String id) { public void setId(int id) {
this.id = id; this.id = id;
} }
@@ -89,12 +89,12 @@ public class Club {
} }
@PropertyName("ano fundacao") @PropertyName("ano fundacao")
public String getFoundationYear() { public int getFoundationYear() {
return foundationYear; return foundationYear;
} }
@PropertyName("ano fundacao") @PropertyName("ano fundacao")
public void setFoundationYear(String foundationYear) { public void setFoundationYear(int foundationYear) {
this.foundationYear = foundationYear; this.foundationYear = foundationYear;
} }
@@ -119,18 +119,18 @@ public class Club {
} }
@PropertyName("jogadores") @PropertyName("jogadores")
public Map<String, Player> getPlayersMap() { public ArrayList<Player> getPlayersMap() {
return players; return players;
} }
@PropertyName("jogadores") @PropertyName("jogadores")
public void setPlayersMap(Map<String, Player> players) { public void setPlayersMap(ArrayList<Player> players) {
this.players = players; this.players = players;
} }
public List<Player> getPlayersList() { public List<Player> getPlayersList() {
if (players == null) if (players == null)
return new ArrayList<>(); return new ArrayList<>();
return new ArrayList<>(players.values()); return new ArrayList<>(players);
} }
} }

View File

@@ -4,7 +4,7 @@ import com.google.firebase.database.PropertyName;
public class Player { public class Player {
@PropertyName("id") @PropertyName("id")
private String id; private int id;
@PropertyName("nome") @PropertyName("nome")
private String nome; private String nome;
@@ -13,18 +13,18 @@ public class Player {
// Default constructor required for calls to DataSnapshot.getValue(Player.class) // 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.id = id;
this.nome = nome; this.nome = nome;
} }
@PropertyName("id") @PropertyName("id")
public String getId() { public int getId() {
return id; return id;
} }
@PropertyName("id") @PropertyName("id")
public void setId(String id) { public void setId(int id) {
this.id = id; this.id = id;
} }

View File

@@ -65,7 +65,7 @@ public class ClubDetailFragment extends Fragment {
Club club = snapshot.getValue(Club.class); Club club = snapshot.getValue(Club.class);
if (club != null) { if (club != null) {
binding.textDetailClubName.setText(club.getName()); binding.textDetailClubName.setText(club.getName());
binding.textDetailFoundation.setText(club.getFoundationYear()); binding.textDetailFoundation.setText(String.valueOf(club.getFoundationYear()));
binding.textDetailPresident.setText(club.getPresident()); binding.textDetailPresident.setText(club.getPresident());
binding.textDetailStadium.setText(club.getStadium()); binding.textDetailStadium.setText(club.getStadium());
binding.textDetailAddress.setText(club.getAddress()); binding.textDetailAddress.setText(club.getAddress());

View File

@@ -58,7 +58,7 @@ public class ClubsFragment extends Fragment {
} }
ClubAdapter adapter = new ClubAdapter(clubs, club -> { ClubAdapter adapter = new ClubAdapter(clubs, club -> {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("clubId", club.getId()); bundle.putString("clubId", String.valueOf(club.getId()));
androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this) androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this)
.navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle); .navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle);
}); });

View File

@@ -49,7 +49,9 @@ public class PlayerAdapter extends RecyclerView.Adapter<PlayerAdapter.PlayerView
} }
public void bind(Player player) { public void bind(Player player) {
if (player != null){
name.setText(player.getNome()); name.setText(player.getNome());
} }
} }
} }
}