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