Optimizacion de los xml y implemetacion de nuevas clases y optimizacion igualmente de classes antiguas
This commit is contained in:
parent
be4f0cfc33
commit
c497403142
|
|
@ -44,4 +44,8 @@ dependencies {
|
|||
testImplementation(libs.junit)
|
||||
androidTestImplementation(libs.ext.junit)
|
||||
androidTestImplementation(libs.espresso.core)
|
||||
|
||||
/*Dependecia para usar glide y cargar imagenes mediante url*/
|
||||
implementation("com.github.bumptech.glide:glide:4.16.0")
|
||||
annotationProcessor("com.github.bumptech.glide:compiler:4.16.0")
|
||||
}
|
||||
|
|
@ -2,6 +2,9 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Agregado el permiso de Internet -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
|
|
|
|||
|
|
@ -1,47 +1,68 @@
|
|||
package com.santiparra.yomitrack.model.adapters.homeadapter;
|
||||
package com.santiparra.yomitrack.ui.adapters; // Ajusta tu paquete si es necesario
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.santiparra.yomitrack.R;
|
||||
import com.santiparra.yomitrack.model.ItemModel;
|
||||
import com.santiparra.yomitrack.model.adapters.airing.AiringViewHolder;
|
||||
import com.santiparra.yomitrack.model.adapters.airing.AnimeViewHolder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
|
||||
public class HomeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Integer> imageList;
|
||||
private List<ItemModel> itemList;
|
||||
private String sectionTitle; // Para saber si es Airing o no
|
||||
|
||||
public HomeAdapter(List<Integer> imageList) {
|
||||
this.imageList = imageList;
|
||||
private static final int TYPE_AIRING = 0;
|
||||
private static final int TYPE_ANIME_MANGA = 1;
|
||||
|
||||
public HomeAdapter(List<ItemModel> itemList, String sectionTitle) {
|
||||
this.itemList = itemList;
|
||||
this.sectionTitle = sectionTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (sectionTitle.equalsIgnoreCase("Airing")) {
|
||||
return TYPE_AIRING;
|
||||
} else {
|
||||
return TYPE_ANIME_MANGA;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public HomeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_anime_card, parent, false);
|
||||
return new ViewHolder(view);
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull HomeAdapter.ViewHolder holder, int position) {
|
||||
holder.imageView.setImageResource(imageList.get(position));
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
ItemModel item = itemList.get(position);
|
||||
|
||||
if (holder instanceof AiringViewHolder) {
|
||||
((AiringViewHolder) holder).bind(item);
|
||||
} else if (holder instanceof AnimeViewHolder) {
|
||||
((AnimeViewHolder) holder).bind(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return imageList.size();
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView imageView;
|
||||
public ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
imageView = itemView.findViewById(R.id.imageView);
|
||||
}
|
||||
return itemList.size();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ import androidx.annotation.NonNull;
|
|||
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;
|
||||
|
|
@ -18,9 +19,9 @@ import java.util.Map;
|
|||
public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionViewHolder> {
|
||||
|
||||
private final List<String> sectionTitles;
|
||||
private final Map<String, List<Integer>> sectionImages;
|
||||
private final Map<String, List<ItemModel>> sectionImages;
|
||||
|
||||
public SectionAdapter(List<String> sectionTitles, Map<String, List<Integer>> sectionImages) {
|
||||
public SectionAdapter(List<String> sectionTitles, Map<String, List<ItemModel>> sectionImages) {
|
||||
this.sectionTitles = sectionTitles;
|
||||
this.sectionImages = sectionImages;
|
||||
}
|
||||
|
|
@ -35,11 +36,11 @@ public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionV
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
|
||||
String title = sectionTitles.get(position);
|
||||
List<Integer> images = sectionImages.get(title);
|
||||
List<ItemModel> items = sectionImages.get(title);
|
||||
|
||||
holder.sectionTitle.setText(title);
|
||||
|
||||
HomeAdapter homeAdapter = new HomeAdapter(images);
|
||||
HomeAdapter homeAdapter = new HomeAdapter(items, title);
|
||||
holder.sectionRecycler.setLayoutManager(
|
||||
new LinearLayoutManager(holder.itemView.getContext(), LinearLayoutManager.HORIZONTAL, false)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.santiparra.yomitrack.R;
|
||||
import com.santiparra.yomitrack.model.adapters.homeadapter.HomeAdapter;
|
||||
import com.santiparra.yomitrack.model.ItemModel;
|
||||
import com.santiparra.yomitrack.model.adapters.sectionadapter.SectionAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -20,10 +21,8 @@ import java.util.Map;
|
|||
|
||||
public class FragmentHome extends Fragment {
|
||||
|
||||
private RecyclerView horizontalRecyclerView;
|
||||
|
||||
public FragmentHome() {
|
||||
super(R.layout.fragment_home); // Estás usando ViewBinding/Inflado automático por constructor
|
||||
super(R.layout.fragment_home);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -32,18 +31,35 @@ public class FragmentHome extends Fragment {
|
|||
|
||||
RecyclerView mainRecyclerView = view.findViewById(R.id.mainRecyclerView);
|
||||
|
||||
// Crear las secciones
|
||||
List<String> sectionTitles = Arrays.asList(
|
||||
"Airing", "Anime in Progress", "Manga in Progress"
|
||||
);
|
||||
|
||||
Map<String, List<Integer>> sectionImages = new HashMap<>();
|
||||
sectionImages.put("Airing", Arrays.asList(R.drawable.imagen1, R.drawable.imagen2, R.drawable.imagen3));
|
||||
sectionImages.put("Anime in Progress", Arrays.asList(R.drawable.imagen4, R.drawable.imagen5));
|
||||
sectionImages.put("Manga in Progress", Arrays.asList(R.drawable.imagen6, R.drawable.imagen7, R.drawable.imagen8));
|
||||
// Crear el contenido de cada sección como List<ItemModel>
|
||||
Map<String, List<ItemModel>> sectionItems = new HashMap<>();
|
||||
|
||||
SectionAdapter adapter = new SectionAdapter(sectionTitles, sectionImages);
|
||||
List<ItemModel> airingItems = new ArrayList<>();
|
||||
airingItems.add(new ItemModel("Naruto", "5/220", "https://i.imgur.com/N5uCbDu.jpg", 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));
|
||||
|
||||
List<ItemModel> animeInProgressItems = new ArrayList<>();
|
||||
animeInProgressItems.add(new ItemModel("Attack on Titan", "16/25", "https://i.imgur.com/z4d4kWk.jpg", ItemModel.ContentType.ANIME));
|
||||
animeInProgressItems.add(new ItemModel("Jujutsu Kaisen", "10/24", "https://i.imgur.com/lWhD6Zc.jpg", ItemModel.ContentType.ANIME));
|
||||
|
||||
List<ItemModel> mangaInProgressItems = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
android:gravity="center_horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:id="@+id/animeImage"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="220dp"
|
||||
android:scaleType="centerCrop"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
android:layout_marginBottom="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:id="@+id/animeImage"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="220dp"
|
||||
android:scaleType="centerCrop"
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@
|
|||
<item name="imageView" type="id" />
|
||||
<item name="sectionTitle" type="id" />
|
||||
<item name="sectionRecycler" type="id" />
|
||||
<item name="mediaImage" type="id" />
|
||||
</resources>
|
||||
|
|
@ -3,4 +3,5 @@
|
|||
<string name="home_section_list">List of home sections (Airing, Reading, etc.)</string>
|
||||
<string name="manga_image_desc" />
|
||||
<string name="anime_image_desc" />
|
||||
<string name="media_image_desc">Media Image</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue