tabela
This commit is contained in:
@@ -73,15 +73,20 @@ public class HomeFragment extends Fragment {
|
|||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
List<Team> teams = new ArrayList<>();
|
List<Team> teams = new ArrayList<>();
|
||||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
Team team = postSnapshot.getValue(Team.class);
|
try {
|
||||||
if (team != null) {
|
Team team = postSnapshot.getValue(Team.class);
|
||||||
// If ID is missing, set it from the key
|
if (team != null) {
|
||||||
if (team.getId() == null) {
|
// If ID is missing, set it from the key
|
||||||
team.setId(postSnapshot.getKey());
|
if (team.getId() == null) {
|
||||||
|
team.setId(postSnapshot.getKey());
|
||||||
|
}
|
||||||
|
teams.add(team);
|
||||||
}
|
}
|
||||||
teams.add(team);
|
} catch (Exception e) {
|
||||||
|
android.util.Log.e("HomeFragment", "Error mapping Team: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
android.util.Log.d("HomeFragment", "Fetched " + teams.size() + " teams for escalao: " + currentEscalao);
|
||||||
|
|
||||||
// Sort by Points (Descending), then Goal Difference, then Goals For
|
// Sort by Points (Descending), then Goal Difference, then Goals For
|
||||||
Collections.sort(teams, new Comparator<Team>() {
|
Collections.sort(teams, new Comparator<Team>() {
|
||||||
|
|||||||
@@ -1,154 +1,45 @@
|
|||||||
package com.example.vdcscore.ui.home;
|
package com.example.vdcscore.ui.home;
|
||||||
|
|
||||||
import com.google.firebase.database.PropertyName;
|
import com.google.firebase.database.Exclude;
|
||||||
|
import com.google.firebase.database.IgnoreExtraProperties;
|
||||||
|
|
||||||
|
@IgnoreExtraProperties
|
||||||
public class Team {
|
public class Team {
|
||||||
|
@Exclude
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
@PropertyName("nome")
|
// Nomes exatos dos nós na Base de Dados
|
||||||
private String name;
|
public String nome;
|
||||||
|
public int pontos;
|
||||||
@PropertyName("pontos")
|
public int jogos;
|
||||||
private int points;
|
public int empates;
|
||||||
|
public int derrotas;
|
||||||
@PropertyName("jogos")
|
public int diferenca_golos;
|
||||||
private int played;
|
public int golos_marcados;
|
||||||
|
public int golos_sofridos;
|
||||||
@PropertyName("vitorias")
|
public String imagem;
|
||||||
private int won;
|
|
||||||
|
|
||||||
@PropertyName("empates")
|
|
||||||
private int drawn;
|
|
||||||
|
|
||||||
@PropertyName("derrotas")
|
|
||||||
private int lost;
|
|
||||||
|
|
||||||
@PropertyName("golos_marcados")
|
|
||||||
private int goalsFor;
|
|
||||||
|
|
||||||
@PropertyName("golos_sofridos")
|
|
||||||
private int goalsAgainst;
|
|
||||||
|
|
||||||
@PropertyName("diferenca_golos")
|
|
||||||
private int goalDifference;
|
|
||||||
|
|
||||||
@PropertyName("imagem")
|
|
||||||
private String imageUrl;
|
|
||||||
|
|
||||||
public Team() {
|
public Team() {
|
||||||
// Required empty constructor for Firebase
|
// Necessário pelo Firebase
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
// Apenas usados para consumo na UI, ignorados na leitura direta do Firebase
|
||||||
public String getId() {
|
@Exclude public String getId() { return id; }
|
||||||
return id;
|
@Exclude public void setId(String id) { this.id = id; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
@Exclude public String getName() { return nome; }
|
||||||
this.id = id;
|
@Exclude public int getPlayed() { return jogos; }
|
||||||
}
|
|
||||||
|
@Exclude public int getWon() {
|
||||||
@PropertyName("nome")
|
if (pontos > 0) return (pontos - empates) / 3;
|
||||||
public String getName() {
|
return 0;
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("nome")
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("pontos")
|
|
||||||
public int getPoints() {
|
|
||||||
return points;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("pontos")
|
|
||||||
public void setPoints(int points) {
|
|
||||||
this.points = points;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("jogos")
|
|
||||||
public int getPlayed() {
|
|
||||||
return played;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("jogos")
|
|
||||||
public void setPlayed(int played) {
|
|
||||||
this.played = played;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("vitorias")
|
|
||||||
public int getWon() {
|
|
||||||
// Fallback calculation in case "vitorias" field is not explicit in DB
|
|
||||||
if (won == 0 && points > 0) {
|
|
||||||
return (points - drawn) / 3;
|
|
||||||
}
|
|
||||||
return won;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("vitorias")
|
|
||||||
public void setWon(int won) {
|
|
||||||
this.won = won;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("empates")
|
|
||||||
public int getDrawn() {
|
|
||||||
return drawn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("empates")
|
|
||||||
public void setDrawn(int drawn) {
|
|
||||||
this.drawn = drawn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("derrotas")
|
|
||||||
public int getLost() {
|
|
||||||
return lost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("derrotas")
|
|
||||||
public void setLost(int lost) {
|
|
||||||
this.lost = lost;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("golos_marcados")
|
|
||||||
public int getGoalsFor() {
|
|
||||||
return goalsFor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("golos_marcados")
|
|
||||||
public void setGoalsFor(int goalsFor) {
|
|
||||||
this.goalsFor = goalsFor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("golos_sofridos")
|
|
||||||
public int getGoalsAgainst() {
|
|
||||||
return goalsAgainst;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("golos_sofridos")
|
|
||||||
public void setGoalsAgainst(int goalsAgainst) {
|
|
||||||
this.goalsAgainst = goalsAgainst;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("diferenca_golos")
|
|
||||||
public int getGoalDifference() {
|
|
||||||
return goalDifference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PropertyName("diferenca_golos")
|
|
||||||
public void setGoalDifference(int goalDifference) {
|
|
||||||
this.goalDifference = goalDifference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PropertyName("imagem")
|
@Exclude public int getDrawn() { return empates; }
|
||||||
public String getImageUrl() {
|
@Exclude public int getLost() { return derrotas; }
|
||||||
return imageUrl;
|
@Exclude public int getGoalDifference() { return diferenca_golos; }
|
||||||
}
|
@Exclude public int getGoalsFor() { return golos_marcados; }
|
||||||
|
@Exclude public int getGoalsAgainst() { return golos_sofridos; }
|
||||||
@PropertyName("imagem")
|
@Exclude public int getPoints() { return pontos; }
|
||||||
public void setImageUrl(String imageUrl) {
|
@Exclude public String getImageUrl() { return imagem; }
|
||||||
this.imageUrl = imageUrl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user