Compare commits
3 Commits
0fbbd77f9f
...
9348951090
| Author | SHA1 | Date | |
|---|---|---|---|
| 9348951090 | |||
| a019287d92 | |||
| 012815d969 |
@@ -119,34 +119,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void loadProfileImageInNavHeader(String imageUrl, ImageView imageView) {
|
||||
new Thread(() -> {
|
||||
InputStream input = null;
|
||||
try {
|
||||
java.net.URL url = new java.net.URL(imageUrl);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
input = connection.getInputStream();
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(input);
|
||||
runOnUiThread(() -> {
|
||||
if (bitmap != null && imageView != null) {
|
||||
imageView.setImageBitmap(bitmap);
|
||||
imageView.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// Se falhar, tentar carregar do Storage
|
||||
runOnUiThread(() -> loadProfileImageFromStorage(imageView));
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (Exception e) {
|
||||
// Ignorar erro ao fechar
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
if (imageUrl == null || imageView == null) return;
|
||||
Glide.with(this)
|
||||
.load(imageUrl)
|
||||
.placeholder(R.mipmap.ic_launcher_round)
|
||||
.error(R.mipmap.ic_launcher)
|
||||
.circleCrop()
|
||||
.into(imageView);
|
||||
}
|
||||
|
||||
private void loadProfileImageFromStorage(ImageView imageView) {
|
||||
|
||||
@@ -62,49 +62,55 @@ public class ClubsFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void loadClubsData(RecyclerView recyclerView, ProgressBar progressBar) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes");
|
||||
if (progressBar != null) progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
// Remove previous listener to avoid duplicate data or leaks
|
||||
if (mValueEventListener != null) {
|
||||
// Remove previous listener from the PREVIOUS path
|
||||
if (mDatabase != null && mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference().child("clubes");
|
||||
|
||||
mValueEventListener = new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
if (binding == null) return;
|
||||
|
||||
List<Club> clubs = new ArrayList<>();
|
||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||
if (postSnapshot.child("jogadores").child(currentEscalao).exists()) {
|
||||
try {
|
||||
Club club = postSnapshot.getValue(Club.class);
|
||||
if (club != null) {
|
||||
clubs.add(club);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
ClubAdapter adapter = new ClubAdapter(clubs, club -> {
|
||||
if (binding == null) return;
|
||||
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);
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
if (clubs.isEmpty()) {
|
||||
// Keep UI empty but don't show mock data automatically to avoid confusion
|
||||
// Toast.makeText(getContext(), "No clubs found.", Toast.LENGTH_SHORT).show();
|
||||
if (recyclerView != null) {
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
Log.w(TAG, "loadClubs:onCancelled", error.toException());
|
||||
if (getContext() != null) {
|
||||
if (getContext() != null && binding != null) {
|
||||
Toast.makeText(getContext(), "Failed to load clubs.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
if (binding != null) {
|
||||
binding.progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,32 +193,13 @@ public class ContaActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void loadProfileImage(String imageUrl) {
|
||||
new Thread(() -> {
|
||||
InputStream input = null;
|
||||
try {
|
||||
java.net.URL url = new java.net.URL(imageUrl);
|
||||
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
||||
connection.setDoInput(true);
|
||||
connection.connect();
|
||||
input = connection.getInputStream();
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(input);
|
||||
runOnUiThread(() -> {
|
||||
if (bitmap != null && imageProfile != null) {
|
||||
imageProfile.setImageBitmap(bitmap);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
runOnUiThread(() -> loadProfileImageFromStorage());
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (Exception e) {
|
||||
// Ignorar erro ao fechar
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
if (imageUrl == null || imageProfile == null) return;
|
||||
Glide.with(this)
|
||||
.load(imageUrl)
|
||||
.placeholder(R.mipmap.ic_launcher_round)
|
||||
.error(R.mipmap.ic_launcher)
|
||||
.circleCrop()
|
||||
.into(imageProfile);
|
||||
}
|
||||
|
||||
private void loadProfileImageFromStorage() {
|
||||
|
||||
@@ -50,6 +50,7 @@ public class GalleryFragment extends Fragment {
|
||||
mDatabase.addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
if (binding == null) return;
|
||||
List<Matchday> matchdays = new ArrayList<>();
|
||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||
Matchday matchday = new Matchday();
|
||||
|
||||
@@ -61,50 +61,49 @@ public class HomeFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void fetchStandings() {
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
||||
|
||||
// Remove previous listener to avoid duplicate data or leaks
|
||||
if (mValueEventListener != null) {
|
||||
// Remove previous listener from the PREVIOUS path
|
||||
if (mDatabase != null && mValueEventListener != null) {
|
||||
mDatabase.removeEventListener(mValueEventListener);
|
||||
}
|
||||
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("classificacoes").child(currentEscalao);
|
||||
|
||||
mValueEventListener = new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
if (binding == null) return;
|
||||
|
||||
List<Team> teams = new ArrayList<>();
|
||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||
try {
|
||||
Team team = postSnapshot.getValue(Team.class);
|
||||
if (team != null) {
|
||||
// If ID is missing, set it from the key
|
||||
if (team.getId() == null) {
|
||||
team.setId(postSnapshot.getKey());
|
||||
if (team.getTeam_id() == null) {
|
||||
team.setTeam_id(postSnapshot.getKey());
|
||||
}
|
||||
teams.add(team);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
android.util.Log.e("HomeFragment", "Error mapping Team: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
android.util.Log.d("HomeFragment", "Fetched " + teams.size() + " teams for escalao: " + currentEscalao);
|
||||
|
||||
// Sort by Points (Descending), then Goal Difference, then Goals For
|
||||
Collections.sort(teams, new Comparator<Team>() {
|
||||
@Override
|
||||
public int compare(Team t1, Team t2) {
|
||||
if (t1.getPoints() != t2.getPoints()) {
|
||||
return t2.getPoints() - t1.getPoints(); // Descending points
|
||||
}
|
||||
return t2.getGoalDifference() - t1.getGoalDifference(); // Descending GD
|
||||
// Sort properly
|
||||
Collections.sort(teams, (t1, t2) -> {
|
||||
if (t1.getPontos() != t2.getPontos()) {
|
||||
return t2.getPontos() - t1.getPontos();
|
||||
}
|
||||
return t2.getDiferenca_golos() - t1.getDiferenca_golos();
|
||||
});
|
||||
|
||||
if (adapter != null) {
|
||||
adapter.setTeams(teams);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(@NonNull DatabaseError error) {
|
||||
if (getContext() != null) {
|
||||
if (getContext() != null && binding != null) {
|
||||
Toast.makeText(getContext(), "Erro ao carregar classificação: " + error.getMessage(),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.vdcscore.R;
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.ViewHolder> {
|
||||
|
||||
private List<Team> mTeams;
|
||||
@@ -38,6 +39,7 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||
Team team = mTeams.get(position);
|
||||
if (team == null) return;
|
||||
|
||||
int rank = position + 1;
|
||||
holder.textPosition.setText(String.valueOf(rank));
|
||||
@@ -56,24 +58,20 @@ public class StandingsAdapter extends RecyclerView.Adapter<StandingsAdapter.View
|
||||
holder.textPosition.setTextColor(android.graphics.Color.BLACK);
|
||||
}
|
||||
|
||||
holder.textTeamName.setText(team.getName());
|
||||
|
||||
if (team.getImageUrl() != null && !team.getImageUrl().isEmpty()) {
|
||||
com.bumptech.glide.Glide.with(holder.itemView.getContext())
|
||||
.load(team.getImageUrl())
|
||||
String imageUrl = team.getImagem();
|
||||
Glide.with(holder.itemView.getContext())
|
||||
.load(imageUrl != null ? imageUrl : "")
|
||||
.placeholder(R.mipmap.ic_launcher)
|
||||
.error(R.mipmap.ic_launcher)
|
||||
.into(holder.imageLogo);
|
||||
} else {
|
||||
holder.imageLogo.setImageResource(R.mipmap.ic_launcher);
|
||||
}
|
||||
|
||||
holder.textPlayed.setText(String.valueOf(team.getPlayed()));
|
||||
holder.textWon.setText(String.valueOf(team.getWon()));
|
||||
holder.textDrawn.setText(String.valueOf(team.getDrawn()));
|
||||
holder.textLost.setText(String.valueOf(team.getLost()));
|
||||
holder.textGoalDiff.setText(String.valueOf(team.getGoalDifference()));
|
||||
holder.textPoints.setText(String.valueOf(team.getPoints()));
|
||||
holder.textTeamName.setText(team.getNome() != null ? team.getNome() : "---");
|
||||
holder.textPlayed.setText(String.valueOf(team.getJogos()));
|
||||
holder.textWon.setText(String.valueOf(team.getVitorias()));
|
||||
holder.textDrawn.setText(String.valueOf(team.getEmpates()));
|
||||
holder.textLost.setText(String.valueOf(team.getDerrotas()));
|
||||
holder.textGoalDiff.setText(String.valueOf(team.getDiferenca_golos()));
|
||||
holder.textPoints.setText(String.valueOf(team.getPontos()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,6 +31,7 @@ public class LiveGamesFragment extends Fragment {
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
gameViewModel.getGames().observe(getViewLifecycleOwner(), games -> {
|
||||
if (binding == null) return;
|
||||
GameAdapter adapter = new GameAdapter(games, game -> {
|
||||
gameViewModel.selectGame(game);
|
||||
Navigation.findNavController(root).navigate(R.id.action_nav_live_games_to_nav_live_game_detail);
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="8dp"
|
||||
android:paddingVertical="10dp"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:background="@drawable/bg_table_header">
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="POS"
|
||||
android:text="#"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Space
|
||||
android:layout_width="28dp"
|
||||
@@ -71,8 +71,8 @@
|
||||
android:layout_weight="1"
|
||||
android:text="EQUIPA"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -80,8 +80,8 @@
|
||||
android:gravity="center"
|
||||
android:text="J"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -89,8 +89,8 @@
|
||||
android:gravity="center"
|
||||
android:text="V"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -98,8 +98,8 @@
|
||||
android:gravity="center"
|
||||
android:text="E"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="24dp"
|
||||
@@ -107,8 +107,8 @@
|
||||
android:gravity="center"
|
||||
android:text="D"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="26dp"
|
||||
@@ -116,8 +116,8 @@
|
||||
android:gravity="center"
|
||||
android:text="DG"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="32dp"
|
||||
@@ -125,8 +125,8 @@
|
||||
android:gravity="center"
|
||||
android:text="PTS"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="normal" />
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingVertical="12dp"
|
||||
android:paddingVertical="10dp"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
@@ -20,7 +20,7 @@
|
||||
android:gravity="center"
|
||||
android:text="1"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="12sp"
|
||||
android:textSize="11sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/bg_circle_green" />
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginHorizontal="2dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
@@ -37,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Team Name"
|
||||
android:textColor="@color/black"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold"
|
||||
android:ellipsize="end"
|
||||
@@ -49,7 +50,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -58,7 +59,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -67,7 +68,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -76,7 +77,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -85,7 +86,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textColor="@color/text_secondary"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
@@ -95,7 +96,7 @@
|
||||
android:gravity="center"
|
||||
android:text="0"
|
||||
android:textStyle="bold"
|
||||
android:textColor="@color/black"
|
||||
android:textColor="@color/text_primary"
|
||||
android:textSize="13sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user