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)
|
testImplementation(libs.junit)
|
||||||
androidTestImplementation(libs.ext.junit)
|
androidTestImplementation(libs.ext.junit)
|
||||||
androidTestImplementation(libs.espresso.core)
|
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"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<!-- Agregado el permiso de Internet -->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
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.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.santiparra.yomitrack.R;
|
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;
|
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) {
|
private static final int TYPE_AIRING = 0;
|
||||||
this.imageList = imageList;
|
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
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public HomeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_anime_card, parent, false);
|
if (viewType == TYPE_AIRING) {
|
||||||
return new ViewHolder(view);
|
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
|
@Override
|
||||||
public void onBindViewHolder(@NonNull HomeAdapter.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
holder.imageView.setImageResource(imageList.get(position));
|
ItemModel item = itemList.get(position);
|
||||||
|
|
||||||
|
if (holder instanceof AiringViewHolder) {
|
||||||
|
((AiringViewHolder) holder).bind(item);
|
||||||
|
} else if (holder instanceof AnimeViewHolder) {
|
||||||
|
((AnimeViewHolder) holder).bind(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return imageList.size();
|
return itemList.size();
|
||||||
}
|
|
||||||
|
|
||||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
ImageView imageView;
|
|
||||||
public ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
imageView = itemView.findViewById(R.id.imageView);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
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.R;
|
||||||
import com.santiparra.yomitrack.model.adapters.homeadapter.HomeAdapter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -18,9 +19,9 @@ import java.util.Map;
|
||||||
public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionViewHolder> {
|
public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionViewHolder> {
|
||||||
|
|
||||||
private final List<String> sectionTitles;
|
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.sectionTitles = sectionTitles;
|
||||||
this.sectionImages = sectionImages;
|
this.sectionImages = sectionImages;
|
||||||
}
|
}
|
||||||
|
|
@ -35,11 +36,11 @@ public class SectionAdapter extends RecyclerView.Adapter<SectionAdapter.SectionV
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull SectionViewHolder holder, int position) {
|
||||||
String title = sectionTitles.get(position);
|
String title = sectionTitles.get(position);
|
||||||
List<Integer> images = sectionImages.get(title);
|
List<ItemModel> items = sectionImages.get(title);
|
||||||
|
|
||||||
holder.sectionTitle.setText(title);
|
holder.sectionTitle.setText(title);
|
||||||
|
|
||||||
HomeAdapter homeAdapter = new HomeAdapter(images);
|
HomeAdapter homeAdapter = new HomeAdapter(items, title);
|
||||||
holder.sectionRecycler.setLayoutManager(
|
holder.sectionRecycler.setLayoutManager(
|
||||||
new LinearLayoutManager(holder.itemView.getContext(), LinearLayoutManager.HORIZONTAL, false)
|
new LinearLayoutManager(holder.itemView.getContext(), LinearLayoutManager.HORIZONTAL, false)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,10 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.santiparra.yomitrack.R;
|
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 com.santiparra.yomitrack.model.adapters.sectionadapter.SectionAdapter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -20,10 +21,8 @@ import java.util.Map;
|
||||||
|
|
||||||
public class FragmentHome extends Fragment {
|
public class FragmentHome extends Fragment {
|
||||||
|
|
||||||
private RecyclerView horizontalRecyclerView;
|
|
||||||
|
|
||||||
public FragmentHome() {
|
public FragmentHome() {
|
||||||
super(R.layout.fragment_home); // Estás usando ViewBinding/Inflado automático por constructor
|
super(R.layout.fragment_home);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -32,18 +31,35 @@ public class FragmentHome extends Fragment {
|
||||||
|
|
||||||
RecyclerView mainRecyclerView = view.findViewById(R.id.mainRecyclerView);
|
RecyclerView mainRecyclerView = view.findViewById(R.id.mainRecyclerView);
|
||||||
|
|
||||||
|
// Crear las secciones
|
||||||
List<String> sectionTitles = Arrays.asList(
|
List<String> sectionTitles = Arrays.asList(
|
||||||
"Airing", "Anime in Progress", "Manga in Progress"
|
"Airing", "Anime in Progress", "Manga in Progress"
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, List<Integer>> sectionImages = new HashMap<>();
|
// Crear el contenido de cada sección como List<ItemModel>
|
||||||
sectionImages.put("Airing", Arrays.asList(R.drawable.imagen1, R.drawable.imagen2, R.drawable.imagen3));
|
Map<String, List<ItemModel>> sectionItems = new HashMap<>();
|
||||||
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));
|
|
||||||
|
|
||||||
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.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
mainRecyclerView.setAdapter(adapter);
|
mainRecyclerView.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
android:gravity="center_horizontal">
|
android:gravity="center_horizontal">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/animeImage"
|
||||||
android:layout_width="160dp"
|
android:layout_width="160dp"
|
||||||
android:layout_height="220dp"
|
android:layout_height="220dp"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
android:layout_marginBottom="8dp">
|
android:layout_marginBottom="8dp">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/animeImage"
|
||||||
android:layout_width="160dp"
|
android:layout_width="160dp"
|
||||||
android:layout_height="220dp"
|
android:layout_height="220dp"
|
||||||
android:scaleType="centerCrop"
|
android:scaleType="centerCrop"
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,5 @@
|
||||||
<item name="imageView" type="id" />
|
<item name="imageView" type="id" />
|
||||||
<item name="sectionTitle" type="id" />
|
<item name="sectionTitle" type="id" />
|
||||||
<item name="sectionRecycler" type="id" />
|
<item name="sectionRecycler" type="id" />
|
||||||
|
<item name="mediaImage" type="id" />
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -3,4 +3,5 @@
|
||||||
<string name="home_section_list">List of home sections (Airing, Reading, etc.)</string>
|
<string name="home_section_list">List of home sections (Airing, Reading, etc.)</string>
|
||||||
<string name="manga_image_desc" />
|
<string name="manga_image_desc" />
|
||||||
<string name="anime_image_desc" />
|
<string name="anime_image_desc" />
|
||||||
|
<string name="media_image_desc">Media Image</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue