resolucao de erros
This commit is contained in:
@@ -61,45 +61,49 @@ public class HomeFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void fetchStandings() {
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
||||
|
||||
// Remove previous listener to avoid duplicate data or leaks
|
||||
if (mValueEventListener != null) {
|
||||
// Remove previous listener from previous database path
|
||||
if (mDatabase != null && mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
||||
|
||||
mValueEventListener = new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
if (binding == null) return;
|
||||
|
||||
List<Team> 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 (although team_id comes from json usually)
|
||||
if (team.getTeam_id() == null) {
|
||||
team.setTeam_id(postSnapshot.getKey());
|
||||
try {
|
||||
Team team = postSnapshot.getValue(Team.class);
|
||||
if (team != null) {
|
||||
if (team.getTeam_id() == null) {
|
||||
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)
|
||||
Collections.sort(teams, new Comparator<Team>() {
|
||||
@Override
|
||||
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
|
||||
// Sort properly
|
||||
Collections.sort(teams, (t1, t2) -> {
|
||||
if (t1.getPontos() != t2.getPontos()) {
|
||||
return t2.getPontos() - t1.getPontos();
|
||||
}
|
||||
return t2.getDiferenca_golos() - t1.getDiferenca_golos();
|
||||
});
|
||||
|
||||
adapter.setTeams(teams);
|
||||
if (adapter != null) {
|
||||
adapter.setTeams(teams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Team team = mTeams.get(position);
|
||||
if (team == null) return;
|
||||
|
||||
int rank = position + 1;
|
||||
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);
|
||||
}
|
||||
|
||||
String imageUrl = team.getImagem();
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.load(team.getImagem())
|
||||
.load(imageUrl != null ? imageUrl : "")
|
||||
.placeholder(R.mipmap.ic_launcher)
|
||||
.error(R.mipmap.ic_launcher)
|
||||
.into(holder.imageLogo);
|
||||
|
||||
holder.textTeamName.setText(team.getNome());
|
||||
holder.textTeamName.setText(team.getNome() != null ? team.getNome() : "---");
|
||||
holder.textPlayed.setText(String.valueOf(team.getJogos()));
|
||||
holder.textWon.setText(String.valueOf(team.getVitorias()));
|
||||
holder.textDrawn.setText(String.valueOf(team.getEmpates()));
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="8dp"
|
||||
android:paddingVertical="10dp"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:background="@drawable/bg_table_header">
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="POS"
|
||||
android:text="#"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Space
|
||||
android:layout_width="28dp"
|
||||
@@ -71,8 +71,8 @@
|
||||
android:layout_weight="1"
|
||||
android:text="EQUIPA"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -80,8 +80,8 @@
|
||||
android:gravity="center"
|
||||
android:text="J"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -89,8 +89,8 @@
|
||||
android:gravity="center"
|
||||
android:text="V"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -98,8 +98,8 @@
|
||||
android:gravity="center"
|
||||
android:text="E"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -107,8 +107,8 @@
|
||||
android:gravity="center"
|
||||
android:text="D"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="26dp"
|
||||
@@ -116,8 +116,8 @@
|
||||
android:gravity="center"
|
||||
android:text="DG"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="32dp"
|
||||
@@ -125,8 +125,8 @@
|
||||
android:gravity="center"
|
||||
android:text="PTS"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="12dp"
|
||||
android:paddingVertical="10dp"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
@@ -20,7 +20,7 @@
|
||||
android:gravity="center"
|
||||
android:text="1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="12sp"
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/bg_circle_green" />
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="2dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
@@ -37,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Team Name"
|
||||
android:textColor="@color/black"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold"
|
||||
android:ellipsize="end"
|
||||
@@ -49,7 +50,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -58,7 +59,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -67,7 +68,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -76,7 +77,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -85,7 +86,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -95,7 +96,7 @@
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="13sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user