From 07b617a19524ff451175f4c1f6a9f39441f19837 Mon Sep 17 00:00:00 2001 From: santi Date: Tue, 6 May 2025 16:07:11 +0200 Subject: [PATCH] Optimizacion de los xml y implemetacion de nuevas clases y optimizacion igualmente de classes antiguas --- .../adapters/homeadapter/HomeAdapter.java | 14 +- .../sectionadapter/SectionAdapter.java | 3 +- .../santiparra/yomitrack/ui/MainActivity.java | 1 - .../ui/fragments/home/FragmentHome.java | 42 +++- .../ui/fragments/profile/FragmentProfile.java | 129 ++++++++++++- app/src/main/res/layout/activity_main.xml | 9 +- app/src/main/res/layout/fragment_home.xml | 63 ++++-- app/src/main/res/layout/fragment_profile.xml | 182 +++++++++++++++++- app/src/main/res/layout/item_anime_card.xml | 39 ---- app/src/main/res/layout/item_manga_card.xml | 37 ---- app/src/main/res/layout/item_section.xml | 22 ++- app/src/main/res/values/colors.xml | 9 + app/src/main/res/values/ids.xml | 11 ++ app/src/main/res/values/strings.xml | 2 + 14 files changed, 435 insertions(+), 128 deletions(-) delete mode 100644 app/src/main/res/layout/item_anime_card.xml delete mode 100644 app/src/main/res/layout/item_manga_card.xml diff --git a/app/src/main/java/com/santiparra/yomitrack/model/adapters/homeadapter/HomeAdapter.java b/app/src/main/java/com/santiparra/yomitrack/model/adapters/homeadapter/HomeAdapter.java index a7dc85f..8bdd29c 100644 --- a/app/src/main/java/com/santiparra/yomitrack/model/adapters/homeadapter/HomeAdapter.java +++ b/app/src/main/java/com/santiparra/yomitrack/model/adapters/homeadapter/HomeAdapter.java @@ -1,4 +1,4 @@ -package com.santiparra.yomitrack.ui.adapters; // Ajusta tu paquete si es necesario +package com.santiparra.yomitrack.model.adapters.homeadapter; // Ajusta tu paquete si es necesario import android.view.LayoutInflater; import android.view.View; @@ -39,13 +39,17 @@ public class HomeAdapter extends RecyclerView.Adapter { @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_media_card, parent, false); + + // Ajustamos manualmente el ancho + ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); + layoutParams.width = (int) (parent.getMeasuredWidth() * 0.85); // 85% del ancho de pantalla + view.setLayoutParams(layoutParams); + if (viewType == TYPE_AIRING) { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_anime_horizontal_card, parent, false); return new AiringViewHolder(view); } else { - View view = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_anime_card, parent, false); return new AnimeViewHolder(view); } } diff --git a/app/src/main/java/com/santiparra/yomitrack/model/adapters/sectionadapter/SectionAdapter.java b/app/src/main/java/com/santiparra/yomitrack/model/adapters/sectionadapter/SectionAdapter.java index 87a021c..f6aeb68 100644 --- a/app/src/main/java/com/santiparra/yomitrack/model/adapters/sectionadapter/SectionAdapter.java +++ b/app/src/main/java/com/santiparra/yomitrack/model/adapters/sectionadapter/SectionAdapter.java @@ -10,8 +10,8 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.santiparra.yomitrack.model.ItemModel; -import com.santiparra.yomitrack.ui.adapters.HomeAdapter; import com.santiparra.yomitrack.R; +import com.santiparra.yomitrack.model.adapters.homeadapter.HomeAdapter; import java.util.List; import java.util.Map; @@ -41,6 +41,7 @@ public class SectionAdapter extends RecyclerView.Adapter { int itemId = item.getItemId(); diff --git a/app/src/main/java/com/santiparra/yomitrack/ui/fragments/home/FragmentHome.java b/app/src/main/java/com/santiparra/yomitrack/ui/fragments/home/FragmentHome.java index 0d843d9..253f05b 100644 --- a/app/src/main/java/com/santiparra/yomitrack/ui/fragments/home/FragmentHome.java +++ b/app/src/main/java/com/santiparra/yomitrack/ui/fragments/home/FragmentHome.java @@ -2,13 +2,18 @@ package com.santiparra.yomitrack.ui.fragments.home; import android.os.Bundle; import android.view.View; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.cardview.widget.CardView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.bumptech.glide.Glide; import com.santiparra.yomitrack.R; import com.santiparra.yomitrack.model.ItemModel; import com.santiparra.yomitrack.model.adapters.sectionadapter.SectionAdapter; @@ -29,6 +34,7 @@ public class FragmentHome extends Fragment { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + // RecyclerView principal RecyclerView mainRecyclerView = view.findViewById(R.id.mainRecyclerView); // Crear las secciones @@ -36,11 +42,10 @@ public class FragmentHome extends Fragment { "Airing", "Anime in Progress", "Manga in Progress" ); - // Crear el contenido de cada sección como List Map> sectionItems = new HashMap<>(); List airingItems = new ArrayList<>(); - airingItems.add(new ItemModel("Naruto", "5/220", "https://i.imgur.com/N5uCbDu.jpg", ItemModel.ContentType.ANIME)); + airingItems.add(new ItemModel("Naruto", "5/220", "https://th.bing.com/th/id/OIP.aypxRH6Qq7yXLFCXiYhaKAHaLo?rs=1&pid=ImgDetMain", ItemModel.ContentType.ANIME)); airingItems.add(new ItemModel("One Piece", "900/1100", "https://i.imgur.com/VgVfG6K.jpg", ItemModel.ContentType.ANIME)); airingItems.add(new ItemModel("Bleach", "100/366", "https://i.imgur.com/I0d1HyA.jpg", ItemModel.ContentType.ANIME)); @@ -52,14 +57,43 @@ public class FragmentHome extends Fragment { mangaInProgressItems.add(new ItemModel("Chainsaw Man", "45/100", "https://i.imgur.com/7tZ0h8R.jpg", ItemModel.ContentType.MANGA)); mangaInProgressItems.add(new ItemModel("Berserk", "370/380", "https://i.imgur.com/8FJYYHo.jpg", ItemModel.ContentType.MANGA)); - // Asignar los items a las secciones sectionItems.put("Airing", airingItems); sectionItems.put("Anime in Progress", animeInProgressItems); sectionItems.put("Manga in Progress", mangaInProgressItems); - // Configurar RecyclerView SectionAdapter adapter = new SectionAdapter(sectionTitles, sectionItems); mainRecyclerView.setLayoutManager(new LinearLayoutManager(getContext())); mainRecyclerView.setAdapter(adapter); + + // Sección inferior: campo de estado + nueva card + EditText editStatus = view.findViewById(R.id.editStatus); + + View activityCard = view.findViewById(R.id.activityCard); + ImageView activityImage = activityCard.findViewById(R.id.activityImage); + TextView activityUser = activityCard.findViewById(R.id.activityUser); + TextView activityAction = activityCard.findViewById(R.id.activityAction); + TextView activityTitle = activityCard.findViewById(R.id.activityTitle); + TextView activityTime = activityCard.findViewById(R.id.activityTime); + + // Contenido inicial + activityUser.setText("Midca"); + activityAction.setText("Read chapters 1 - 60 of"); + activityTitle.setText("Choujun! Choujou Senpai"); + activityTime.setText("4 minutes ago"); + + Glide.with(requireContext()) + .load("https://i.imgur.com/7tZ0h8R.jpg") + .placeholder(R.drawable.placeholder_image) + .error(R.drawable.error_image) + .into(activityImage); + + // Actualización con el texto del usuario + editStatus.setOnEditorActionListener((v, actionId, event) -> { + String status = editStatus.getText().toString().trim(); + if (!status.isEmpty()) { + activityAction.setText(status); + } + return true; + }); } } diff --git a/app/src/main/java/com/santiparra/yomitrack/ui/fragments/profile/FragmentProfile.java b/app/src/main/java/com/santiparra/yomitrack/ui/fragments/profile/FragmentProfile.java index 524da11..913bda9 100644 --- a/app/src/main/java/com/santiparra/yomitrack/ui/fragments/profile/FragmentProfile.java +++ b/app/src/main/java/com/santiparra/yomitrack/ui/fragments/profile/FragmentProfile.java @@ -4,15 +4,138 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import com.santiparra.yomitrack.R; +import com.santiparra.yomitrack.model.UserStats; +import com.santiparra.yomitrack.utils.StatsHelper; + +import java.util.List; public class FragmentProfile extends Fragment { + + public FragmentProfile() {} + @Override - public View onCreateView(LayoutInflater layoutInflater, ViewGroup container, - Bundle saveInstanceState){ - return layoutInflater.inflate(R.layout.fragment_profile,container,false); + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_profile, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + TextView usernameText = view.findViewById(R.id.usernameText); + TextView descriptionText = view.findViewById(R.id.descriptionText); + LinearLayout statsContainer = view.findViewById(R.id.animeStatsContainer); + + usernameText.setText("BtwIsSanti"); + descriptionText.setText("Eiko is my waifu right now\nMai and Mikasa is my second wife"); + + // Cargar estadísticas simuladas + List statsList = StatsHelper.getAnimeStats(); + + for (UserStats stat : statsList) { + View statView = LayoutInflater.from(getContext()) + .inflate(R.layout.item_stat_bar, statsContainer, false); + + TextView label = statView.findViewById(R.id.statLabelFull); + ProgressBar bar = statView.findViewById(R.id.statProgressBar); + + label.setText(stat.getCategory() + " • " + stat.getCount()); + bar.setProgress(stat.getPercentage()); + + // Aplicar color distinto por categoría + int colorRes = R.color.primary; // default + switch (stat.getCategory()) { + case "Watching": + colorRes = R.color.statWatching; + break; + case "Completed": + colorRes = R.color.statCompleted; + break; + case "On Hold": + colorRes = R.color.statOnHold; + break; + case "Dropped": + colorRes = R.color.statDropped; + break; + case "Plan to Watch": + colorRes = R.color.statPlanToWatch; + break; + } + + bar.setProgressTintList(ContextCompat.getColorStateList(requireContext(), colorRes)); + statsContainer.addView(statView); + } + + // Agregar tarjetas de actividad (opcional) + LinearLayout activityContainer = view.findViewById(R.id.activityContainer); + + if (activityContainer != null) { + // Lista simulada de updates + String[] activities = { + "Watched episode 5 of Kakushite! Makina-san!!", + "Watched episode 5 of Chotto dake Ai ga Omo...", + "Watched episode 4 of Go-Toubun no Hanayome", + "Watched episode 3 of Kanojo, Okarishimasu", + "Watched episode 12 of Jujutsu Kaisen", + "Watched episode 8 of Bleach: TYBW", + "Watched episode 1 of Chainsaw Man", + "Watched episode 10 of Dr. Stone", + "Watched episode 9 of Mushoku Tensei", + "Watched episode 11 of Ousama Ranking", + "Watched episode 7 of HUNTER×HUNTER" // Se ignora si hay más de 10 + }; + + int limit = Math.min(10, activities.length); + + for (int i = 0; i < limit; i++) { + View card = LayoutInflater.from(getContext()) + .inflate(R.layout.item_activity, activityContainer, false); + + TextView text = card.findViewById(R.id.activityText); + TextView time = card.findViewById(R.id.activityTime); + + text.setText(activities[i]); + time.setText("16 hours ago"); + + activityContainer.addView(card); + } + } + + // Estadísticas de manga + LinearLayout mangaStatsContainer = view.findViewById(R.id.mangaStatsContainer); + List mangaStats = StatsHelper.getMangaStats(); + + for (UserStats stat : mangaStats) { + View statView = LayoutInflater.from(getContext()) + .inflate(R.layout.item_stat_bar, mangaStatsContainer, false); + + TextView label = statView.findViewById(R.id.statLabelFull); + ProgressBar bar = statView.findViewById(R.id.statProgressBar); + + label.setText(stat.getCategory() + " • " + stat.getCount()); + bar.setProgress(stat.getPercentage()); + + int colorRes = R.color.primary; + switch (stat.getCategory()) { + case "Reading": colorRes = R.color.statWatching; break; + case "Completed": colorRes = R.color.statCompleted; break; + case "On Hold": colorRes = R.color.statOnHold; break; + case "Dropped": colorRes = R.color.statDropped; break; + case "Plan to Read": colorRes = R.color.statPlanToWatch; break; + } + + bar.setProgressTintList(ContextCompat.getColorStateList(requireContext(), colorRes)); + mangaStatsContainer.addView(statView); + } + } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 586a536..6373187 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -19,6 +19,7 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="85dp" + android:layout_marginTop="0dp" android:background="@color/primary"> + android:scaleType="fitCenter" + android:src="@drawable/logo_yomitrack" /> + android:src="@drawable/ic_profile" /> diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 55ecc25..f135dda 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -1,27 +1,60 @@ + + tools:context=".ui.fragments.home.FragmentHome"> - - + - + + + + + + + + diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 8321316..1ee000c 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -1,16 +1,178 @@ - + + android:padding="16dp"> - + android:layout_height="wrap_content" + android:paddingBottom="80dp"> - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/item_anime_card.xml b/app/src/main/res/layout/item_anime_card.xml deleted file mode 100644 index 59f56a4..0000000 --- a/app/src/main/res/layout/item_anime_card.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/item_manga_card.xml b/app/src/main/res/layout/item_manga_card.xml deleted file mode 100644 index a4da23e..0000000 --- a/app/src/main/res/layout/item_manga_card.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - diff --git a/app/src/main/res/layout/item_section.xml b/app/src/main/res/layout/item_section.xml index 5bd0b26..05eb5a1 100644 --- a/app/src/main/res/layout/item_section.xml +++ b/app/src/main/res/layout/item_section.xml @@ -1,27 +1,31 @@ + android:paddingHorizontal="16dp" + android:paddingTop="12dp" + android:paddingBottom="0dp"> + android:paddingBottom="8dp" /> + android:paddingStart="8dp" + android:paddingEnd="8dp" + android:overScrollMode="never" + android:nestedScrollingEnabled="false" + android:orientation="horizontal" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index b576025..d001ccf 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,4 +3,13 @@ #1F2937 #121926 #FFFFFF + #808080 + + + #3db4f2 + #16c98d + #f5a623 + #f45b69 + #c678dd + \ No newline at end of file diff --git a/app/src/main/res/values/ids.xml b/app/src/main/res/values/ids.xml index 1c68781..d8b0210 100644 --- a/app/src/main/res/values/ids.xml +++ b/app/src/main/res/values/ids.xml @@ -6,4 +6,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 20c4361..cb06f31 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,4 +4,6 @@ Media Image + \n + Write a status... \ No newline at end of file