TABELA
This commit is contained in:
@@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.example.vdcscore.R;
|
||||
import com.example.vdcscore.databinding.FragmentHomeBinding;
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
@@ -27,6 +28,8 @@ public class HomeFragment extends Fragment {
|
||||
private FragmentHomeBinding binding;
|
||||
private StandingsAdapter adapter;
|
||||
private DatabaseReference mDatabase;
|
||||
private ValueEventListener mValueEventListener;
|
||||
private String currentEscalao = "seniores";
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -39,17 +42,33 @@ public class HomeFragment extends Fragment {
|
||||
binding.recyclerStandings.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
binding.recyclerStandings.setAdapter(adapter);
|
||||
|
||||
// Initialize Firebase
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("standings");
|
||||
// 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";
|
||||
}
|
||||
fetchStandings();
|
||||
}
|
||||
});
|
||||
|
||||
// Fetch Data
|
||||
// Fetch Data for default escalao
|
||||
fetchStandings();
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private void fetchStandings() {
|
||||
mDatabase.addValueEventListener(new ValueEventListener() {
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("standings").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<Team> teams = new ArrayList<>();
|
||||
@@ -85,12 +104,17 @@ public class HomeFragment extends Fragment {
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
mDatabase.addValueEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (mDatabase != null && mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,38 @@
|
||||
tools:context=".ui.home.HomeFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Classificação"
|
||||
android:textSize="28sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/primary_color"
|
||||
android:layout_marginBottom="24dp" />
|
||||
android:layout_marginBottom="16dp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/toggleGroupEscalao"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:checkedButton="@id/btnSeniores"
|
||||
android:gravity="center"
|
||||
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>
|
||||
|
||||
<!-- Table Header -->
|
||||
<LinearLayout
|
||||
|
||||
Reference in New Issue
Block a user