This commit is contained in:
2026-03-11 10:26:47 +00:00
parent 3c8d4217b0
commit acac87d95d
3 changed files with 99 additions and 60 deletions

View File

@@ -61,7 +61,7 @@ public class HomeFragment extends Fragment {
} }
private void fetchStandings() { private void fetchStandings() {
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao); mDatabase = FirebaseDatabase.getInstance().getReference("standings").child(currentEscalao);
// Remove previous listener to avoid duplicate data or leaks // Remove previous listener to avoid duplicate data or leaks
if (mValueEventListener != null) { if (mValueEventListener != null) {
@@ -75,22 +75,22 @@ public class HomeFragment extends Fragment {
for (DataSnapshot postSnapshot : snapshot.getChildren()) { for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Team team = postSnapshot.getValue(Team.class); Team team = postSnapshot.getValue(Team.class);
if (team != null) { if (team != null) {
// If ID is missing, set it from the key (although team_id comes from json usually) // If ID is missing, set it from the key
if (team.getTeam_id() == null) { if (team.getId() == null) {
team.setTeam_id(postSnapshot.getKey()); team.setId(postSnapshot.getKey());
} }
teams.add(team); teams.add(team);
} }
} }
// Sort properly (JSON might already be sorted by "posicao", but we sort by points and GD just in case) // Sort by Points (Descending), then Goal Difference, then Goals For
Collections.sort(teams, new Comparator<Team>() { Collections.sort(teams, new Comparator<Team>() {
@Override @Override
public int compare(Team t1, Team t2) { public int compare(Team t1, Team t2) {
if (t1.getPontos() != t2.getPontos()) { if (t1.getPoints() != t2.getPoints()) {
return t2.getPontos() - t1.getPontos(); // Descending points return t2.getPoints() - t1.getPoints(); // Descending points
} }
return t2.getDiferenca_golos() - t1.getDiferenca_golos(); // Descending GD return t2.getGoalDifference() - t1.getGoalDifference(); // Descending GD
} }
}); });

View File

@@ -13,8 +13,6 @@ import com.example.vdcscore.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.bumptech.glide.Glide;
public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.ViewHolder> { public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.ViewHolder> {
private List<Team> mTeams; private List<Team> mTeams;
@@ -57,18 +55,13 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
holder.textPosition.setTextColor(android.graphics.Color.BLACK); holder.textPosition.setTextColor(android.graphics.Color.BLACK);
} }
Glide.with(holder.itemView.getContext()) holder.textTeamName.setText(team.getName());
.load(team.getImagem()) holder.textPlayed.setText(String.valueOf(team.getPlayed()));
.placeholder(R.mipmap.ic_launcher) holder.textWon.setText(String.valueOf(team.getWon()));
.into(holder.imageLogo); holder.textDrawn.setText(String.valueOf(team.getDrawn()));
holder.textLost.setText(String.valueOf(team.getLost()));
holder.textTeamName.setText(team.getNome()); holder.textGoalDiff.setText(String.valueOf(team.getGoalDifference()));
holder.textPlayed.setText(String.valueOf(team.getJogos())); holder.textPoints.setText(String.valueOf(team.getPoints()));
holder.textWon.setText(String.valueOf(team.getVitorias()));
holder.textDrawn.setText(String.valueOf(team.getEmpates()));
holder.textLost.setText(String.valueOf(team.getDerrotas()));
holder.textGoalDiff.setText(String.valueOf(team.getDiferenca_golos()));
holder.textPoints.setText(String.valueOf(team.getPontos()));
} }
@Override @Override

View File

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