mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Add order detail screen, fix calculate of price food
This commit is contained in:
@@ -54,9 +54,24 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
//Init data
|
||||
holder.foodName.setText(foodBasket.getName());
|
||||
holder.shopName.setText(foodBasket.getShopName());
|
||||
holder.price.setText(Common.changeCurrencyUnit(foodBasket.getCost()));
|
||||
holder.quantity.setNumber(foodBasket.getQuantity());
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
if(foodBasket.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
cost = foodBasket.getCost() - (foodBasket.getCost() * foodBasket.getDiscountPercent()/100);
|
||||
|
||||
//Show discountPercent value on screen
|
||||
holder.discount.setVisibility(View.VISIBLE);
|
||||
holder.discount.setText("-" + foodBasket.getDiscountPercent()+ "%");
|
||||
} else {
|
||||
cost = foodBasket.getCost();
|
||||
}
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
|
||||
//Check food image is null or not null
|
||||
if(foodBasket.getImg() == null){
|
||||
holder.imageView.setImageResource(R.drawable.default_image_food);
|
||||
@@ -88,9 +103,10 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
float total = 0;
|
||||
|
||||
for(Basket foodTemp: listBasketFood){
|
||||
total += (foodTemp.getCost()) * (Float.parseFloat(foodTemp.getQuantity())) * (100 - foodTemp.getDiscount())/100;
|
||||
total += (foodTemp.getCost()) * (Float.parseFloat(foodTemp.getQuantity())) * (100 - foodTemp.getDiscountPercent())/100;
|
||||
}
|
||||
basketFragment.total.setText(Common.changeCurrencyUnit(total));
|
||||
basketFragment.totalFloat = total;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +118,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
|
||||
public static class BasketViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
TextView foodName, shopName, price, total;
|
||||
TextView foodName, shopName, price, total, discount;
|
||||
public LinearLayout layoutForeGround;
|
||||
ImageView imageView;
|
||||
ElegantNumberButton quantity;
|
||||
@@ -117,6 +133,7 @@ public class BasketAdapter extends RecyclerView.Adapter<BasketAdapter.BasketView
|
||||
imageView = itemView.findViewById(R.id.image_view);
|
||||
quantity = itemView.findViewById(R.id.quantity);
|
||||
total = itemView.findViewById(R.id.total_text_view);
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
|
||||
layoutForeGround = itemView.findViewById(R.id.layout_foreground);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Basket;
|
||||
import com.capstone.foodify.Model.OrderDetail;
|
||||
import com.capstone.foodify.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
@@ -17,12 +19,12 @@ import java.util.List;
|
||||
|
||||
public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.OrderDetailViewHolder>{
|
||||
|
||||
public List<OrderDetail> listOrderDetails;
|
||||
public List<Basket> listFoodInBasket;
|
||||
|
||||
public OrderDetailAdapter(){}
|
||||
|
||||
public void setData(List<OrderDetail> listOrderDetails){
|
||||
this.listOrderDetails = listOrderDetails;
|
||||
public void setData(List<Basket> listFoodInBasket){
|
||||
this.listFoodInBasket = listFoodInBasket;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,28 +37,43 @@ public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull OrderDetailViewHolder holder, int position) {
|
||||
OrderDetail orderDetail = listOrderDetails.get(position);
|
||||
Basket food = listFoodInBasket.get(position);
|
||||
|
||||
if(orderDetail == null)
|
||||
if(food == null)
|
||||
return;
|
||||
|
||||
Picasso.get().load("https://images.unsplash.com/photo-1546069901-ba9599a7e63c?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8MXx8fGVufDB8fHx8&w=1000&q=80").into(holder.image_view);
|
||||
holder.food_name.setText("Food Name");
|
||||
holder.shop_name.setText("Shop Name");
|
||||
holder.price.setText("120000 đ");
|
||||
holder.quantity.setText("Số lượng: 2");
|
||||
Picasso.get().load(food.getImg()).into(holder.image_view);
|
||||
holder.food_name.setText(food.getName());
|
||||
holder.shop_name.setText(food.getShopName());
|
||||
holder.quantity.setText("Số lượng: " + food.getQuantity());
|
||||
|
||||
//Check value discountPercent
|
||||
float cost = 0;
|
||||
if(food.getDiscountPercent() > 0){
|
||||
|
||||
//Calculate final cost when apply discountPercent
|
||||
cost = food.getCost() - (food.getCost() * food.getDiscountPercent()/100);
|
||||
|
||||
//Show discountPercent value on screen
|
||||
holder.discount.setVisibility(View.VISIBLE);
|
||||
holder.discount.setText("-" + food.getDiscountPercent()+ "%");
|
||||
} else {
|
||||
cost = food.getCost();
|
||||
}
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if(listOrderDetails != null)
|
||||
return listOrderDetails.size();
|
||||
if(listFoodInBasket != null)
|
||||
return listFoodInBasket.size();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class OrderDetailViewHolder extends RecyclerView.ViewHolder{
|
||||
ImageView image_view;
|
||||
TextView food_name, shop_name, price, quantity;
|
||||
TextView food_name, shop_name, price, quantity, discount;
|
||||
|
||||
public OrderDetailViewHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
@@ -67,6 +84,7 @@ public class OrderDetailAdapter extends RecyclerView.Adapter<OrderDetailAdapter.
|
||||
shop_name = itemView.findViewById(R.id.shop_name_text_view);
|
||||
price = itemView.findViewById(R.id.price_text_view);
|
||||
quantity = itemView.findViewById(R.id.quantity_text_view);
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user