correcao de erros
This commit is contained in:
@@ -47,19 +47,16 @@ public class ClubDetailFragment extends Fragment {
|
|||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
|
||||||
// Verificar se vieram argumentos do Adapter
|
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
// Receber o objeto Club inteiro
|
|
||||||
Club clubeRecebido = (Club) getArguments().getSerializable("clube_selecionado");
|
Club clubeRecebido = (Club) getArguments().getSerializable("clube_selecionado");
|
||||||
|
|
||||||
if (clubeRecebido != null) {
|
if (clubeRecebido != null) {
|
||||||
// Preencher os dados usando o binding
|
// Preencher views diretamente
|
||||||
binding.textDetailClubName.setText(clubeRecebido.getName());
|
binding.textDetailClubName.setText(clubeRecebido.getName());
|
||||||
|
binding.textDetailFoundation.setText(String.valueOf(clubeRecebido.getFoundationYear()));
|
||||||
binding.textDetailPresident.setText(clubeRecebido.getPresident());
|
binding.textDetailPresident.setText(clubeRecebido.getPresident());
|
||||||
binding.textDetailAddress.setText(clubeRecebido.getAddress());
|
binding.textDetailAddress.setText(clubeRecebido.getAddress());
|
||||||
binding.textDetailFoundation.setText(String.valueOf(clubeRecebido.getFoundationYear()));
|
|
||||||
|
|
||||||
// Carregar imagem
|
|
||||||
if (getContext() != null) {
|
if (getContext() != null) {
|
||||||
Glide.with(this)
|
Glide.with(this)
|
||||||
.load(clubeRecebido.getImageUrl())
|
.load(clubeRecebido.getImageUrl())
|
||||||
@@ -68,11 +65,16 @@ public class ClubDetailFragment extends Fragment {
|
|||||||
.into(binding.imageDetailLogo);
|
.into(binding.imageDetailLogo);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configurar botão de jogadores
|
// Configurar o botão para ver jogadores
|
||||||
binding.btnPlayers.setOnClickListener(v -> {
|
binding.btnPlayers.setOnClickListener(v -> {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
// Passando o ID como String, garantindo compatibilidade
|
// Passar o 'clube_selecionado' também para a lista de jogadores se necessário,
|
||||||
|
// ou passar o ID como antes se o fragmento de jogadores esperar ID
|
||||||
bundle.putString("clubId", String.valueOf(clubeRecebido.getId()));
|
bundle.putString("clubId", String.valueOf(clubeRecebido.getId()));
|
||||||
|
// Se o ClubPlayersFragment esperar "clube_selecionado" tambem, poderiamos
|
||||||
|
// passar:
|
||||||
|
// bundle.putSerializable("clube_selecionado", clubeRecebido);
|
||||||
|
|
||||||
Navigation.findNavController(view).navigate(R.id.action_nav_club_detail_to_nav_club_players,
|
Navigation.findNavController(view).navigate(R.id.action_nav_club_detail_to_nav_club_players,
|
||||||
bundle);
|
bundle);
|
||||||
});
|
});
|
||||||
@@ -80,6 +82,38 @@ public class ClubDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadClubDetails() {
|
||||||
|
mDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
Club club = snapshot.getValue(Club.class);
|
||||||
|
if (club != null) {
|
||||||
|
binding.textDetailClubName.setText(club.getName());
|
||||||
|
binding.textDetailFoundation.setText(String.valueOf(club.getFoundationYear()));
|
||||||
|
binding.textDetailPresident.setText(club.getPresident());
|
||||||
|
binding.textDetailAddress.setText(club.getAddress());
|
||||||
|
// binding.textDetailStadium.setText(club.getStadium()); // Hidden for now
|
||||||
|
|
||||||
|
// binding.imageDetailLogo.setImageResource(R.mipmap.ic_launcher_round);
|
||||||
|
if (getContext() != null) {
|
||||||
|
Glide.with(ClubDetailFragment.this)
|
||||||
|
.load(club.getImageUrl())
|
||||||
|
.placeholder(R.mipmap.ic_launcher_round)
|
||||||
|
.error(R.mipmap.ic_launcher)
|
||||||
|
.into(binding.imageDetailLogo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
if (getContext() != null) {
|
||||||
|
Toast.makeText(getContext(), "Failed to load club details.", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import com.google.firebase.database.ValueEventListener;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ClubsFragment extends Fragment {
|
public class ClubsFragment extends Fragment {
|
||||||
|
|
||||||
private FragmentClubsBinding binding;
|
private FragmentClubsBinding binding;
|
||||||
private DatabaseReference mDatabase;
|
private DatabaseReference mDatabase;
|
||||||
@@ -58,7 +58,7 @@ public class ClubsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("clubId", String.valueOf(club.getId()));
|
bundle.putSerializable("clube_selecionado", club);
|
||||||
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);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user