From acac87d95dad1ddc041c0de4b48e1c01de53d2a2 Mon Sep 17 00:00:00 2001 From: 230421 <230421@epvc.pt> Date: Wed, 11 Mar 2026 10:26:47 +0000 Subject: [PATCH 1/5] . --- .../vdcscore/ui/home/HomeFragment.java | 16 +-- .../vdcscore/ui/home/StandingsAdapter.java | 21 +-- .../com/example/vdcscore/ui/home/Team.java | 122 ++++++++++++------ 3 files changed, 99 insertions(+), 60 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 563130b..0302c59 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 @@ -61,7 +61,7 @@ public class HomeFragment extends Fragment { } 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 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 (although team_id comes from json usually) - if (team.getTeam_id() == null) { - team.setTeam_id(postSnapshot.getKey()); + // If ID is missing, set it from the key + if (team.getId() == null) { + team.setId(postSnapshot.getKey()); } 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() { @Override public int compare(Team t1, Team t2) { - if (t1.getPontos() != t2.getPontos()) { - return t2.getPontos() - t1.getPontos(); // Descending points + if (t1.getPoints() != t2.getPoints()) { + return t2.getPoints() - t1.getPoints(); // Descending points } - return t2.getDiferenca_golos() - t1.getDiferenca_golos(); // Descending GD + return t2.getGoalDifference() - t1.getGoalDifference(); // Descending GD } }); diff --git a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java index 4075ae1..287f797 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java @@ -13,8 +13,6 @@ import com.example.vdcscore.R; import java.util.ArrayList; import java.util.List; -import com.bumptech.glide.Glide; - public class StandingsAdapter extends RecyclerView.Adapter { private List mTeams; @@ -57,18 +55,13 @@ public class StandingsAdapter extends RecyclerView.Adapter Date: Tue, 17 Mar 2026 10:24:41 +0000 Subject: [PATCH 2/5] tabela --- .../vdcscore/ui/home/HomeFragment.java | 2 +- .../vdcscore/ui/home/StandingsAdapter.java | 11 ++++ .../com/example/vdcscore/ui/home/Team.java | 62 ++++++++++++++++--- 3 files changed, 67 insertions(+), 8 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 0302c59..9503b6b 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 @@ -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) { diff --git a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java index 287f797..bbb9f98 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java @@ -56,6 +56,17 @@ public class StandingsAdapter extends RecyclerView.Adapter 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") + public String getImageUrl() { + return imageUrl; + } + + @PropertyName("imagem") + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } } 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 3/5] 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; } } From 91fde336b3a87438be375c214fd4ed2ebd5244a9 Mon Sep 17 00:00:00 2001 From: 230421 <230421@epvc.pt> Date: Tue, 17 Mar 2026 15:36:54 +0000 Subject: [PATCH 4/5] . --- .idea/deploymentTargetSelector.xml | 1 + .../vdcscore/ui/home/StandingsAdapter.java | 11 ++ .../com/example/vdcscore/ui/home/Team.java | 131 +++++++++++++----- 3 files changed, 108 insertions(+), 35 deletions(-) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..ca16a99 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,6 +4,7 @@ diff --git a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java index bbb9f98..ea01c5f 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java @@ -9,6 +9,7 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.example.vdcscore.R; +import com.bumptech.glide.Glide; import java.util.ArrayList; import java.util.List; @@ -73,6 +74,16 @@ public class StandingsAdapter extends RecyclerView.Adapter 0) return (pontos - empates) / 3; - return 0; + public Team(String id, String name, int points, int played) { + this.id = id; + this.name = name; + this.points = points; + this.played = played; + } + + // Getters and Setters + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public int getPlayed() { + return played; + } + + public void setPlayed(int played) { + this.played = played; + } + + public int getWon() { + return won; + } + + public void setWon(int won) { + this.won = won; + } + + 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; } - - @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; } } From 0fbbd77f9f387867be10a00ae9a2be1b2831ddee Mon Sep 17 00:00:00 2001 From: 230421 <230421@epvc.pt> Date: Tue, 17 Mar 2026 15:39:49 +0000 Subject: [PATCH 5/5] resolucao de uns erros --- .../com/example/vdcscore/ui/home/StandingsAdapter.java | 10 ---------- .../main/java/com/example/vdcscore/ui/home/Team.java | 9 +++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java index ea01c5f..06fcf51 100644 --- a/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java +++ b/app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java @@ -74,16 +74,6 @@ public class StandingsAdapter extends RecyclerView.Adapter