mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Show rating bar food and list comment user
This commit is contained in:
@@ -7,12 +7,14 @@ 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;
|
||||
import com.capstone.foodify.Model.Food;
|
||||
import com.capstone.foodify.R;
|
||||
import com.squareup.picasso.Picasso;
|
||||
@@ -80,7 +82,41 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
|
||||
holder.price.setText(Common.changeCurrencyUnit(cost));
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -102,7 +138,7 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
|
||||
public class FoodViewHolder extends RecyclerView.ViewHolder{
|
||||
|
||||
private ImageView image;
|
||||
private ImageView image, basket_icon;
|
||||
private TextView name, price, discount;
|
||||
|
||||
public FoodViewHolder(@NonNull View itemView) {
|
||||
@@ -112,6 +148,7 @@ public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.FoodViewHolder
|
||||
name = itemView.findViewById(R.id.title);
|
||||
price = itemView.findViewById(R.id.price);
|
||||
discount = itemView.findViewById(R.id.discount);
|
||||
basket_icon = itemView.findViewById(R.id.basket_icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user