108 lines
3.5 KiB
Java
108 lines
3.5 KiB
Java
package com.example.lookifyv2;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.os.Bundle;
|
|
import android.content.Context;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.MenuInflater;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.PopupMenu; //?????????????????????
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
import java.util.List;
|
|
|
|
public class ProductsAdapter extends RecyclerView.Adapter<ProductsAdapter.ViewHolder>{
|
|
|
|
private Context context;
|
|
private List<Product> products;
|
|
|
|
public ProductsAdapter(Context context, List<Product> products) {
|
|
this.context = context;
|
|
this.products = products;
|
|
}
|
|
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card,parent,false);
|
|
|
|
return new ViewHolder(itemView);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(final ViewHolder holder, int position) {
|
|
|
|
holder.productName.setText(products.get(position).getproductName());
|
|
holder.productPrice.setText(products.get(position).getproductPrice()); //????????????????????????
|
|
Glide.with(context).load(products.get(position).getImageLink()).into(holder.imageView);
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return products.size();
|
|
}
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
|
|
|
|
public TextView productName;
|
|
public TextView productPrice;
|
|
public ImageView imageView;
|
|
|
|
public ViewHolder(View itemView) {
|
|
super(itemView);
|
|
productName = (TextView) itemView.findViewById(R.id.productname);
|
|
imageView = (ImageView) itemView.findViewById(R.id.image);
|
|
productPrice = (TextView) itemView.findViewById(R.id.productprice);
|
|
imageView.setOnClickListener(this);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
int position = getAdapterPosition();
|
|
showPopupMenu(v,position);
|
|
}
|
|
}
|
|
|
|
private void showPopupMenu(View view, int position) {
|
|
PopupMenu popup = new PopupMenu(context, view);
|
|
MenuInflater inflater = popup.getMenuInflater();
|
|
inflater.inflate(R.menu.menu_context, popup.getMenu());
|
|
popup.setOnMenuItemClickListener(new MenuClickListener(position));
|
|
popup.show();
|
|
}
|
|
|
|
class MenuClickListener implements PopupMenu.OnMenuItemClickListener {
|
|
Integer pos;
|
|
public MenuClickListener(int pos) {
|
|
this.pos=pos;
|
|
}
|
|
|
|
@Override
|
|
public boolean onMenuItemClick(MenuItem menuItem) {
|
|
switch (menuItem.getItemId()) {
|
|
case R.id.action_favourite:
|
|
Toast.makeText(context, products.get(pos).getproductName()+" is added to favourite", Toast.LENGTH_SHORT).show();
|
|
return true;
|
|
case R.id.action_watch:
|
|
Toast.makeText(context, products.get(pos).getproductName()+" is added to watchlist", Toast.LENGTH_SHORT).show();
|
|
return true;
|
|
case R.id.action_book:
|
|
Toast.makeText(context, "Booked Ticket for "+ products.get(pos).getproductName(), Toast.LENGTH_SHORT).show();
|
|
return true;
|
|
default:
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|