resolver erros
This commit is contained in:
@@ -119,34 +119,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadProfileImageInNavHeader(String imageUrl, ImageView imageView) {
|
private void loadProfileImageInNavHeader(String imageUrl, ImageView imageView) {
|
||||||
new Thread(() -> {
|
if (imageUrl == null || imageView == null) return;
|
||||||
InputStream input = null;
|
Glide.with(this)
|
||||||
try {
|
.load(imageUrl)
|
||||||
java.net.URL url = new java.net.URL(imageUrl);
|
.placeholder(R.mipmap.ic_launcher_round)
|
||||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
.error(R.mipmap.ic_launcher)
|
||||||
connection.setDoInput(true);
|
.circleCrop()
|
||||||
connection.connect();
|
.into(imageView);
|
||||||
input = connection.getInputStream();
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeStream(input);
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
if (bitmap != null && imageView != null) {
|
|
||||||
imageView.setImageBitmap(bitmap);
|
|
||||||
imageView.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Se falhar, tentar carregar do Storage
|
|
||||||
runOnUiThread(() -> loadProfileImageFromStorage(imageView));
|
|
||||||
} finally {
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
input.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignorar erro ao fechar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadProfileImageFromStorage(ImageView imageView) {
|
private void loadProfileImageFromStorage(ImageView imageView) {
|
||||||
|
|||||||
@@ -62,49 +62,55 @@ public class ClubsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) {
|
private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) {
|
||||||
progressBar.setVisibility(View.VISIBLE);
|
if (progressBar != null) progressBar.setVisibility(View.VISIBLE);
|
||||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes");
|
|
||||||
|
|
||||||
// Remove previous listener to avoid duplicate data or leaks
|
// Remove previous listener from the PREVIOUS path
|
||||||
if (mValueEventListener != null) {
|
if (mDatabase != null && mValueEventListener != null) {
|
||||||
mDatabase.removeEventListener(mValueEventListener);
|
mDatabase.removeEventListener(mValueEventListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes");
|
||||||
|
|
||||||
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<Club> clubs = new ArrayList<>();
|
List<Club> clubs = new ArrayList<>();
|
||||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
if (postSnapshot.child("jogadores").child(currentEscalao).exists()) {
|
if (postSnapshot.child("jogadores").child(currentEscalao).exists()) {
|
||||||
Club club = postSnapshot.getValue(Club.class);
|
try {
|
||||||
if (club != null) {
|
Club club = postSnapshot.getValue(Club.class);
|
||||||
clubs.add(club);
|
if (club != null) {
|
||||||
|
clubs.add(club);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
||||||
|
if (binding == null) return;
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putSerializable("clube_selecionado", club);
|
bundle.putSerializable("clube_selecionado", club);
|
||||||
bundle.putString("escalao", currentEscalao);
|
bundle.putString("escalao", currentEscalao);
|
||||||
androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this)
|
androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this)
|
||||||
.navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle);
|
.navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle);
|
||||||
});
|
});
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
progressBar.setVisibility(View.GONE);
|
if (recyclerView != null) {
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
if (clubs.isEmpty()) {
|
}
|
||||||
// Keep UI empty but don't show mock data automatically to avoid confusion
|
if (progressBar != null) {
|
||||||
// Toast.makeText(getContext(), "No clubs found.", Toast.LENGTH_SHORT).show();
|
progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancelled(@NonNull DatabaseError error) {
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
Log.w(TAG, "loadClubs:onCancelled", error.toException());
|
Log.w(TAG, "loadClubs:onCancelled", error.toException());
|
||||||
if (getContext() != null) {
|
if (getContext() != null && binding != null) {
|
||||||
Toast.makeText(getContext(), "Failed to load clubs.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Failed to load clubs.", Toast.LENGTH_SHORT).show();
|
||||||
}
|
|
||||||
if (binding != null) {
|
|
||||||
binding.progressBar.setVisibility(View.GONE);
|
binding.progressBar.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,32 +193,13 @@ public class ContaActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadProfileImage(String imageUrl) {
|
private void loadProfileImage(String imageUrl) {
|
||||||
new Thread(() -> {
|
if (imageUrl == null || imageProfile == null) return;
|
||||||
InputStream input = null;
|
Glide.with(this)
|
||||||
try {
|
.load(imageUrl)
|
||||||
java.net.URL url = new java.net.URL(imageUrl);
|
.placeholder(R.mipmap.ic_launcher_round)
|
||||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
.error(R.mipmap.ic_launcher)
|
||||||
connection.setDoInput(true);
|
.circleCrop()
|
||||||
connection.connect();
|
.into(imageProfile);
|
||||||
input = connection.getInputStream();
|
|
||||||
Bitmap bitmap = BitmapFactory.decodeStream(input);
|
|
||||||
runOnUiThread(() -> {
|
|
||||||
if (bitmap != null && imageProfile != null) {
|
|
||||||
imageProfile.setImageBitmap(bitmap);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (Exception e) {
|
|
||||||
runOnUiThread(() -> loadProfileImageFromStorage());
|
|
||||||
} finally {
|
|
||||||
if (input != null) {
|
|
||||||
try {
|
|
||||||
input.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// Ignorar erro ao fechar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadProfileImageFromStorage() {
|
private void loadProfileImageFromStorage() {
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public class GalleryFragment extends Fragment {
|
|||||||
mDatabase.addValueEventListener(new ValueEventListener() {
|
mDatabase.addValueEventListener(new ValueEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
if (binding == null) return;
|
||||||
List<Matchday> matchdays = new ArrayList<>();
|
List<Matchday> matchdays = new ArrayList<>();
|
||||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
Matchday matchday = new Matchday();
|
Matchday matchday = new Matchday();
|
||||||
|
|||||||
@@ -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 the PREVIOUS 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()));
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public class LiveGamesFragment extends Fragment {
|
|||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
||||||
gameViewModel.getGames().observe(getViewLifecycleOwner(), games -> {
|
gameViewModel.getGames().observe(getViewLifecycleOwner(), games -> {
|
||||||
|
if (binding == null) return;
|
||||||
GameAdapter adapter = new GameAdapter(games, game -> {
|
GameAdapter adapter = new GameAdapter(games, game -> {
|
||||||
gameViewModel.selectGame(game);
|
gameViewModel.selectGame(game);
|
||||||
Navigation.findNavController(root).navigate(R.id.action_nav_live_games_to_nav_live_game_detail);
|
Navigation.findNavController(root).navigate(R.id.action_nav_live_games_to_nav_live_game_detail);
|
||||||
|
|||||||
Reference in New Issue
Block a user