mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Merge API to Shop Detail screen
This commit is contained in:
@@ -55,9 +55,15 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
holder.foodName.setText(foodBasket.getName());
|
||||
holder.shopName.setText(foodBasket.getShopName());
|
||||
holder.price.setText(Common.changeCurrencyUnit(foodBasket.getCost()));
|
||||
Picasso.get().load(foodBasket.getImg()).into(holder.imageView);
|
||||
holder.quantity.setNumber(foodBasket.getQuantity());
|
||||
|
||||
//Check food image is null or not null
|
||||
if(foodBasket.getImg() == null){
|
||||
holder.imageView.setImageResource(R.drawable.default_image_food);
|
||||
} else {
|
||||
Picasso.get().load(foodBasket.getImg()).into(holder.imageView);
|
||||
}
|
||||
|
||||
//Calculate total price
|
||||
calculateTotalPrice();
|
||||
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
package com.capstone.foodify.Adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Activity.FoodDetailActivity;
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Basket.Basket;
|
||||
import com.capstone.foodify.Model.Food.Food;
|
||||
import com.capstone.foodify.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodShopViewHolder> {
|
||||
|
||||
private List<Food> listFoodShop;
|
||||
private Context context;
|
||||
|
||||
public FoodShopAdapter() {
|
||||
public FoodShopAdapter(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setData(List<Food> listFoodShop){
|
||||
@@ -39,10 +48,61 @@ public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodSh
|
||||
if(food == null)
|
||||
return;
|
||||
|
||||
// Picasso.get().load(food.getImg()).into(holder.imageView);
|
||||
// holder.foodName.setText(food.getName());
|
||||
// holder.quantitySoldOut.setText("1.2k đã bán");
|
||||
// holder.price.setText(food.getPrice());
|
||||
if(food.getImages().size() == 0){
|
||||
holder.imageView.setImageResource(R.drawable.default_image_food);
|
||||
} else {
|
||||
Picasso.get().load(food.getImages().get(0).getImageUrl()).into(holder.imageView);
|
||||
}
|
||||
|
||||
holder.foodName.setText(food.getName());
|
||||
holder.quantitySoldOut.setText("1.2k đã bán");
|
||||
holder.price.setText(Common.changeCurrencyUnit(food.getCost()));
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(context, FoodDetailActivity.class);
|
||||
intent.putExtra("FoodId", food.getId());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
//Set event basket icon
|
||||
holder.basket_icon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Basket foodInBasket = Common.getFoodExistInBasket(food.getId());
|
||||
if(foodInBasket == null){
|
||||
//If item is not exist in basket
|
||||
|
||||
//Check food image is null or not
|
||||
String imageTemp = null;
|
||||
if(food.getImages().size() > 0)
|
||||
imageTemp = food.getImages().get(0).getImageUrl();
|
||||
|
||||
Common.LIST_BASKET_FOOD.add(new Basket(food.getId(), imageTemp, food.getName(), food.getCost(), food.getShop().getName(),
|
||||
"1", food.getDiscountPercent()));
|
||||
} else {
|
||||
//If item is exist in basket
|
||||
|
||||
for(int i = 0; i < Common.LIST_BASKET_FOOD.size(); i++){
|
||||
String foodId = Common.LIST_BASKET_FOOD.get(i).getId();
|
||||
//Find foodId exist
|
||||
if(foodId.equals(food.getId())){
|
||||
//Get quantity food from basket
|
||||
String quantity = Common.LIST_BASKET_FOOD.get(i).getQuantity();
|
||||
|
||||
//Change quantity food from basket
|
||||
int quantityInt = Integer.parseInt(quantity) + 1;
|
||||
Common.LIST_BASKET_FOOD.get(i).setQuantity(String.valueOf(quantityInt));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Toast.makeText(context, "Đã thêm " + food.getName() + " vào giỏ hàng!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +114,7 @@ public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodSh
|
||||
|
||||
public class FoodShopViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
ImageView imageView;
|
||||
ImageView imageView, basket_icon;
|
||||
TextView foodName, quantitySoldOut, price;
|
||||
|
||||
|
||||
@@ -65,6 +125,7 @@ public class FoodShopAdapter extends RecyclerView.Adapter<FoodShopAdapter.FoodSh
|
||||
foodName = itemView.findViewById(R.id.food_name_text_view);
|
||||
quantitySoldOut = itemView.findViewById(R.id.quantity_sold_out);
|
||||
price = itemView.findViewById(R.id.price_text_view);
|
||||
basket_icon = itemView.findViewById(R.id.basket_icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Activity.FoodDetailActivity;
|
||||
import com.capstone.foodify.Activity.ShopDetailActivity;
|
||||
import com.capstone.foodify.Model.Shop.Shop;
|
||||
import com.capstone.foodify.R;
|
||||
@@ -49,7 +50,7 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
|
||||
|
||||
//Init data
|
||||
Picasso.get().load(shop.getImageUrl()).into(holder.imageView);
|
||||
holder.shopName.setText("Shop Name");
|
||||
holder.shopName.setText(shop.getName());
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -57,6 +58,15 @@ public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.ShopViewHolder
|
||||
context.startActivity(new Intent(context, ShopDetailActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(context, ShopDetailActivity.class);
|
||||
intent.putExtra("ShopId", shop.getId());
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user