Terminacion de la clase FragmentProfile que ya tiene toda la funcionalidad que a de tener y optimizacion de otras para que funcione y creacion de javas y xml!
This commit is contained in:
parent
5b258bc19a
commit
85ec9155e4
Binary file not shown.
|
|
@ -7,6 +7,7 @@ import com.santiparra.yomitrack.db.entities.UserEntity;
|
|||
import com.santiparra.yomitrack.model.AniListMedia;
|
||||
import com.santiparra.yomitrack.model.AnimePageResponse;
|
||||
import com.santiparra.yomitrack.model.ApiResponse;
|
||||
import com.santiparra.yomitrack.model.CommentModel;
|
||||
import com.santiparra.yomitrack.model.LoginResponse;
|
||||
import com.santiparra.yomitrack.model.MangaPageResponse;
|
||||
import com.santiparra.yomitrack.model.RegisterResponse;
|
||||
|
|
@ -22,6 +23,7 @@ import retrofit2.Call;
|
|||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.HTTP;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
|
|
@ -32,6 +34,7 @@ public interface ApiService {
|
|||
// ---------------- Usuario ----------------
|
||||
@POST("users/register")
|
||||
Call<RegisterResponse> registerUser(@Body UserEntity user);
|
||||
|
||||
@POST("users/login")
|
||||
Call<LoginResponse> loginUser(@Body UserEntity user);
|
||||
|
||||
|
|
@ -83,9 +86,28 @@ public interface ApiService {
|
|||
|
||||
@GET("api/activity/list/{userId}")
|
||||
Call<List<ActivityLog>> getActivityLog(@Path("userId") int userId);
|
||||
|
||||
@GET("api/activity/comments/{activityId}")
|
||||
Call<List<CommentModel>> getCommentsByActivity(@Path("activityId") int activityId);
|
||||
|
||||
@GET("/api/activity/like/{userId}/{activityId}")
|
||||
Call<JsonObject> checkLike(
|
||||
@Path("userId") int userId,
|
||||
@Path("activityId") int activityId
|
||||
);
|
||||
|
||||
@POST("api/activity/like")
|
||||
Call<JsonObject> postLike(@Body JsonObject body);
|
||||
|
||||
@POST("api/activity/comment")
|
||||
Call<JsonObject> postComment(@Body JsonObject body);
|
||||
|
||||
@POST("api/activity/add")
|
||||
Call<JsonObject> postActivity(@Body Map<String, Object> body);
|
||||
|
||||
@HTTP(method = "DELETE", path = "api/activity/like/remove", hasBody = true)
|
||||
Call<JsonObject> deleteLike(@Body JsonObject body);
|
||||
|
||||
|
||||
// ---------------- AniList API ----------------
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,35 @@
|
|||
package com.santiparra.yomitrack.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Modelo de actividad reciente para mostrar acciones de usuario.
|
||||
*/
|
||||
public class RecentActivityModel {
|
||||
public int activityId; // ← agregar esto
|
||||
public String user;
|
||||
public String action;
|
||||
public String title;
|
||||
public String time;
|
||||
public String imageUrl;
|
||||
public List<CommentModel> comments = new ArrayList<>();
|
||||
|
||||
public RecentActivityModel(String user, String action, String title, String time, String imageUrl) {
|
||||
public RecentActivityModel(int activityId, String user, String action, String title, String time, String imageUrl) {
|
||||
this.activityId = activityId;
|
||||
this.user = user;
|
||||
this.action = action;
|
||||
this.title = title;
|
||||
this.time = time;
|
||||
this.imageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public void addComment(CommentModel comment) {
|
||||
comments.add(comment);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return activityId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,17 @@ package com.santiparra.yomitrack.model.adapters.recentactivity_adapter;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.santiparra.yomitrack.R;
|
||||
import com.santiparra.yomitrack.model.CommentDialog;
|
||||
import com.santiparra.yomitrack.model.CommentModel;
|
||||
import com.santiparra.yomitrack.model.RecentActivityModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecentActivityAdapter extends RecyclerView.Adapter<RecentActivityAdapter.ActivityViewHolder> {
|
||||
|
|
@ -41,6 +42,36 @@ public class RecentActivityAdapter extends RecyclerView.Adapter<RecentActivityAd
|
|||
.load(activity.imageUrl)
|
||||
.placeholder(R.drawable.placeholder_image)
|
||||
.into(holder.image);
|
||||
|
||||
holder.commentContainer.removeAllViews();
|
||||
|
||||
if (holder.commentContainer != null) {
|
||||
holder.commentContainer.removeAllViews();
|
||||
|
||||
for (CommentModel comment : activity.comments) {
|
||||
View commentView = LayoutInflater.from(holder.itemView.getContext())
|
||||
.inflate(R.layout.item_comment, holder.commentContainer, false);
|
||||
|
||||
TextView commentText = commentView.findViewById(R.id.commentText);
|
||||
ImageButton commentLike = commentView.findViewById(R.id.commentLikeButton);
|
||||
|
||||
commentText.setText(comment.text);
|
||||
commentLike.setImageResource(comment.liked ? R.drawable.ic_heart_filled : R.drawable.ic_heart);
|
||||
commentLike.setColorFilter(comment.liked
|
||||
? holder.itemView.getContext().getColor(R.color.pink)
|
||||
: holder.itemView.getContext().getColor(R.color.textPrimary));
|
||||
|
||||
commentLike.setOnClickListener(v -> {
|
||||
comment.liked = !comment.liked;
|
||||
commentLike.setImageResource(comment.liked ? R.drawable.ic_heart_filled : R.drawable.ic_heart);
|
||||
commentLike.setColorFilter(comment.liked
|
||||
? holder.itemView.getContext().getColor(R.color.pink)
|
||||
: holder.itemView.getContext().getColor(R.color.textPrimary));
|
||||
});
|
||||
|
||||
holder.commentContainer.addView(commentView);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -48,9 +79,12 @@ public class RecentActivityAdapter extends RecyclerView.Adapter<RecentActivityAd
|
|||
return activityList.size();
|
||||
}
|
||||
|
||||
static class ActivityViewHolder extends RecyclerView.ViewHolder {
|
||||
class ActivityViewHolder extends RecyclerView.ViewHolder {
|
||||
TextView user, action, title, time;
|
||||
ImageView image;
|
||||
ImageButton likeButton, commentButton;
|
||||
LinearLayout commentContainer;
|
||||
boolean isLiked = false;
|
||||
|
||||
public ActivityViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
|
@ -59,6 +93,26 @@ public class RecentActivityAdapter extends RecyclerView.Adapter<RecentActivityAd
|
|||
title = itemView.findViewById(R.id.activityTitle);
|
||||
time = itemView.findViewById(R.id.activityTime);
|
||||
image = itemView.findViewById(R.id.activityCover);
|
||||
likeButton = itemView.findViewById(R.id.likeButton);
|
||||
commentButton = itemView.findViewById(R.id.commentButton);
|
||||
commentContainer = itemView.findViewById(R.id.commentsContainer); // <- protección aplicada
|
||||
|
||||
likeButton.setOnClickListener(v -> {
|
||||
isLiked = !isLiked;
|
||||
likeButton.setImageResource(isLiked ? R.drawable.ic_heart_filled : R.drawable.ic_heart);
|
||||
likeButton.setColorFilter(isLiked
|
||||
? itemView.getContext().getColor(R.color.pink)
|
||||
: itemView.getContext().getColor(R.color.textPrimary));
|
||||
});
|
||||
|
||||
commentButton.setOnClickListener(v -> {
|
||||
RecentActivityModel activity = activityList.get(getAdapterPosition());
|
||||
int activityId = activity.getId();
|
||||
int userId = this.user.getId();
|
||||
|
||||
CommentDialog dialog = new CommentDialog(itemView.getContext(), userId, activityId, () -> {});
|
||||
dialog.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.santiparra.yomitrack.api.ApiClient;
|
|||
import com.santiparra.yomitrack.api.ApiService;
|
||||
import com.santiparra.yomitrack.db.entities.AnimeEntity;
|
||||
import com.santiparra.yomitrack.model.ApiResponse;
|
||||
import com.santiparra.yomitrack.ui.fragments.profile.FragmentProfile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -146,7 +147,7 @@ public class EditAnimeFragment extends Fragment {
|
|||
if (response.isSuccessful()) {
|
||||
String message = response.body() != null ? response.body().getMessage() : "Anime actualizado";
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
registrarActividad(anime.getTitle());
|
||||
registrarActividad(anime.getTitle(), anime.getImageUrl());
|
||||
requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.edit().putBoolean("refresh_profile", true).apply();
|
||||
requireActivity().getSupportFragmentManager().popBackStack();
|
||||
|
|
@ -165,14 +166,15 @@ public class EditAnimeFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void deleteAnime() {
|
||||
registrarActividadEliminacion(anime.getTitle(), anime.getImageUrl());
|
||||
|
||||
api.deleteAnime(anime.getId()).enqueue(new Callback<ApiResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
|
||||
if (!isAdded()) return;
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
String message = response.body() != null ? response.body().getMessage() : "Anime eliminado";
|
||||
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(requireContext(), "Anime eliminado", Toast.LENGTH_SHORT).show();
|
||||
requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.edit().putBoolean("refresh_profile", true).apply();
|
||||
requireActivity().getSupportFragmentManager().popBackStack();
|
||||
|
|
@ -183,35 +185,59 @@ public class EditAnimeFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onFailure(Call<ApiResponse> call, Throwable t) {
|
||||
Log.e("API_RESPONSE", "onFailure eliminar: " + t.getMessage(), t);
|
||||
if (!isAdded()) return;
|
||||
Toast.makeText(requireContext(), "Fallo en la conexión", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registrarActividad(String titulo) {
|
||||
int userId = requireContext()
|
||||
.getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.getInt("user_id", -1);
|
||||
|
||||
private void registrarActividad(String titulo, String imagen) {
|
||||
int userId = requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE).getInt("user_id", -1);
|
||||
if (userId == -1) return;
|
||||
|
||||
Map<String, Object> actividad = new HashMap<>();
|
||||
actividad.put("userId", userId);
|
||||
actividad.put("action", "editó un anime");
|
||||
actividad.put("action", "update de un anime");
|
||||
actividad.put("mediaTitle", titulo);
|
||||
actividad.put("imageUrl", anime.getImageUrl());
|
||||
actividad.put("imageUrl", imagen);
|
||||
|
||||
api.postActivity(actividad).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
Log.d("ACTIVITY_EDIT", "Actividad registrada: " + response.code());
|
||||
Log.d("ACTIVITY_DELETE", "Actividad de edicion registrada");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Log.e("ACTIVITY_EDIT", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
Log.e("ACTIVITY_DELETE", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registrarActividadEliminacion(String titulo, String imagen) {
|
||||
int userId = requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE).getInt("user_id", -1);
|
||||
if (userId == -1) return;
|
||||
|
||||
Map<String, Object> actividad = new HashMap<>();
|
||||
actividad.put("userId", userId);
|
||||
actividad.put("action", "eliminó un anime");
|
||||
actividad.put("mediaTitle", titulo);
|
||||
actividad.put("imageUrl", imagen);
|
||||
|
||||
api.postActivity(actividad).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
Log.d("ACTIVITY_DELETE", "Actividad de eliminación registrada");
|
||||
|
||||
|
||||
if (getParentFragment() instanceof FragmentProfile) {
|
||||
((FragmentProfile) getParentFragment()).loadActivity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Log.e("ACTIVITY_DELETE", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import com.santiparra.yomitrack.api.ApiClient;
|
|||
import com.santiparra.yomitrack.api.ApiService;
|
||||
import com.santiparra.yomitrack.db.entities.MangaEntity;
|
||||
import com.santiparra.yomitrack.model.ApiResponse;
|
||||
import com.santiparra.yomitrack.ui.fragments.profile.FragmentProfile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -141,7 +142,7 @@ public class EditMangaFragment extends Fragment {
|
|||
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
Toast.makeText(requireContext(), response.body().getMessage(), Toast.LENGTH_SHORT).show();
|
||||
registrarActividad(manga.getTitle());
|
||||
registrarActividad(manga.getTitle(), manga.getImageUrl());
|
||||
requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.edit().putBoolean("refresh_profile", true).apply();
|
||||
requireActivity().getSupportFragmentManager().popBackStack();
|
||||
|
|
@ -159,13 +160,15 @@ public class EditMangaFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void deleteManga() {
|
||||
registrarActividadEliminacionManga(manga.getTitle(), manga.getImageUrl());
|
||||
|
||||
api.deleteManga(manga.getId()).enqueue(new Callback<ApiResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
|
||||
if (!isAdded()) return;
|
||||
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
Toast.makeText(requireContext(), response.body().getMessage(), Toast.LENGTH_SHORT).show();
|
||||
if (response.isSuccessful()) {
|
||||
Toast.makeText(requireContext(), "Manga eliminado", Toast.LENGTH_SHORT).show();
|
||||
requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.edit().putBoolean("refresh_profile", true).apply();
|
||||
requireActivity().getSupportFragmentManager().popBackStack();
|
||||
|
|
@ -182,29 +185,55 @@ public class EditMangaFragment extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void registrarActividad(String titulo) {
|
||||
int userId = requireContext()
|
||||
.getSharedPreferences("user_session", Context.MODE_PRIVATE)
|
||||
.getInt("user_id", -1);
|
||||
|
||||
private void registrarActividad(String titulo, String imagen) {
|
||||
int userId = requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE).getInt("user_id", -1);
|
||||
if (userId == -1) return;
|
||||
|
||||
Map<String, Object> actividad = new HashMap<>();
|
||||
actividad.put("userId", userId);
|
||||
actividad.put("action", "editó un manga");
|
||||
actividad.put("action", "update de un manga");
|
||||
actividad.put("mediaTitle", titulo);
|
||||
actividad.put("imageUrl", manga.getImageUrl());
|
||||
actividad.put("imageUrl", imagen);
|
||||
|
||||
api.postActivity(actividad).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
Log.d("ACTIVITY_EDIT_MANGA", "Actividad registrada: " + response.code());
|
||||
Log.d("ACTIVITY_DELETE", "Actividad de edicion registrada");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Log.e("ACTIVITY_EDIT_MANGA", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
Log.e("ACTIVITY_DELETE", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void registrarActividadEliminacionManga(String titulo, String imagen) {
|
||||
int userId = requireContext().getSharedPreferences("user_session", Context.MODE_PRIVATE).getInt("user_id", -1);
|
||||
if (userId == -1) return;
|
||||
|
||||
Map<String, Object> actividad = new HashMap<>();
|
||||
actividad.put("userId", userId);
|
||||
actividad.put("action", "eliminó un manga");
|
||||
actividad.put("mediaTitle", titulo);
|
||||
actividad.put("imageUrl", imagen);
|
||||
|
||||
api.postActivity(actividad).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
Log.d("ACTIVITY_DELETE", "Actividad de eliminación registrada");
|
||||
|
||||
if (getParentFragment() instanceof FragmentProfile) {
|
||||
((FragmentProfile) getParentFragment()).loadActivity();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Log.e("ACTIVITY_DELETE", "Error al registrar actividad: " + t.getMessage(), t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,8 +76,8 @@ public class FragmentHome extends Fragment {
|
|||
activityRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
fullRecentActivity.addAll(Arrays.asList(
|
||||
new RecentActivityModel("Midca", "Read chapters 1 - 60 of", "Choujun! Choujou Senpai", "4 minutes ago", "https://i.imgur.com/7tZ0h8R.jpg"),
|
||||
new RecentActivityModel("prtrncyon", "Scored 9/10 on", "Chainsaw Man", "12 hours ago", "https://cdn.myanimelist.net/images/manga/2/253146.jpg")
|
||||
//new RecentActivityModel("Midca", "Read chapters 1 - 60 of", "Choujun! Choujou Senpai", "4 minutes ago", "https://i.imgur.com/7tZ0h8R.jpg"),
|
||||
//new RecentActivityModel("prtrncyon", "Scored 9/10 on", "Chainsaw Man", "12 hours ago", "https://cdn.myanimelist.net/images/manga/2/253146.jpg")
|
||||
// ... más datos simulados aquí
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ public class LoginFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loginAsGuest() {
|
||||
saveUserSession(-1, "Invitado");
|
||||
goToMainActivity();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.santiparra.yomitrack.ui.fragments.profile;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
|
|
@ -16,14 +15,17 @@ import androidx.annotation.Nullable;
|
|||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.santiparra.yomitrack.R;
|
||||
import com.santiparra.yomitrack.api.ApiClient;
|
||||
import com.santiparra.yomitrack.api.ApiService;
|
||||
import com.santiparra.yomitrack.model.CommentDialog;
|
||||
import com.santiparra.yomitrack.model.CommentModel;
|
||||
import com.santiparra.yomitrack.model.UserStatsResponse;
|
||||
import com.santiparra.yomitrack.utils.ActivityLog;
|
||||
import com.santiparra.yomitrack.utils.DateUtils;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -151,16 +153,22 @@ public class FragmentProfile extends Fragment {
|
|||
|
||||
private int getColorForStatus(String status) {
|
||||
switch (status.toLowerCase(Locale.ROOT)) {
|
||||
case "watching": return requireContext().getColor(R.color.status_watching);
|
||||
case "completed": return requireContext().getColor(R.color.status_completed);
|
||||
case "paused": return requireContext().getColor(R.color.status_paused);
|
||||
case "dropped": return requireContext().getColor(R.color.status_dropped);
|
||||
case "planning": return requireContext().getColor(R.color.status_planning);
|
||||
default: return requireContext().getColor(R.color.gray);
|
||||
case "watching":
|
||||
return requireContext().getColor(R.color.status_watching);
|
||||
case "completed":
|
||||
return requireContext().getColor(R.color.status_completed);
|
||||
case "paused":
|
||||
return requireContext().getColor(R.color.status_paused);
|
||||
case "dropped":
|
||||
return requireContext().getColor(R.color.status_dropped);
|
||||
case "planning":
|
||||
return requireContext().getColor(R.color.status_planning);
|
||||
default:
|
||||
return requireContext().getColor(R.color.gray);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadActivity() {
|
||||
public void loadActivity() {
|
||||
api.getActivityLog(userId).enqueue(new Callback<List<ActivityLog>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<ActivityLog>> call, Response<List<ActivityLog>> response) {
|
||||
|
|
@ -170,14 +178,97 @@ public class FragmentProfile extends Fragment {
|
|||
|
||||
for (ActivityLog log : response.body()) {
|
||||
View card = inflater.inflate(R.layout.item_activity_card, activityContainer, false);
|
||||
|
||||
LinearLayout commentsContainer = card.findViewById(R.id.commentsContainer);
|
||||
|
||||
commentsContainer.setVisibility(View.GONE);
|
||||
|
||||
card.setOnClickListener(v -> {
|
||||
if (commentsContainer.getVisibility() == View.VISIBLE) {
|
||||
commentsContainer.animate().alpha(0).setDuration(150).withEndAction(() -> {
|
||||
commentsContainer.setVisibility(View.GONE);
|
||||
}).start();
|
||||
} else {
|
||||
commentsContainer.setAlpha(0);
|
||||
commentsContainer.setVisibility(View.VISIBLE);
|
||||
loadComments(log.getId(), commentsContainer);
|
||||
commentsContainer.animate().alpha(1).setDuration(150).start();
|
||||
}
|
||||
});
|
||||
|
||||
((TextView) card.findViewById(R.id.activityUser)).setText(username);
|
||||
((TextView) card.findViewById(R.id.activityAction)).setText(log.getAction());
|
||||
((TextView) card.findViewById(R.id.activityTitle)).setText(log.getMediaTitle());
|
||||
((TextView) card.findViewById(R.id.activityTime)).setText(log.getTimestamp());
|
||||
((TextView) card.findViewById(R.id.activityTime)).setText(DateUtils.getRelativeTime(log.getTimestamp()));
|
||||
|
||||
ImageView coverImage = card.findViewById(R.id.activityCover);
|
||||
if (!TextUtils.isEmpty(log.getImageUrl())) {
|
||||
Glide.with(requireContext()).load(log.getImageUrl()).into((ImageView) card.findViewById(R.id.activityCover));
|
||||
Glide.with(requireContext())
|
||||
.load(log.getImageUrl())
|
||||
.placeholder(R.drawable.placeholder_image)
|
||||
.error(R.drawable.placeholder_image)
|
||||
.into(coverImage);
|
||||
}
|
||||
|
||||
ImageButton commentButton = card.findViewById(R.id.commentButton);
|
||||
ImageButton likeButton = card.findViewById(R.id.likeButton);
|
||||
|
||||
commentButton.setOnClickListener(v -> {
|
||||
CommentDialog dialog = new CommentDialog(requireContext(), userId, log.getId(), () -> {
|
||||
loadComments(log.getId(), card.findViewById(R.id.commentsContainer));
|
||||
});
|
||||
dialog.show();
|
||||
});
|
||||
|
||||
api.checkLike(userId, log.getId()).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
final boolean[] isLiked = {response.body().get("liked").getAsBoolean()};
|
||||
actualizarCorazon(likeButton, isLiked[0]);
|
||||
|
||||
likeButton.setOnClickListener(v -> {
|
||||
if (isLiked[0]) {
|
||||
api.deleteLike(createLikeJson(userId, log.getId())).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
if (response.isSuccessful()) {
|
||||
isLiked[0] = false;
|
||||
actualizarCorazon(likeButton, false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Toast.makeText(getContext(), "Error de conexión", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
api.postLike(createLikeJson(userId, log.getId())).enqueue(new Callback<JsonObject>() {
|
||||
@Override
|
||||
public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
|
||||
if (response.isSuccessful()) {
|
||||
isLiked[0] = true;
|
||||
actualizarCorazon(likeButton, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Toast.makeText(getContext(), "Error de conexión", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<JsonObject> call, Throwable t) {
|
||||
Toast.makeText(getContext(), "Error al verificar like", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
activityContainer.addView(card);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +276,7 @@ public class FragmentProfile extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onFailure(Call<List<ActivityLog>> call, Throwable t) {
|
||||
Toast.makeText(getContext(), "Error al cargar actividad", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(getContext(), "Fallo al cargar actividad", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -219,6 +310,65 @@ public class FragmentProfile extends Fragment {
|
|||
});
|
||||
}
|
||||
|
||||
private void loadComments(int activityId, LinearLayout container) {
|
||||
api.getCommentsByActivity(activityId).enqueue(new Callback<List<CommentModel>>() {
|
||||
@Override
|
||||
public void onResponse(Call<List<CommentModel>> call, Response<List<CommentModel>> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
container.removeAllViews();
|
||||
LayoutInflater inflater = LayoutInflater.from(getContext());
|
||||
|
||||
for (CommentModel comment : response.body()) {
|
||||
View commentView = LayoutInflater.from(getContext())
|
||||
.inflate(R.layout.item_comment, container, false);
|
||||
|
||||
TextView usernameView = commentView.findViewById(R.id.commentUsername);
|
||||
TextView commentText = commentView.findViewById(R.id.commentText);
|
||||
TextView dateView = commentView.findViewById(R.id.commentDate);
|
||||
ImageView avatar = commentView.findViewById(R.id.commentAvatar);
|
||||
|
||||
usernameView.setText(comment.getUsername());
|
||||
commentText.setText(comment.getText());
|
||||
dateView.setText(DateUtils.getRelativeTime(comment.getCreatedAt())); // usa tu util
|
||||
|
||||
if (!TextUtils.isEmpty(comment.getAvatarUrl())) {
|
||||
Glide.with(getContext())
|
||||
.load(comment.getAvatarUrl())
|
||||
.placeholder(R.drawable.rectangle_placeholder)
|
||||
.error(R.drawable.error_image)
|
||||
.into(avatar);
|
||||
}
|
||||
|
||||
container.addView(commentView);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<List<CommentModel>> call, Throwable t) {
|
||||
Toast.makeText(getContext(), "Error al cargar comentarios", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private JsonObject createLikeJson(int userId, int activityId) {
|
||||
JsonObject body = new JsonObject();
|
||||
body.addProperty("userId", userId);
|
||||
body.addProperty("activityId", activityId);
|
||||
return body;
|
||||
}
|
||||
|
||||
private void actualizarCorazon(ImageButton likeButton, boolean liked) {
|
||||
if (liked) {
|
||||
likeButton.setImageResource(R.drawable.ic_heart_filled);
|
||||
likeButton.setColorFilter(requireContext().getColor(R.color.pink));
|
||||
} else {
|
||||
likeButton.setImageResource(R.drawable.ic_heart_outline);
|
||||
likeButton.setColorFilter(requireContext().getColor(R.color.gray));
|
||||
}
|
||||
}
|
||||
|
||||
private void saveBiography() {
|
||||
bioPrefs.edit().putString(BIO_KEY, editBiography.getText().toString().trim()).apply();
|
||||
Toast.makeText(getContext(), "Biografía guardada", Toast.LENGTH_SHORT).show();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.google.gson.annotations.SerializedName;
|
|||
|
||||
public class ActivityLog {
|
||||
|
||||
@SerializedName("id")
|
||||
private int id;
|
||||
@SerializedName("action")
|
||||
private String action;
|
||||
|
||||
|
|
@ -13,16 +15,26 @@ public class ActivityLog {
|
|||
@SerializedName("timestamp")
|
||||
private String timestamp;
|
||||
|
||||
@SerializedName("imagenUrl")
|
||||
@SerializedName("imageUrl")
|
||||
private String imageUrl;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public String getMediaTitle() {
|
||||
return mediaTitle;
|
||||
}
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public String getAction() { return action; }
|
||||
|
||||
public String getMediaTitle() { return mediaTitle; }
|
||||
|
||||
public String getTimestamp() { return timestamp; }
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB |
|
|
@ -1,125 +1,97 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<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:id="@+id/activityCard"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardCornerRadius="16dp"
|
||||
app:cardElevation="6dp"
|
||||
android:backgroundTint="@color/primary">
|
||||
android:layout_margin="12dp"
|
||||
app:cardCornerRadius="24dp"
|
||||
app:cardElevation="8dp"
|
||||
app:cardBackgroundColor="@color/primary">
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="12dp">
|
||||
|
||||
<!-- Imagen de portada -->
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/activityCover"
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="110dp"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="90dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/sample_cover"
|
||||
android:layout_alignParentStart="true" />
|
||||
android:src="@drawable/placeholder_image"
|
||||
android:layout_marginEnd="12dp" />
|
||||
|
||||
<!-- Layout de contenido -->
|
||||
<LinearLayout
|
||||
android:id="@+id/contentLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/activityCover"
|
||||
android:layout_marginStart="12dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_alignTop="@id/activityCover"
|
||||
android:layout_alignBottom="@id/activityCover"
|
||||
android:layout_marginEnd="36dp">
|
||||
|
||||
<!-- Usuario y hora -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activityUser"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Usuario"
|
||||
android:textColor="@color/textPrimary"
|
||||
android:textStyle="bold"
|
||||
android:text="Usuario"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
<TextView
|
||||
android:id="@+id/activityAction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="completó"
|
||||
android:textSize="13sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activityTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Nombre del anime o manga"
|
||||
android:textSize="13sp"
|
||||
android:maxLines="2"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/activityTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="5 minutes ago"
|
||||
android:textColor="@color/textPrimary"
|
||||
android:textSize="13sp" />
|
||||
android:text="hace 3 horas"
|
||||
android:textSize="12sp"
|
||||
android:textColor="@color/gray"
|
||||
android:layout_marginTop="4dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Acción -->
|
||||
<TextView
|
||||
android:id="@+id/activityAction"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Scored 9/10 on"
|
||||
android:textColor="@color/textPrimary"
|
||||
android:textSize="14sp" />
|
||||
<ImageButton
|
||||
android:id="@+id/likeButton"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_heart_outline"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
app:tint="@color/gray" />
|
||||
|
||||
<!-- Título -->
|
||||
<TextView
|
||||
android:id="@+id/activityTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Chainsaw Man"
|
||||
android:textColor="@color/activeTint"
|
||||
android:textStyle="bold"
|
||||
android:textSize="14sp"
|
||||
android:layout_marginBottom="8dp" />
|
||||
|
||||
<!-- Mini foto de perfil -->
|
||||
<ImageView
|
||||
android:id="@+id/activityMiniThumb"
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_profile"
|
||||
android:background="@drawable/circle_mask"
|
||||
android:clipToOutline="true" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Iconos de comentario y like -->
|
||||
<LinearLayout
|
||||
android:id="@+id/activityActions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_alignBottom="@+id/activityCover"
|
||||
android:layout_alignParentEnd="true">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
<ImageButton
|
||||
android:id="@+id/commentButton"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_comment"
|
||||
app:tint="@color/textPrimary" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:src="@drawable/ic_heart"
|
||||
app:tint="@color/textPrimary" />
|
||||
app:tint="@color/gray" />
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
<LinearLayout
|
||||
android:id="@+id/commentsContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:layout_marginTop="4dp" />
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
android:layout_height="170dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:clipToOutline="true"
|
||||
android:background="@drawable/sample_cover" />
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTitle"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
<color name="background">#121926</color>
|
||||
<color name="textPrimary">#FFFFFF</color>
|
||||
<color name="gray">#808080</color>
|
||||
<color name="activeTint">#F26D50</color> <!-- estilo AniList -->
|
||||
<color name="activeTint">#F26D50</color>
|
||||
<color name="pink">#FF4081</color>
|
||||
|
||||
<!-- Colores por estado anime -->
|
||||
<color name="status_completed">#4CAF50</color> <!-- verde -->
|
||||
|
|
|
|||
|
|
@ -52,4 +52,8 @@
|
|||
<item name="statusDot" type="id" />
|
||||
<item name="editSearch" type="id" />
|
||||
<item name="animeStatText" type="id" />
|
||||
<item name="commentsContainer" type="id" />
|
||||
<item name="commentButton" type="id" />
|
||||
<item name="likeButton" type="id" />
|
||||
<item name="activityCover" type="id" />
|
||||
</resources>
|
||||
|
|
@ -7,6 +7,8 @@
|
|||
<string name="profile">\n</string>
|
||||
<string name="write_a_status">Write a status...</string>
|
||||
<string name="show_more" />
|
||||
<string name="cover_image" />
|
||||
<string name="like_comment" />
|
||||
<string-array name="media_types">
|
||||
<item>Anime</item>
|
||||
<item>Manga</item>
|
||||
|
|
|
|||
Loading…
Reference in New Issue