Merge remote-tracking branch 'origin/main'

# Conflicts:
#	app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java
#	app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java
This commit is contained in:
2026-03-17 16:52:45 +00:00
4 changed files with 116 additions and 67 deletions

View File

@@ -4,6 +4,7 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DialogSelection />
</SelectionState>
</selectionStates>
</component>

View File

@@ -61,49 +61,45 @@ public class HomeFragment extends Fragment {
}
private void fetchStandings() {
// Remove previous listener from previous database path
if (mDatabase != null && mValueEventListener != null) {
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
// Remove previous listener to avoid duplicate data or leaks
if (mValueEventListener != null) {
mDatabase.removeEventListener(mValueEventListener);
}
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (binding == null) return;
List<Team> teams = new ArrayList<>();
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
try {
Team team = postSnapshot.getValue(Team.class);
if (team != null) {
if (team.getTeam_id() == null) {
team.setTeam_id(postSnapshot.getKey());
}
teams.add(team);
Team team = postSnapshot.getValue(Team.class);
if (team != null) {
// If ID is missing, set it from the key (although team_id comes from json usually)
if (team.getTeam_id() == null) {
team.setTeam_id(postSnapshot.getKey());
}
} catch (Exception e) {
e.printStackTrace();
teams.add(team);
}
}
// Sort properly
Collections.sort(teams, (t1, t2) -> {
if (t1.getPontos() != t2.getPontos()) {
return t2.getPontos() - t1.getPontos();
// Sort properly (JSON might already be sorted by "posicao", but we sort by points and GD just in case)
Collections.sort(teams, new Comparator<Team>() {
@Override
public int compare(Team t1, Team t2) {
if (t1.getPontos() != t2.getPontos()) {
return t2.getPontos() - t1.getPontos(); // Descending points
}
return t2.getDiferenca_golos() - t1.getDiferenca_golos(); // Descending GD
}
return t2.getDiferenca_golos() - t1.getDiferenca_golos();
});
if (adapter != null) {
adapter.setTeams(teams);
}
adapter.setTeams(teams);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
if (getContext() != null && binding != null) {
if (getContext() != null) {
Toast.makeText(getContext(), "Erro ao carregar classificação: " + error.getMessage(),
Toast.LENGTH_SHORT).show();
}

View File

@@ -39,7 +39,6 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Team team = mTeams.get(position);
if (team == null) return;
int rank = position + 1;
holder.textPosition.setText(String.valueOf(rank));
@@ -58,14 +57,12 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
holder.textPosition.setTextColor(android.graphics.Color.BLACK);
}
String imageUrl = team.getImagem();
Glide.with(holder.itemView.getContext())
.load(imageUrl != null ? imageUrl : "")
.load(team.getImagem())
.placeholder(R.mipmap.ic_launcher)
.error(R.mipmap.ic_launcher)
.into(holder.imageLogo);
holder.textTeamName.setText(team.getNome() != null ? team.getNome() : "---");
holder.textTeamName.setText(team.getNome());
holder.textPlayed.setText(String.valueOf(team.getJogos()));
holder.textWon.setText(String.valueOf(team.getVitorias()));
holder.textDrawn.setText(String.valueOf(team.getEmpates()));

View File

@@ -1,60 +1,115 @@
package com.example.vdcscore.ui.home;
public class Team {
private String team_id;
private String nome;
private int pontos;
private int jogos;
private int vitorias;
private int empates;
private int derrotas;
private int golos_marcados;
private int golos_sofridos;
private int diferenca_golos;
private String imagem;
private String id;
private String name;
private int points;
private int played;
private int won;
private int drawn;
private int lost;
private int goalsFor;
private int goalsAgainst;
private int goalDifference;
private String imageUrl;
public Team() {
// Required empty constructor for Firebase
}
public Team(String team_id, String nome, int pontos, int jogos) {
this.team_id = team_id;
this.nome = nome;
this.pontos = pontos;
this.jogos = jogos;
public Team(String id, String name, int points, int played) {
this.id = id;
this.name = name;
this.points = points;
this.played = played;
}
// Getters and Setters
public String getTeam_id() { return team_id; }
public void setTeam_id(String team_id) { this.team_id = team_id; }
public String getId() {
return id;
}
public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }
public void setId(String id) {
this.id = id;
}
public int getPontos() { return pontos; }
public void setPontos(int pontos) { this.pontos = pontos; }
public String getName() {
return name;
}
public int getJogos() { return jogos; }
public void setJogos(int jogos) { this.jogos = jogos; }
public void setName(String name) {
this.name = name;
}
public int getVitorias() { return vitorias; }
public void setVitorias(int vitorias) { this.vitorias = vitorias; }
public int getPoints() {
return points;
}
public int getEmpates() { return empates; }
public void setEmpates(int empates) { this.empates = empates; }
public void setPoints(int points) {
this.points = points;
}
public int getDerrotas() { return derrotas; }
public void setDerrotas(int derrotas) { this.derrotas = derrotas; }
public int getPlayed() {
return played;
}
public int getGolos_marcados() { return golos_marcados; }
public void setGolos_marcados(int golos_marcados) { this.golos_marcados = golos_marcados; }
public void setPlayed(int played) {
this.played = played;
}
public int getGolos_sofridos() { return golos_sofridos; }
public void setGolos_sofridos(int golos_sofridos) { this.golos_sofridos = golos_sofridos; }
public int getWon() {
return won;
}
public int getDiferenca_golos() { return diferenca_golos; }
public void setDiferenca_golos(int diferenca_golos) { this.diferenca_golos = diferenca_golos; }
public void setWon(int won) {
this.won = won;
}
public String getImagem() { return imagem; }
public void setImagem(String imagem) { this.imagem = imagem; }
public int getDrawn() {
return drawn;
}
public void setDrawn(int drawn) {
this.drawn = drawn;
}
public int getLost() {
return lost;
}
public void setLost(int lost) {
this.lost = lost;
}
public int getGoalsFor() {
return goalsFor;
}
public void setGoalsFor(int goalsFor) {
this.goalsFor = goalsFor;
}
public int getGoalsAgainst() {
return goalsAgainst;
}
public void setGoalsAgainst(int goalsAgainst) {
this.goalsAgainst = goalsAgainst;
}
public int getGoalDifference() {
return goalDifference;
}
public void setGoalDifference(int goalDifference) {
this.goalDifference = goalDifference;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
}