conseguir vizualisar os clubes

This commit is contained in:
2026-03-10 16:39:53 +00:00
parent 702320e819
commit 17ab677589
7 changed files with 119 additions and 41 deletions

View File

@@ -28,12 +28,8 @@ public class Club implements Serializable {
@PropertyName("presidente") @PropertyName("presidente")
private String president; private String president;
@PropertyName("jogadores")
private HashMap<String, Player> players;
public Club() { public Club() {
// Default constructor for Firebase // Default constructor for Firebase
players = new HashMap<>();
} }
public Club(int id, String name, String imageUrl, String stadium, int foundationYear, String address, public Club(int id, String name, String imageUrl, String stadium, int foundationYear, String address,
@@ -45,7 +41,6 @@ public class Club implements Serializable {
this.foundationYear = foundationYear; this.foundationYear = foundationYear;
this.address = address; this.address = address;
this.president = president; this.president = president;
this.players = new HashMap<>();
} }
@PropertyName("id") @PropertyName("id")
@@ -118,19 +113,4 @@ public class Club implements Serializable {
this.president = president; this.president = president;
} }
@PropertyName("jogadores")
public HashMap<String, Player> getPlayersMap() {
return players;
}
@PropertyName("jogadores")
public void setPlayersMap(HashMap<String, Player> players) {
this.players = players;
}
public List<Player> getPlayersList() {
if (players == null)
return new ArrayList<>();
return new ArrayList<>(players.values());
}
} }

View File

@@ -10,13 +10,25 @@ public class Player implements Serializable {
@PropertyName("nome") @PropertyName("nome")
private String nome; private String nome;
@PropertyName("foto")
private String foto;
@PropertyName("data_nascimento")
private String dataNascimento;
@PropertyName("naturalidade")
private String naturalidade;
public Player() { public Player() {
// Default constructor required for calls to DataSnapshot.getValue(Player.class) // Default constructor required for calls to DataSnapshot.getValue(Player.class)
} }
public Player(int id, String nome) { public Player(int id, String nome, String foto, String dataNascimento, String naturalidade) {
this.id = id; this.id = id;
this.nome = nome; this.nome = nome;
this.foto = foto;
this.dataNascimento = dataNascimento;
this.naturalidade = naturalidade;
} }
@PropertyName("id") @PropertyName("id")
@@ -38,4 +50,34 @@ public class Player implements Serializable {
public void setNome(String nome) { public void setNome(String nome) {
this.nome = nome; this.nome = nome;
} }
@PropertyName("foto")
public String getFoto() {
return foto;
}
@PropertyName("foto")
public void setFoto(String foto) {
this.foto = foto;
}
@PropertyName("data_nascimento")
public String getDataNascimento() {
return dataNascimento;
}
@PropertyName("data_nascimento")
public void setDataNascimento(String dataNascimento) {
this.dataNascimento = dataNascimento;
}
@PropertyName("naturalidade")
public String getNaturalidade() {
return naturalidade;
}
@PropertyName("naturalidade")
public void setNaturalidade(String naturalidade) {
this.naturalidade = naturalidade;
}
} }

View File

@@ -55,7 +55,8 @@ public class ClubPlayersFragment extends Fragment {
binding.progressBarPlayers.setVisibility(View.VISIBLE); binding.progressBarPlayers.setVisibility(View.VISIBLE);
if (clubId != null && escalao != null) { if (clubId != null && escalao != null) {
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(escalao).child(clubId); mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(clubId).child("jogadores")
.child(escalao);
loadPlayers(); loadPlayers();
} else { } else {
binding.progressBarPlayers.setVisibility(View.GONE); binding.progressBarPlayers.setVisibility(View.GONE);
@@ -68,21 +69,25 @@ public class ClubPlayersFragment extends Fragment {
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() { mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override @Override
public void onDataChange(@NonNull DataSnapshot snapshot) { public void onDataChange(@NonNull DataSnapshot snapshot) {
Club club = snapshot.getValue(Club.class);
binding.progressBarPlayers.setVisibility(View.GONE); binding.progressBarPlayers.setVisibility(View.GONE);
if (club != null) { List<Player> playerList = new ArrayList<>();
List<Player> playerList = club.getPlayersList(); if (snapshot.exists()) {
if (playerList != null && !playerList.isEmpty()) { for (DataSnapshot playerSnapshot : snapshot.getChildren()) {
Player player = playerSnapshot.getValue(Player.class);
if (player != null) {
playerList.add(player);
}
}
}
if (!playerList.isEmpty()) {
PlayerAdapter adapter = new PlayerAdapter(playerList); PlayerAdapter adapter = new PlayerAdapter(playerList);
binding.recyclerPlayersList.setAdapter(adapter); binding.recyclerPlayersList.setAdapter(adapter);
binding.textNoPlayers.setVisibility(View.GONE); binding.textNoPlayers.setVisibility(View.GONE);
} else { } else {
binding.textNoPlayers.setVisibility(View.VISIBLE); binding.textNoPlayers.setVisibility(View.VISIBLE);
} }
} else {
binding.textNoPlayers.setVisibility(View.VISIBLE);
}
} }
@Override @Override

View File

@@ -63,7 +63,7 @@ public class ClubsFragment extends Fragment {
private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) { private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) {
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(currentEscalao); mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes");
// Remove previous listener to avoid duplicate data or leaks // Remove previous listener to avoid duplicate data or leaks
if (mValueEventListener != null) { if (mValueEventListener != null) {

View File

@@ -3,11 +3,14 @@ package com.example.vdcscore.ui.clubs;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.vdcscore.R; import com.example.vdcscore.R;
import com.example.vdcscore.models.Player; import com.example.vdcscore.models.Player;
@@ -42,15 +45,43 @@ public class PlayerAdapter extends RecyclerView.Adapter<PlayerAdapter.PlayerView
static class PlayerViewHolder extends RecyclerView.ViewHolder { static class PlayerViewHolder extends RecyclerView.ViewHolder {
private final TextView name; private final TextView name;
private final TextView details;
private final ImageView photo;
public PlayerViewHolder(@NonNull View itemView) { public PlayerViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
name = itemView.findViewById(R.id.text_player_name); name = itemView.findViewById(R.id.text_player_name);
details = itemView.findViewById(R.id.text_player_details);
photo = itemView.findViewById(R.id.image_player_icon);
} }
public void bind(Player player) { public void bind(Player player) {
if (player != null) { if (player != null) {
name.setText(player.getNome()); name.setText(player.getNome());
String detailsText = "";
if (player.getNaturalidade() != null && !player.getNaturalidade().isEmpty()) {
detailsText += player.getNaturalidade() + " ";
}
if (player.getDataNascimento() != null && !player.getDataNascimento().isEmpty()) {
detailsText += " | " + player.getDataNascimento();
}
if (details != null) {
details.setText(detailsText.trim().startsWith("|") ? detailsText.replaceFirst("\\|", "").trim()
: detailsText.trim());
}
if (player.getFoto() != null && !player.getFoto().isEmpty()) {
Glide.with(itemView.getContext())
.load(player.getFoto())
.circleCrop()
.placeholder(R.drawable.ic_menu_camera)
.error(R.drawable.ic_menu_camera)
.into(photo);
} else {
photo.setImageResource(R.drawable.ic_menu_camera);
}
} }
} }
} }

View File

@@ -8,18 +8,37 @@
<ImageView <ImageView
android:id="@+id/image_player_icon" android:id="@+id/image_player_icon"
android:layout_width="40dp" android:layout_width="48dp"
android:layout_height="40dp" android:layout_height="48dp"
android:src="@drawable/ic_menu_camera" android:src="@drawable/ic_menu_camera"
android:scaleType="centerCrop"
android:contentDescription="Player Icon" android:contentDescription="Player Icon"
android:layout_marginEnd="16dp"/> android:layout_marginEnd="16dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/text_player_name" android:id="@+id/text_player_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Player Name" android:text="Player Name"
android:textSize="16sp" android:textSize="16sp"
android:textColor="@color/black"
android:textStyle="bold" /> android:textStyle="bold" />
<TextView
android:id="@+id/text_player_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Details"
android:textSize="12sp"
android:textColor="#555555"
android:layout_marginTop="2dp" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -1,3 +1,4 @@
#Tue Mar 10 15:29:15 WET 2026
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip