adicao de jogadores na app
This commit is contained in:
@@ -26,12 +26,14 @@ public class ClubDetailFragment extends Fragment {
|
|||||||
private FragmentClubDetailBinding binding;
|
private FragmentClubDetailBinding binding;
|
||||||
private DatabaseReference mDatabase;
|
private DatabaseReference mDatabase;
|
||||||
private String clubId;
|
private String clubId;
|
||||||
|
private String escalao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
clubId = getArguments().getString("clubId");
|
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,
|
// 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
|
// 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()));
|
||||||
|
bundle.putString("escalao", escalao);
|
||||||
// Se o ClubPlayersFragment esperar "clube_selecionado" tambem, poderiamos
|
// Se o ClubPlayersFragment esperar "clube_selecionado" tambem, poderiamos
|
||||||
// passar:
|
// passar:
|
||||||
// bundle.putSerializable("clube_selecionado", clubeRecebido);
|
// bundle.putSerializable("clube_selecionado", clubeRecebido);
|
||||||
|
|||||||
@@ -28,12 +28,14 @@ public class ClubPlayersFragment extends Fragment {
|
|||||||
private FragmentClubPlayersBinding binding;
|
private FragmentClubPlayersBinding binding;
|
||||||
private DatabaseReference mDatabase;
|
private DatabaseReference mDatabase;
|
||||||
private String clubId;
|
private String clubId;
|
||||||
|
private String escalao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
clubId = getArguments().getString("clubId");
|
clubId = getArguments().getString("clubId");
|
||||||
|
escalao = getArguments().getString("escalao");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,13 +54,13 @@ public class ClubPlayersFragment extends Fragment {
|
|||||||
binding.recyclerPlayersList.setLayoutManager(new LinearLayoutManager(getContext()));
|
binding.recyclerPlayersList.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
binding.progressBarPlayers.setVisibility(View.VISIBLE);
|
binding.progressBarPlayers.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (clubId != null) {
|
if (clubId != null && escalao != null) {
|
||||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(clubId);
|
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes").child(escalao).child(clubId);
|
||||||
loadPlayers();
|
loadPlayers();
|
||||||
} else {
|
} else {
|
||||||
binding.progressBarPlayers.setVisibility(View.GONE);
|
binding.progressBarPlayers.setVisibility(View.GONE);
|
||||||
binding.textNoPlayers.setVisibility(View.VISIBLE);
|
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 FragmentClubsBinding binding;
|
||||||
private DatabaseReference mDatabase;
|
private DatabaseReference mDatabase;
|
||||||
|
private ValueEventListener mValueEventListener;
|
||||||
private static final String TAG = "ClubsFragment";
|
private static final String TAG = "ClubsFragment";
|
||||||
|
private String currentEscalao = "seniores"; // Default selection
|
||||||
|
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||||
ViewGroup container, Bundle savedInstanceState) {
|
ViewGroup container, Bundle savedInstanceState) {
|
||||||
binding = FragmentClubsBinding.inflate(inflater, container, false);
|
binding = FragmentClubsBinding.inflate(inflater, container, false);
|
||||||
View root = binding.getRoot();
|
View root = binding.getRoot();
|
||||||
|
|
||||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes"); // Changed to 'clubes' as per
|
|
||||||
// screenshot
|
|
||||||
|
|
||||||
RecyclerView recyclerView = binding.recyclerClubs;
|
RecyclerView recyclerView = binding.recyclerClubs;
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
ProgressBar progressBar = binding.progressBar;
|
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
|
@Override
|
||||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
List<Club> clubs = new ArrayList<>();
|
List<Club> clubs = new ArrayList<>();
|
||||||
@@ -59,6 +83,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.putSerializable("clube_selecionado", club);
|
bundle.putSerializable("clube_selecionado", club);
|
||||||
|
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);
|
||||||
});
|
});
|
||||||
@@ -77,16 +102,21 @@ public class ClubsFragment extends Fragment {
|
|||||||
if (getContext() != null) {
|
if (getContext() != null) {
|
||||||
Toast.makeText(getContext(), "Failed to load clubs.", Toast.LENGTH_SHORT).show();
|
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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
if (mDatabase != null && mValueEventListener != null) {
|
||||||
|
mDatabase.removeEventListener(mValueEventListener);
|
||||||
|
}
|
||||||
binding = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,43 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="@color/background_light">
|
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
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recycler_clubs"
|
android:id="@+id/recycler_clubs"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toBottomOf="@id/toggleGroupEscalao" />
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progress_bar"
|
android:id="@+id/progress_bar"
|
||||||
|
|||||||
@@ -57,6 +57,9 @@
|
|||||||
<argument
|
<argument
|
||||||
android:name="clubId"
|
android:name="clubId"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
|
<argument
|
||||||
|
android:name="escalao"
|
||||||
|
app:argType="string" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_nav_club_detail_to_nav_club_players"
|
android:id="@+id/action_nav_club_detail_to_nav_club_players"
|
||||||
app:destination="@id/nav_club_players" />
|
app:destination="@id/nav_club_players" />
|
||||||
@@ -70,6 +73,9 @@
|
|||||||
<argument
|
<argument
|
||||||
android:name="clubId"
|
android:name="clubId"
|
||||||
app:argType="string" />
|
app:argType="string" />
|
||||||
|
<argument
|
||||||
|
android:name="escalao"
|
||||||
|
app:argType="string" />
|
||||||
</fragment>
|
</fragment>
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.13.1"
|
agp = "8.13.2"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.3.0"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.7.0"
|
espressoCore = "3.7.0"
|
||||||
|
|||||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,4 +1,4 @@
|
|||||||
#Thu Jan 29 09:53:07 WET 2026
|
#Wed Feb 25 12:48:32 WET 2026
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user