adicao de jogadores na app
This commit is contained in:
@@ -26,12 +26,14 @@ public class ClubDetailFragment extends Fragment {
|
||||
private FragmentClubDetailBinding binding;
|
||||
private DatabaseReference mDatabase;
|
||||
private String clubId;
|
||||
private String escalao;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
clubId = getArguments().getString("clubId");
|
||||
escalao = getArguments().getString("escalao");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +73,7 @@ public class ClubDetailFragment extends Fragment {
|
||||
// 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("escalao", escalao);
|
||||
// Se o ClubPlayersFragment esperar "clube_selecionado" tambem, poderiamos
|
||||
// passar:
|
||||
// bundle.putSerializable("clube_selecionado", clubeRecebido);
|
||||
|
||||
@@ -28,12 +28,14 @@ public class ClubPlayersFragment extends Fragment {
|
||||
private FragmentClubPlayersBinding binding;
|
||||
private DatabaseReference mDatabase;
|
||||
private String clubId;
|
||||
private String escalao;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
clubId = getArguments().getString("clubId");
|
||||
escalao = getArguments().getString("escalao");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +54,13 @@ public class ClubPlayersFragment extends Fragment {
|
||||
binding.recyclerPlayersList.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
binding.progressBarPlayers.setVisibility(View.VISIBLE);
|
||||
|
||||
if (clubId != null) {
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(clubId);
|
||||
if (clubId != null && escalao != null) {
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(escalao).child(clubId);
|
||||
loadPlayers();
|
||||
} else {
|
||||
binding.progressBarPlayers.setVisibility(View.GONE);
|
||||
binding.textNoPlayers.setVisibility(View.VISIBLE);
|
||||
binding.textNoPlayers.setText("Erro: Clube não identificado.");
|
||||
binding.textNoPlayers.setText("Erro: Clube ou escalão não identificado.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,23 +30,47 @@ public class ClubsFragment extends Fragment {
|
||||
|
||||
private FragmentClubsBinding binding;
|
||||
private DatabaseReference mDatabase;
|
||||
private ValueEventListener mValueEventListener;
|
||||
private static final String TAG = "ClubsFragment";
|
||||
private String currentEscalao = "seniores"; // Default selection
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
binding = FragmentClubsBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes"); // Changed to 'clubes' as per
|
||||
// screenshot
|
||||
|
||||
RecyclerView recyclerView = binding.recyclerClubs;
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
ProgressBar progressBar = binding.progressBar;
|
||||
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
// Set up toggle listener
|
||||
binding.toggleGroupEscalao.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
|
||||
if (isChecked) {
|
||||
if (checkedId == R.id.btnJuniores) {
|
||||
currentEscalao = "juniores";
|
||||
} else if (checkedId == R.id.btnSeniores) {
|
||||
currentEscalao = "seniores";
|
||||
}
|
||||
loadClubsData(recyclerView, progressBar);
|
||||
}
|
||||
});
|
||||
|
||||
mDatabase.addValueEventListener(new ValueEventListener() {
|
||||
// Initial Data Load
|
||||
loadClubsData(recyclerView, progressBar);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(currentEscalao);
|
||||
|
||||
// Remove previous listener to avoid duplicate data or leaks
|
||||
if (mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
mValueEventListener = new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
List<Club> clubs = new ArrayList<>();
|
||||
@@ -59,6 +83,7 @@ public class ClubsFragment extends Fragment {
|
||||
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable("clube_selecionado", club);
|
||||
bundle.putString("escalao", currentEscalao);
|
||||
androidx.navigation.fragment.NavHostFragment.findNavController(ClubsFragment.this)
|
||||
.navigate(R.id.action_nav_clubs_to_nav_club_detail, bundle);
|
||||
});
|
||||
@@ -77,16 +102,21 @@ public class ClubsFragment extends Fragment {
|
||||
if (getContext() != null) {
|
||||
Toast.makeText(getContext(), "Failed to load clubs.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
binding.progressBar.setVisibility(View.GONE);
|
||||
if (binding != null) {
|
||||
binding.progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return root;
|
||||
mDatabase.addValueEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (mDatabase != null && mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,15 +5,43 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background_light">
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/toggleGroupEscalao"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
app:checkedButton="@id/btnSeniores"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:singleSelection="true">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnSeniores"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Seniores" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnJuniores"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Juniores" />
|
||||
|
||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recycler_clubs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toBottomOf="@id/toggleGroupEscalao" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
|
||||
@@ -57,6 +57,9 @@
|
||||
<argument
|
||||
android:name="clubId"
|
||||
app:argType="string" />
|
||||
<argument
|
||||
android:name="escalao"
|
||||
app:argType="string" />
|
||||
<action
|
||||
android:id="@+id/action_nav_club_detail_to_nav_club_players"
|
||||
app:destination="@id/nav_club_players" />
|
||||
@@ -70,6 +73,9 @@
|
||||
<argument
|
||||
android:name="clubId"
|
||||
app:argType="string" />
|
||||
<argument
|
||||
android:name="escalao"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
|
||||
</navigation>
|
||||
Reference in New Issue
Block a user