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
b7770c9fc6
commit
589b948054
|
|
@ -0,0 +1,176 @@
|
||||||
|
package com.santiparra.yomitrack.model.adapters.anilist_adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.santiparra.yomitrack.R;
|
||||||
|
import com.santiparra.yomitrack.api.ApiClient;
|
||||||
|
import com.santiparra.yomitrack.api.ApiService;
|
||||||
|
import com.santiparra.yomitrack.db.entities.AnimeEntity;
|
||||||
|
import com.santiparra.yomitrack.db.entities.MangaEntity;
|
||||||
|
import com.santiparra.yomitrack.model.AniListMedia;
|
||||||
|
import com.santiparra.yomitrack.utils.ActivityLog;
|
||||||
|
import com.santiparra.yomitrack.utils.DateUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
public class AniListSearchAdapter extends RecyclerView.Adapter<AniListSearchAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
private final List<AniListMedia> mediaList;
|
||||||
|
private final Context context;
|
||||||
|
private final String mediaType;
|
||||||
|
|
||||||
|
public AniListSearchAdapter(Context context, List<AniListMedia> mediaList, String mediaType) {
|
||||||
|
this.context = context;
|
||||||
|
this.mediaList = mediaList;
|
||||||
|
this.mediaType = mediaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(context).inflate(R.layout.item_anilist_search, parent, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
AniListMedia item = mediaList.get(position);
|
||||||
|
holder.title.setText(item.getTitle());
|
||||||
|
|
||||||
|
Glide.with(context).load(item.getImageUrl()).into(holder.cover);
|
||||||
|
|
||||||
|
holder.btnAdd.setOnClickListener(v -> {
|
||||||
|
SharedPreferences prefs = context.getSharedPreferences("user_session", Context.MODE_PRIVATE);
|
||||||
|
int userId = prefs.getInt("user_id", -1);
|
||||||
|
|
||||||
|
if (userId == -1) {
|
||||||
|
Toast.makeText(context, "Función solo disponible para usuarios registrados", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiService apiService = ApiClient.getClient().create(ApiService.class);
|
||||||
|
|
||||||
|
if (mediaType.equals("ANIME")) {
|
||||||
|
AnimeEntity anime = new AnimeEntity(
|
||||||
|
item.getId(),
|
||||||
|
item.getTitle(),
|
||||||
|
"Watching",
|
||||||
|
userId,
|
||||||
|
item.getImageUrl(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
anime.setType("TV");
|
||||||
|
|
||||||
|
apiService.insertAnime(anime).enqueue(new Callback<>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) {
|
||||||
|
Toast.makeText(context, "Anime añadido", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
// 🔁 Registrar actividad usando Map
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("userId", userId);
|
||||||
|
body.put("action", "añadió");
|
||||||
|
body.put("mediaTitle", item.getTitle());
|
||||||
|
body.put("timestamp", DateUtils.getCurrentTimestamp());
|
||||||
|
body.put("imageUrl", item.getImageUrl());
|
||||||
|
|
||||||
|
apiService.postActivity(body).enqueue(new Callback<>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, Throwable t) {
|
||||||
|
Toast.makeText(context, "Error al añadir anime", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
MangaEntity manga = new MangaEntity(
|
||||||
|
item.getId(),
|
||||||
|
item.getTitle(),
|
||||||
|
"Reading",
|
||||||
|
userId,
|
||||||
|
item.getImageUrl(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
manga.setType("Manga");
|
||||||
|
|
||||||
|
apiService.insertManga(manga).enqueue(new Callback<>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) {
|
||||||
|
Toast.makeText(context, "Manga añadido", Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("userId", userId);
|
||||||
|
body.put("action", "añadió");
|
||||||
|
body.put("mediaTitle", item.getTitle());
|
||||||
|
body.put("timestamp", DateUtils.getCurrentTimestamp());
|
||||||
|
body.put("imageUrl", item.getImageUrl());
|
||||||
|
|
||||||
|
apiService.postActivity(body).enqueue(new Callback<>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call call, Response response) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call call, Throwable t) {
|
||||||
|
Toast.makeText(context, "Error al añadir manga", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return mediaList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
TextView title;
|
||||||
|
ImageView cover;
|
||||||
|
Button btnAdd;
|
||||||
|
|
||||||
|
public ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
title = itemView.findViewById(R.id.itemTitle);
|
||||||
|
cover = itemView.findViewById(R.id.itemImage);
|
||||||
|
btnAdd = itemView.findViewById(R.id.btnAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
package com.santiparra.yomitrack.model.adapters.homeadapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
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.cardview.widget.CardView;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
|
import com.santiparra.yomitrack.R;
|
||||||
|
import com.santiparra.yomitrack.model.ItemModel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class HomeCardAdapter extends RecyclerView.Adapter<HomeCardAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
public interface OnItemClickListener {
|
||||||
|
void onItemClick(ItemModel item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final List<ItemModel> itemList;
|
||||||
|
private final OnItemClickListener listener;
|
||||||
|
|
||||||
|
public HomeCardAdapter(List<ItemModel> itemList, OnItemClickListener listener) {
|
||||||
|
this.itemList = itemList;
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_home_card, parent, false);
|
||||||
|
return new ViewHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
||||||
|
ItemModel item = itemList.get(position);
|
||||||
|
holder.title.setText(item.getTitle());
|
||||||
|
holder.progress.setText(item.getProgress());
|
||||||
|
Glide.with(holder.itemView.getContext()).load(item.getImageUrl()).into(holder.cover);
|
||||||
|
|
||||||
|
holder.card.setOnClickListener(v -> listener.onItemClick(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return itemList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
TextView title, progress;
|
||||||
|
ImageView cover;
|
||||||
|
CardView card;
|
||||||
|
|
||||||
|
public ViewHolder(@NonNull View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
title = itemView.findViewById(R.id.itemTitle);
|
||||||
|
progress = itemView.findViewById(R.id.itemProgress);
|
||||||
|
cover = itemView.findViewById(R.id.itemImage);
|
||||||
|
card = itemView.findViewById(R.id.cardItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="@color/primary"/>
|
||||||
|
<corners android:radius="24dp"/>
|
||||||
|
</shape>
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M10,9V5L3,12l7,7v-4c4.55,0 7.5,1.43 9.5,4.29 -1.14,-4.57 -4.34,-8.29 -9.5,-8.29z" />
|
||||||
|
</vector>
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
card_view:cardCornerRadius="16dp"
|
||||||
|
card_view:cardElevation="6dp"
|
||||||
|
android:layout_margin="8dp"
|
||||||
|
card_view:cardBackgroundColor="@color/primary">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="12dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/itemImage"
|
||||||
|
android:layout_width="90dp"
|
||||||
|
android:layout_height="130dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:layout_marginEnd="12dp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/itemTitle"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Título"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:ellipsize="end"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAdd"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="AÑADIR"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:backgroundTint="#3A3D42"
|
||||||
|
android:textColor="@android:color/white"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/cardItem"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:backgroundTint="@color/primary"
|
||||||
|
android:elevation="4dp"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:padding="8dp">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/itemImage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="180dp"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:contentDescription="@string/cover_image" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/itemTitle"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/textPrimary"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:maxLines="2"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:text="Title" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/itemProgress"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/textPrimary"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
|
android:text="0/0" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
Loading…
Reference in New Issue