Skip to content

Commit

Permalink
Merge pull request #17 from Mofazzal874/Amit
Browse files Browse the repository at this point in the history
Modified all the adapters(category, suggested, view all), Added javad…
  • Loading branch information
superXnova21 authored May 27, 2024
2 parents 9e81763 + b8ad8e5 commit e5146fa
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.projecto.adapters;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
Expand All @@ -19,47 +18,72 @@

import java.util.List;

/**
* Adapter class for displaying categories in a RecyclerView.
* This adapter manages the binding of CategoryModel data into the UI elements within a RecyclerView.
*/
public class CategoryAdapters extends RecyclerView.Adapter<CategoryAdapters.ViewHolder> {

Context context;
List<CategoryModel> categoryModelList;
private Context context;
private List<CategoryModel> categoryModelList;

/**
* Constructor for CategoryAdapters.
* @param context The current context.
* @param categoryModelList The list of categories to be displayed.
*/
public CategoryAdapters(Context context, List<CategoryModel> categoryModelList) {
this.context = context;
this.categoryModelList = categoryModelList;
}

/**
* Inflates the view for each category item.
* @param parent The ViewGroup into which the new View will be added after it is bound to an adapter position.
* @param viewType The view type of the new View.
* @return A new ViewHolder that holds the View for each category item.
*/
@NonNull
@Override
public CategoryAdapters.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.category_item,parent,false));
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.category_item, parent, false);
return new ViewHolder(itemView);
}

/**
* Binds data to the view holder at the specified position in the RecyclerView.
* @param holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(@NonNull CategoryAdapters.ViewHolder holder, int position) {
Glide.with(context).load(categoryModelList.get(position).getImg_url()).into(holder.catImg);
holder.name.setText(categoryModelList.get(position).getName());
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
CategoryModel model = categoryModelList.get(position);
Glide.with(context).load(model.getImg_url()).into(holder.catImg);
holder.name.setText(model.getName());


holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, ViewAllActivity.class);
intent.putExtra("type",categoryModelList.get(holder.getAdapterPosition()).getType());
context.startActivity(intent);
}
holder.itemView.setOnClickListener(v -> {
Intent intent = new Intent(context, ViewAllActivity.class);
intent.putExtra("type", model.getType());
context.startActivity(intent);
});
}

/**
* Returns the total number of items in the data set held by the adapter.
* @return The total number of items in this adapter.
*/
@Override
public int getItemCount() {
return categoryModelList.size();
}

/**
* Provides a reference to the type of views that you are using (custom ViewHolder).
*/
public class ViewHolder extends RecyclerView.ViewHolder {

ImageView catImg;
TextView name;

public ViewHolder(@NonNull View itemView) {
super(itemView);
catImg = itemView.findViewById(R.id.cat_img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,80 @@

import com.bumptech.glide.Glide;
import com.example.projecto.R;
import com.example.projecto.activities.DetailActivity;
import com.example.projecto.activities.DetailActivity2;
import com.example.projecto.models.SuggestedModel;

import java.util.List;
import java.util.zip.Inflater;

/**
* Adapter class for displaying suggested products in a RecyclerView.
* This class adapts SuggestedModel data into viewable items, implementing the Adapter design pattern.
*/
public class SuggestedAdapters extends RecyclerView.Adapter<SuggestedAdapters.ViewHolder>{

private Context context;
private List<SuggestedModel> suggestedModelList;

/**
* Constructs the SuggestedAdapters instance.
* @param context The current context.
* @param suggestedModelList The data model list of suggested products.
*/
public SuggestedAdapters(Context context, List<SuggestedModel> suggestedModelList) {
this.context = context;
this.suggestedModelList = suggestedModelList;
}

/**
* Inflates the layout for each item of the RecyclerView.
* @param parent The ViewGroup into which the new view will be added after it is bound to an adapter position.
* @param viewType The view type of the new view.
* @return A new ViewHolder that holds the View for each item.
*/
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.suggested_item,parent,false));
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.suggested_item, parent, false);
return new ViewHolder(itemView);
}

/**
* Binds the data to the ViewHolder in each position of the RecyclerView.
* @param holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Glide.with(context).load(suggestedModelList.get(position).getImg_url()).into(holder.sugImg);
holder.name.setText(suggestedModelList.get(position).getName());
holder.description.setText(suggestedModelList.get(position).getDescription());
holder.gname.setText(suggestedModelList.get(position).getGname());
holder.discount.setText(suggestedModelList.get(position).getDiscount());
SuggestedModel model = suggestedModelList.get(position);
Glide.with(context).load(model.getImg_url()).into(holder.sugImg);
holder.name.setText(model.getName());
holder.description.setText(model.getDescription());
holder.gname.setText(model.getGname());
holder.discount.setText(model.getDiscount());

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, DetailActivity2.class);
intent.putExtra("detail", suggestedModelList.get(holder.getAdapterPosition()));
context.startActivity(intent);
}
holder.itemView.setOnClickListener(v -> {
Intent intent = new Intent(context, DetailActivity2.class);
intent.putExtra("detail", model);
context.startActivity(intent);
});
}

/**
* Returns the total number of items in the data set held by the adapter.
* @return The total number of items in this adapter.
*/
@Override
public int getItemCount() {
return suggestedModelList.size();
}

/**
* Provides a reference to the type of views that you are using (custom ViewHolder).
*/
public class ViewHolder extends RecyclerView.ViewHolder {

ImageView sugImg;
TextView name,description,gname,discount;
TextView name, description, gname, discount;

public ViewHolder(@NonNull View itemView) {
super(itemView);
sugImg = itemView.findViewById(R.id.sug_img);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,87 @@
import com.bumptech.glide.Glide;
import com.example.projecto.R;
import com.example.projecto.activities.DetailActivity;
import com.example.projecto.activities.ViewAllActivity;
import com.example.projecto.models.ViewAllModel;

import java.io.Serializable;
import java.util.List;

/**
* Adapter class for managing the display of all products in a RecyclerView.
* This adapter bridges the data in ViewAllModel with the view representation in the RecyclerView.
*/
public class ViewAllAdapters extends RecyclerView.Adapter<ViewAllAdapters.ViewHolder> {
Context context;
List<ViewAllModel> viewAllModelList;
private Context context;
private List<ViewAllModel> viewAllModelList;

/**
* Constructor for ViewAllAdapters.
* @param context The current context.
* @param viewAllModelList The list of all product models to be displayed.
*/
public ViewAllAdapters(Context context, List<ViewAllModel> viewAllModelList) {
this.context = context;
this.viewAllModelList = viewAllModelList;
}

/**
* Inflates the view for each product item.
* @param parent The ViewGroup into which the new View will be added after it is bound to an adapter position.
* @param viewType The view type of the new View.
* @return A new ViewHolder that holds the View for each product item.
*/
@NonNull
@Override
public ViewAllAdapters.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.viewall_item,parent,false));
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.viewall_item, parent, false);
return new ViewHolder(itemView);
}

/**
* Binds data to the view holder at the specified position in the RecyclerView.
* @param holder The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
* @param position The position of the item within the adapter's data set.
*/
@Override
public void onBindViewHolder(@NonNull ViewAllAdapters.ViewHolder holder, int position) {
Glide.with(context).load(viewAllModelList.get(position).getImg_url()).into(holder.imageView);
holder.name.setText(viewAllModelList.get(position).getName());
holder.gname.setText(viewAllModelList.get(position).getGname());
holder.price.setText(viewAllModelList.get(position).getPrice()+" Taka");
holder.discount.setText(viewAllModelList.get(position).getDiscount());
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
ViewAllModel model = viewAllModelList.get(position);
Glide.with(context).load(model.getImg_url()).into(holder.imageView);
holder.name.setText(model.getName());
holder.gname.setText(model.getGname());
holder.price.setText(model.getPrice() + " Taka");
holder.discount.setText(model.getDiscount());

holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra("detail", (Serializable)viewAllModelList.get(holder.getAdapterPosition()));
context.startActivity(intent);
}
holder.itemView.setOnClickListener(v -> {
Intent intent = new Intent(context, DetailActivity.class);
intent.putExtra("detail", (Serializable) model);
context.startActivity(intent);
});

}

/**
* Returns the total number of items in the data set held by the adapter.
* @return The total number of items in this adapter.
*/
@Override
public int getItemCount() {
return viewAllModelList.size();
}

/**
* Provides a reference to the type of views that you are using (custom ViewHolder).
*/
public class ViewHolder extends RecyclerView.ViewHolder {

ImageView imageView;
TextView name, price, gname, discount;

public ViewHolder(@NonNull View itemView) {
super(itemView);

imageView = itemView.findViewById(R.id.item_img);
name = itemView.findViewById(R.id.item_name);
gname = itemView.findViewById(R.id.item_gname);
discount = itemView.findViewById(R.id.item_discount);
price = itemView.findViewById(R.id.item_price);
discount = itemView.findViewById(R.id.item_discount);
}
}
}

0 comments on commit e5146fa

Please sign in to comment.