Merge remote-tracking branch 'origin/main'
# Conflicts: # app/src/main/java/com/example/vdcscore/ui/home/HomeFragment.java # app/src/main/java/com/example/vdcscore/ui/home/StandingsAdapter.java
This commit is contained in:
1
.idea/deploymentTargetSelector.xml
generated
1
.idea/deploymentTargetSelector.xml
generated
@@ -4,6 +4,7 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DialogSelection />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -61,49 +61,45 @@ public class HomeFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fetchStandings() {
|
private void fetchStandings() {
|
||||||
// Remove previous listener from previous database path
|
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
||||||
if (mDatabase != null && mValueEventListener != null) {
|
|
||||||
|
// Remove previous listener to avoid duplicate data or leaks
|
||||||
|
if (mValueEventListener != null) {
|
||||||
mDatabase.removeEventListener(mValueEventListener);
|
mDatabase.removeEventListener(mValueEventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
|
||||||
|
|
||||||
mValueEventListener = new ValueEventListener() {
|
mValueEventListener = new ValueEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
if (binding == null) return;
|
|
||||||
|
|
||||||
List<Team> teams = new ArrayList<>();
|
List<Team> teams = new ArrayList<>();
|
||||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
try {
|
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 (although team_id comes from json usually)
|
||||||
if (team.getTeam_id() == null) {
|
if (team.getTeam_id() == null) {
|
||||||
team.setTeam_id(postSnapshot.getKey());
|
team.setTeam_id(postSnapshot.getKey());
|
||||||
}
|
|
||||||
teams.add(team);
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
teams.add(team);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort properly
|
// Sort properly (JSON might already be sorted by "posicao", but we sort by points and GD just in case)
|
||||||
Collections.sort(teams, (t1, t2) -> {
|
Collections.sort(teams, new Comparator<Team>() {
|
||||||
if (t1.getPontos() != t2.getPontos()) {
|
@Override
|
||||||
return t2.getPontos() - t1.getPontos();
|
public int compare(Team t1, Team t2) {
|
||||||
|
if (t1.getPontos() != t2.getPontos()) {
|
||||||
|
return t2.getPontos() - t1.getPontos(); // Descending points
|
||||||
|
}
|
||||||
|
return t2.getDiferenca_golos() - t1.getDiferenca_golos(); // Descending GD
|
||||||
}
|
}
|
||||||
return t2.getDiferenca_golos() - t1.getDiferenca_golos();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (adapter != null) {
|
adapter.setTeams(teams);
|
||||||
adapter.setTeams(teams);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
if (getContext() != null && binding != null) {
|
if (getContext() != null) {
|
||||||
Toast.makeText(getContext(), "Erro ao carregar classificação: " + error.getMessage(),
|
Toast.makeText(getContext(), "Erro ao carregar classificação: " + error.getMessage(),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
Team team = mTeams.get(position);
|
Team team = mTeams.get(position);
|
||||||
if (team == null) return;
|
|
||||||
|
|
||||||
int rank = position + 1;
|
int rank = position + 1;
|
||||||
holder.textPosition.setText(String.valueOf(rank));
|
holder.textPosition.setText(String.valueOf(rank));
|
||||||
@@ -58,14 +57,12 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
|
|||||||
holder.textPosition.setTextColor(android.graphics.Color.BLACK);
|
holder.textPosition.setTextColor(android.graphics.Color.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
String imageUrl = team.getImagem();
|
|
||||||
Glide.with(holder.itemView.getContext())
|
Glide.with(holder.itemView.getContext())
|
||||||
.load(imageUrl != null ? imageUrl : "")
|
.load(team.getImagem())
|
||||||
.placeholder(R.mipmap.ic_launcher)
|
.placeholder(R.mipmap.ic_launcher)
|
||||||
.error(R.mipmap.ic_launcher)
|
|
||||||
.into(holder.imageLogo);
|
.into(holder.imageLogo);
|
||||||
|
|
||||||
holder.textTeamName.setText(team.getNome() != null ? team.getNome() : "---");
|
holder.textTeamName.setText(team.getNome());
|
||||||
holder.textPlayed.setText(String.valueOf(team.getJogos()));
|
holder.textPlayed.setText(String.valueOf(team.getJogos()));
|
||||||
holder.textWon.setText(String.valueOf(team.getVitorias()));
|
holder.textWon.setText(String.valueOf(team.getVitorias()));
|
||||||
holder.textDrawn.setText(String.valueOf(team.getEmpates()));
|
holder.textDrawn.setText(String.valueOf(team.getEmpates()));
|
||||||
|
|||||||
@@ -1,60 +1,115 @@
|
|||||||
package com.example.vdcscore.ui.home;
|
package com.example.vdcscore.ui.home;
|
||||||
|
|
||||||
public class Team {
|
public class Team {
|
||||||
private String team_id;
|
private String id;
|
||||||
private String nome;
|
private String name;
|
||||||
private int pontos;
|
private int points;
|
||||||
private int jogos;
|
private int played;
|
||||||
private int vitorias;
|
private int won;
|
||||||
private int empates;
|
private int drawn;
|
||||||
private int derrotas;
|
private int lost;
|
||||||
private int golos_marcados;
|
private int goalsFor;
|
||||||
private int golos_sofridos;
|
private int goalsAgainst;
|
||||||
private int diferenca_golos;
|
private int goalDifference;
|
||||||
private String imagem;
|
private String imageUrl;
|
||||||
|
|
||||||
public Team() {
|
public Team() {
|
||||||
// Required empty constructor for Firebase
|
// Required empty constructor for Firebase
|
||||||
}
|
}
|
||||||
|
|
||||||
public Team(String team_id, String nome, int pontos, int jogos) {
|
public Team(String id, String name, int points, int played) {
|
||||||
this.team_id = team_id;
|
this.id = id;
|
||||||
this.nome = nome;
|
this.name = name;
|
||||||
this.pontos = pontos;
|
this.points = points;
|
||||||
this.jogos = jogos;
|
this.played = played;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
// Getters and Setters
|
||||||
public String getTeam_id() { return team_id; }
|
public String getId() {
|
||||||
public void setTeam_id(String team_id) { this.team_id = team_id; }
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNome() { return nome; }
|
public void setId(String id) {
|
||||||
public void setNome(String nome) { this.nome = nome; }
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public int getPontos() { return pontos; }
|
public String getName() {
|
||||||
public void setPontos(int pontos) { this.pontos = pontos; }
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
public int getJogos() { return jogos; }
|
public void setName(String name) {
|
||||||
public void setJogos(int jogos) { this.jogos = jogos; }
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public int getVitorias() { return vitorias; }
|
public int getPoints() {
|
||||||
public void setVitorias(int vitorias) { this.vitorias = vitorias; }
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
public int getEmpates() { return empates; }
|
public void setPoints(int points) {
|
||||||
public void setEmpates(int empates) { this.empates = empates; }
|
this.points = points;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDerrotas() { return derrotas; }
|
public int getPlayed() {
|
||||||
public void setDerrotas(int derrotas) { this.derrotas = derrotas; }
|
return played;
|
||||||
|
}
|
||||||
|
|
||||||
public int getGolos_marcados() { return golos_marcados; }
|
public void setPlayed(int played) {
|
||||||
public void setGolos_marcados(int golos_marcados) { this.golos_marcados = golos_marcados; }
|
this.played = played;
|
||||||
|
}
|
||||||
|
|
||||||
public int getGolos_sofridos() { return golos_sofridos; }
|
public int getWon() {
|
||||||
public void setGolos_sofridos(int golos_sofridos) { this.golos_sofridos = golos_sofridos; }
|
return won;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDiferenca_golos() { return diferenca_golos; }
|
public void setWon(int won) {
|
||||||
public void setDiferenca_golos(int diferenca_golos) { this.diferenca_golos = diferenca_golos; }
|
this.won = won;
|
||||||
|
}
|
||||||
|
|
||||||
public String getImagem() { return imagem; }
|
public int getDrawn() {
|
||||||
public void setImagem(String imagem) { this.imagem = imagem; }
|
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 getImageUrl() {
|
||||||
|
return imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageUrl(String imageUrl) {
|
||||||
|
this.imageUrl = imageUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user