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() {
mDatabase = FirebaseDatabase.getInstance().getReference("standings").child(currentEscalao);
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
// Remove previous listener to avoid duplicate data or leaks
if (mValueEventListener != null) {
@@ -75,22 +75,22 @@ public class HomeFragment extends Fragment {
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
Team team = postSnapshot.getValue(Team.class);
if (team != null) {
// If ID is missing, set it from the key
if (team.getId() == null) {
team.setId(postSnapshot.getKey());
// 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());
}
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>() {
@Override
public int compare(Team t1, Team t2) {
if (t1.getPoints() != t2.getPoints()) {
return t2.getPoints() - t1.getPoints(); // Descending points
if (t1.getPontos() != t2.getPontos()) {
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.List;
import com.bumptech.glide.Glide;
public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.ViewHolder> {
private List<Team> mTeams;
@@ -55,13 +57,18 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
holder.textPosition.setTextColor(android.graphics.Color.BLACK);
}
holder.textTeamName.setText(team.getName());
holder.textPlayed.setText(String.valueOf(team.getPlayed()));
holder.textWon.setText(String.valueOf(team.getWon()));
holder.textDrawn.setText(String.valueOf(team.getDrawn()));
holder.textLost.setText(String.valueOf(team.getLost()));
holder.textGoalDiff.setText(String.valueOf(team.getGoalDifference()));
holder.textPoints.setText(String.valueOf(team.getPoints()));
Glide.with(holder.itemView.getContext())
.load(team.getImagem())
.placeholder(R.mipmap.ic_launcher)
.into(holder.imageLogo);
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()));
holder.textLost.setText(String.valueOf(team.getDerrotas()));
holder.textGoalDiff.setText(String.valueOf(team.getDiferenca_golos()));
holder.textPoints.setText(String.valueOf(team.getPontos()));
}
@Override

View File

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