This commit is contained in:
2026-03-11 10:16:43 +00:00
parent 4f90416cdb
commit 3c8d4217b0
3 changed files with 60 additions and 99 deletions

View File

@@ -61,7 +61,7 @@ public class HomeFragment extends Fragment {
} }
private void fetchStandings() { private void fetchStandings() {
mDatabase = FirebaseDatabase.getInstance().getReference("standings").child(currentEscalao); mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").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 // If ID is missing, set it from the key (although team_id comes from json usually)
if (team.getId() == null) { if (team.getTeam_id() == null) {
team.setId(postSnapshot.getKey()); team.setTeam_id(postSnapshot.getKey());
} }
teams.add(team); teams.add(team);
} }
} }
// Sort by Points (Descending), then Goal Difference, then Goals For // 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>() { Collections.sort(teams, new Comparator<Team>() {
@Override @Override
public int compare(Team t1, Team t2) { public int compare(Team t1, Team t2) {
if (t1.getPoints() != t2.getPoints()) { if (t1.getPontos() != t2.getPontos()) {
return t2.getPoints() - t1.getPoints(); // Descending points return t2.getPontos() - t1.getPontos(); // Descending points
} }
return t2.getGoalDifference() - t1.getGoalDifference(); // Descending GD return t2.getDiferenca_golos() - t1.getDiferenca_golos(); // Descending GD
} }
}); });

View File

@@ -13,6 +13,8 @@ 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;
@@ -55,13 +57,18 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
holder.textPosition.setTextColor(android.graphics.Color.BLACK); holder.textPosition.setTextColor(android.graphics.Color.BLACK);
} }
holder.textTeamName.setText(team.getName()); Glide.with(holder.itemView.getContext())
holder.textPlayed.setText(String.valueOf(team.getPlayed())); .load(team.getImagem())
holder.textWon.setText(String.valueOf(team.getWon())); .placeholder(R.mipmap.ic_launcher)
holder.textDrawn.setText(String.valueOf(team.getDrawn())); .into(holder.imageLogo);
holder.textLost.setText(String.valueOf(team.getLost()));
holder.textGoalDiff.setText(String.valueOf(team.getGoalDifference())); holder.textTeamName.setText(team.getNome());
holder.textPoints.setText(String.valueOf(team.getPoints())); holder.textPlayed.setText(String.valueOf(team.getJogos()));
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,106 +1,60 @@
package com.example.vdcscore.ui.home; package com.example.vdcscore.ui.home;
public class Team { public class Team {
private String id; private String team_id;
private String name; private String nome;
private int points; private int pontos;
private int played; private int jogos;
private int won; private int vitorias;
private int drawn; private int empates;
private int lost; private int derrotas;
private int goalsFor; private int golos_marcados;
private int goalsAgainst; private int golos_sofridos;
private int goalDifference; private int diferenca_golos;
private String imagem;
public Team() { public Team() {
// Required empty constructor for Firebase // Required empty constructor for Firebase
} }
public Team(String id, String name, int points, int played) { public Team(String team_id, String nome, int pontos, int jogos) {
this.id = id; this.team_id = team_id;
this.name = name; this.nome = nome;
this.points = points; this.pontos = pontos;
this.played = played; this.jogos = jogos;
} }
// Getters and Setters // Getters and Setters
public String getId() { public String getTeam_id() { return team_id; }
return id; public void setTeam_id(String team_id) { this.team_id = team_id; }
}
public void setId(String id) { public String getNome() { return nome; }
this.id = id; public void setNome(String nome) { this.nome = nome; }
}
public String getName() { public int getPontos() { return pontos; }
return name; public void setPontos(int pontos) { this.pontos = pontos; }
}
public void setName(String name) { public int getJogos() { return jogos; }
this.name = name; public void setJogos(int jogos) { this.jogos = jogos; }
}
public int getPoints() { public int getVitorias() { return vitorias; }
return points; public void setVitorias(int vitorias) { this.vitorias = vitorias; }
}
public void setPoints(int points) { public int getEmpates() { return empates; }
this.points = points; public void setEmpates(int empates) { this.empates = empates; }
}
public int getPlayed() { public int getDerrotas() { return derrotas; }
return played; public void setDerrotas(int derrotas) { this.derrotas = derrotas; }
}
public void setPlayed(int played) { public int getGolos_marcados() { return golos_marcados; }
this.played = played; public void setGolos_marcados(int golos_marcados) { this.golos_marcados = golos_marcados; }
}
public int getWon() { public int getGolos_sofridos() { return golos_sofridos; }
return won; public void setGolos_sofridos(int golos_sofridos) { this.golos_sofridos = golos_sofridos; }
}
public void setWon(int won) { public int getDiferenca_golos() { return diferenca_golos; }
this.won = won; public void setDiferenca_golos(int diferenca_golos) { this.diferenca_golos = diferenca_golos; }
}
public int getDrawn() { public String getImagem() { return imagem; }
return drawn; public void setImagem(String imagem) { this.imagem = imagem; }
}
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;
}
} }