resolucao de erros
This commit is contained in:
@@ -61,45 +61,49 @@ public class HomeFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fetchStandings() {
|
private void fetchStandings() {
|
||||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
// Remove previous listener from previous database path
|
||||||
|
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()) {
|
||||||
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 (although team_id comes from json usually)
|
if (team != null) {
|
||||||
if (team.getTeam_id() == null) {
|
if (team.getTeam_id() == null) {
|
||||||
team.setTeam_id(postSnapshot.getKey());
|
team.setTeam_id(postSnapshot.getKey());
|
||||||
|
}
|
||||||
|
teams.add(team);
|
||||||
}
|
}
|
||||||
teams.add(team);
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort properly (JSON might already be sorted by "posicao", but we sort by points and GD just in case)
|
// Sort properly
|
||||||
Collections.sort(teams, new Comparator<Team>() {
|
Collections.sort(teams, (t1, t2) -> {
|
||||||
@Override
|
if (t1.getPontos() != t2.getPontos()) {
|
||||||
public int compare(Team t1, Team t2) {
|
return t2.getPontos() - t1.getPontos();
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
|
||||||
adapter.setTeams(teams);
|
if (adapter != null) {
|
||||||
|
adapter.setTeams(teams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
if (getContext() != null) {
|
if (getContext() != null && binding != 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,6 +39,7 @@ 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));
|
||||||
@@ -57,12 +58,14 @@ 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(team.getImagem())
|
.load(imageUrl != null ? imageUrl : "")
|
||||||
.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());
|
holder.textTeamName.setText(team.getNome() != null ? 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()));
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingVertical="8dp"
|
android:paddingVertical="10dp"
|
||||||
android:paddingHorizontal="8dp"
|
android:paddingHorizontal="8dp"
|
||||||
android:background="@drawable/bg_table_header">
|
android:background="@drawable/bg_table_header">
|
||||||
|
|
||||||
@@ -56,10 +56,10 @@
|
|||||||
android:layout_width="28dp"
|
android:layout_width="28dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="POS"
|
android:text="#"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
android:layout_width="28dp"
|
android:layout_width="28dp"
|
||||||
@@ -71,8 +71,8 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="EQUIPA"
|
android:text="EQUIPA"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
@@ -80,8 +80,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="J"
|
android:text="J"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
@@ -89,8 +89,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="V"
|
android:text="V"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
@@ -98,8 +98,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="E"
|
android:text="E"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
@@ -107,8 +107,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="D"
|
android:text="D"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="26dp"
|
android:layout_width="26dp"
|
||||||
@@ -116,8 +116,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="DG"
|
android:text="DG"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
@@ -125,8 +125,8 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="PTS"
|
android:text="PTS"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="10sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="normal" />
|
android:textStyle="bold" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingVertical="12dp"
|
android:paddingVertical="10dp"
|
||||||
android:paddingHorizontal="8dp"
|
android:paddingHorizontal="8dp"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:background="?attr/selectableItemBackground">
|
android:background="?attr/selectableItemBackground">
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="1"
|
android:text="1"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="12sp"
|
android:textSize="11sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:background="@drawable/bg_circle_green" />
|
android:background="@drawable/bg_circle_green" />
|
||||||
|
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_marginHorizontal="2dp"
|
android:layout_marginHorizontal="2dp"
|
||||||
|
android:scaleType="centerInside"
|
||||||
android:src="@mipmap/ic_launcher" />
|
android:src="@mipmap/ic_launcher" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -37,7 +38,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="Team Name"
|
android:text="Team Name"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/text_primary"
|
||||||
android:textSize="13sp"
|
android:textSize="13sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -58,7 +59,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -67,7 +68,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -85,7 +86,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textColor="@color/text_primary"
|
android:textColor="@color/text_secondary"
|
||||||
android:textSize="12sp" />
|
android:textSize="12sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:text="0"
|
android:text="0"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/text_primary"
|
||||||
android:textSize="13sp" />
|
android:textSize="13sp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user