melhores marcadores adicionados

This commit is contained in:
2026-04-24 16:44:50 +01:00
parent ce16ff59b6
commit 8784cc4975
12 changed files with 789 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
package com.example.vdcscore.models;
import com.google.firebase.database.PropertyName;
import java.io.Serializable;
public class TopScorer implements Serializable {
private String playerName;
private String playerPhoto;
private String clubName;
private String clubLogo;
private int goals;
private int position;
public TopScorer() {
// Required for Firebase
}
@PropertyName("playerName")
public String getPlayerName() {
return playerName;
}
@PropertyName("playerName")
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
@PropertyName("playerPhoto")
public String getPlayerPhoto() {
return playerPhoto;
}
@PropertyName("playerPhoto")
public void setPlayerPhoto(String playerPhoto) {
this.playerPhoto = playerPhoto;
}
@PropertyName("clubName")
public String getClubName() {
return clubName;
}
@PropertyName("clubName")
public void setClubName(String clubName) {
this.clubName = clubName;
}
@PropertyName("clubLogo")
public String getClubLogo() {
return clubLogo;
}
@PropertyName("clubLogo")
public void setClubLogo(String clubLogo) {
this.clubLogo = clubLogo;
}
@PropertyName("goals")
public int getGoals() {
return goals;
}
@PropertyName("goals")
public void setGoals(int goals) {
this.goals = goals;
}
@PropertyName("position")
public int getPosition() {
return position;
}
@PropertyName("position")
public void setPosition(int position) {
this.position = position;
}
}

View File

@@ -0,0 +1,89 @@
package com.example.vdcscore.ui.topscorers;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.example.vdcscore.R;
import com.example.vdcscore.models.TopScorer;
import java.util.ArrayList;
import java.util.List;
public class TopScorersAdapter extends RecyclerView.Adapter<TopScorersAdapter.ViewHolder> {
private List<TopScorer> scorers = new ArrayList<>();
public void setTopScorers(List<TopScorer> scorers) {
this.scorers = (scorers != null) ? scorers : new ArrayList<>();
notifyDataSetChanged();
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_top_scorer, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
TopScorer scorer = scorers.get(position);
holder.textPosition.setText(scorer.getPosition() + "º");
holder.textPlayerName.setText(isValid(scorer.getPlayerName()) ? scorer.getPlayerName() : "Jogador");
holder.textClubName.setText(isValid(scorer.getClubName()) ? scorer.getClubName() : "Clube");
holder.textGoals.setText(String.valueOf(scorer.getGoals()));
// Carregar Foto do Jogador
Glide.with(holder.itemView.getContext())
.load(scorer.getPlayerPhoto())
.placeholder(R.drawable.ic_menu_camera)
.error(R.drawable.ic_menu_camera)
.circleCrop()
.into(holder.imgPlayerPhoto);
// Carregar Logótipo do Clube
Glide.with(holder.itemView.getContext())
.load(scorer.getClubLogo())
.placeholder(R.drawable.ic_menu_gallery)
.error(R.drawable.ic_menu_gallery)
.circleCrop()
.into(holder.imgClubLogo);
}
private boolean isValid(String text) {
return text != null && !text.trim().isEmpty() && !text.equalsIgnoreCase("null");
}
@Override
public int getItemCount() {
return scorers.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public final TextView textPosition;
public final TextView textPlayerName;
public final TextView textClubName;
public final TextView textGoals;
public final ImageView imgPlayerPhoto;
public final ImageView imgClubLogo;
public ViewHolder(View view) {
super(view);
textPosition = view.findViewById(R.id.text_position);
textPlayerName = view.findViewById(R.id.text_player_name);
textClubName = view.findViewById(R.id.text_club_name);
textGoals = view.findViewById(R.id.text_goals);
imgPlayerPhoto = view.findViewById(R.id.img_player_photo);
imgClubLogo = view.findViewById(R.id.img_club_logo);
}
}
}

View File

@@ -0,0 +1,130 @@
package com.example.vdcscore.ui.topscorers;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.vdcscore.R;
import com.example.vdcscore.models.TopScorer;
import com.google.android.material.button.MaterialButtonToggleGroup;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class TopScorersFragment extends Fragment {
private RecyclerView recyclerTopScorers;
private TopScorersAdapter adapter;
private MaterialButtonToggleGroup toggleGroupCategory;
private TextView textEmptyState;
private DatabaseReference mDatabase;
private String currentCategory = "seniores";
private ValueEventListener currentListener;
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_top_scorers, container, false);
recyclerTopScorers = root.findViewById(R.id.recycler_top_scorers);
toggleGroupCategory = root.findViewById(R.id.toggleGroupCategory);
textEmptyState = root.findViewById(R.id.text_empty_state);
adapter = new TopScorersAdapter();
recyclerTopScorers.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerTopScorers.setAdapter(adapter);
toggleGroupCategory.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
if (isChecked) {
if (checkedId == R.id.btn_seniores) {
currentCategory = "seniores";
} else if (checkedId == R.id.btn_juniores) {
currentCategory = "juniores";
}
fetchTopScorers();
}
});
fetchTopScorers();
return root;
}
private void fetchTopScorers() {
if (mDatabase != null && currentListener != null) {
mDatabase.removeEventListener(currentListener);
}
textEmptyState.setVisibility(View.VISIBLE);
textEmptyState.setText("A carregar dados...");
recyclerTopScorers.setVisibility(View.GONE);
mDatabase = FirebaseDatabase.getInstance().getReference("marcadores").child(currentCategory);
currentListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (getContext() == null) return;
List<TopScorer> scorersList = new ArrayList<>();
for (DataSnapshot data : snapshot.getChildren()) {
TopScorer scorer = data.getValue(TopScorer.class);
if (scorer != null) {
scorersList.add(scorer);
}
}
// Ordenar por golos descrescente
Collections.sort(scorersList, new Comparator<TopScorer>() {
@Override
public int compare(TopScorer s1, TopScorer s2) {
return Integer.compare(s2.getGoals(), s1.getGoals());
}
});
if (scorersList.isEmpty()) {
textEmptyState.setText("Ainda não existem marcadores registados.");
textEmptyState.setVisibility(View.VISIBLE);
recyclerTopScorers.setVisibility(View.GONE);
} else {
textEmptyState.setVisibility(View.GONE);
recyclerTopScorers.setVisibility(View.VISIBLE);
adapter.setTopScorers(scorersList);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
if (getContext() != null) {
Toast.makeText(getContext(), "Erro ao carregar: " + error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
};
mDatabase.addValueEventListener(currentListener);
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (mDatabase != null && currentListener != null) {
mDatabase.removeEventListener(currentListener);
}
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#F0F2F5"/>
</shape>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#F5F7FA"
tools:context=".ui.topscorers.TopScorersFragment">
<!-- Title and Category Toggle -->
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="4dp"
app:cardCornerRadius="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Melhores Marcadores"
android:textSize="20sp"
android:textColor="#1A237E"
android:textStyle="bold"
android:layout_marginBottom="12dp" />
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleGroupCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true"
app:checkedButton="@+id/btn_seniores">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_seniores"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seniores" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_juniores"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Juniores" />
</com.google.android.material.button.MaterialButtonToggleGroup>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
<!-- Empty State -->
<TextView
android:id="@+id/text_empty_state"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="A carregar dados..."
android:textAlignment="center"
android:gravity="center"
android:textSize="16sp"
android:visibility="gone" />
<!-- RecyclerView -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_top_scorers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="8dp"
android:paddingBottom="16dp"
android:clipToPadding="false"
tools:listitem="@layout/item_top_scorer" />
</LinearLayout>

View File

@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="6dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="12dp"
app:cardElevation="2dp"
app:strokeWidth="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="12dp"
android:gravity="center_vertical">
<!-- Position Badge -->
<TextView
android:id="@+id/text_position"
android:layout_width="32dp"
android:layout_height="32dp"
android:background="@drawable/bg_circle_light_gray"
android:text="1"
android:textColor="#333333"
android:textSize="14sp"
android:textStyle="bold"
android:gravity="center"
android:layout_marginEnd="12dp" />
<!-- Player Photo -->
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/img_player_photo"
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_menu_gallery"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
android:layout_marginEnd="12dp" />
<!-- Player & Club Details -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/text_player_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome do Jogador"
android:textColor="#1A237E"
android:textSize="16sp"
android:textStyle="bold"
android:maxLines="1"
android:ellipsize="end" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_marginTop="4dp">
<ImageView
android:id="@+id/img_club_logo"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_menu_gallery"
android:layout_marginEnd="6dp" />
<TextView
android:id="@+id/text_club_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome do Clube"
android:textColor="#757575"
android:textSize="13sp"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
</LinearLayout>
<!-- Goals Counter -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:paddingStart="12dp">
<TextView
android:id="@+id/text_goals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textColor="#FF6D00"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Golos"
android:textColor="#9E9E9E"
android:textSize="11sp"
android:textAllCaps="true" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>