From 1316a4623127907c4f68f7de81e814e5e8e07a98 Mon Sep 17 00:00:00 2001 From: Andre <230421@epvc.pt> Date: Tue, 17 Mar 2026 10:30:09 +0000 Subject: [PATCH] tabela --- .../vdcscore/ui/home/HomeFragment.java | 17 +- .../com/example/vdcscore/ui/home/Team.java | 171 ++++-------------- 2 files changed, 42 insertions(+), 146 deletions(-) diff --git a/app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java b/app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java index 9503b6b..72b12ce 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java @@ -73,15 +73,20 @@ public class HomeFragment extends Fragment { public void onDataChange(@NonNull DataSnapshot snapshot) { List teams = new ArrayList<>(); 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()); + try { + 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()); + } + 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 Collections.sort(teams, new Comparator() { diff --git a/app/src/main/java/com/example/vdcscore/ui/home/Team.java b/app/src/main/java/com/example/vdcscore/ui/home/Team.java index 4a329f7..296433a 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/Team.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/Team.java @@ -1,154 +1,45 @@ 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 { + @Exclude private String id; - @PropertyName("nome") - private String name; - - @PropertyName("pontos") - private int points; - - @PropertyName("jogos") - private int played; - - @PropertyName("vitorias") - 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; + // Nomes exatos dos nós na Base de Dados + public String nome; + public int pontos; + public int jogos; + public int empates; + public int derrotas; + public int diferenca_golos; + public int golos_marcados; + public int golos_sofridos; + public String imagem; public Team() { - // Required empty constructor for Firebase + // Necessário pelo Firebase } - // Getters and Setters - public String getId() { - return id; - } + // Apenas usados para consumo na UI, ignorados na leitura direta do Firebase + @Exclude public String getId() { return id; } + @Exclude public void setId(String id) { this.id = id; } - public void setId(String id) { - this.id = id; - } - - @PropertyName("nome") - public String getName() { - 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; + @Exclude public String getName() { return nome; } + @Exclude public int getPlayed() { return jogos; } + + @Exclude public int getWon() { + if (pontos > 0) return (pontos - empates) / 3; + return 0; } - @PropertyName("imagem") - public String getImageUrl() { - return imageUrl; - } - - @PropertyName("imagem") - public void setImageUrl(String imageUrl) { - this.imageUrl = imageUrl; - } + @Exclude public int getDrawn() { return empates; } + @Exclude public int getLost() { return derrotas; } + @Exclude public int getGoalDifference() { return diferenca_golos; } + @Exclude public int getGoalsFor() { return golos_marcados; } + @Exclude public int getGoalsAgainst() { return golos_sofridos; } + @Exclude public int getPoints() { return pontos; } + @Exclude public String getImageUrl() { return imagem; } }