mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Add image in Cart
This commit is contained in:
Binary file not shown.
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
public class Database extends SQLiteAssetHelper {
|
||||
|
||||
private static final String DB_NAME = "EatItDB.db";
|
||||
private static final int DB_VER = 1;
|
||||
private static final int DB_VER = 2;
|
||||
|
||||
public Database(Context context) {
|
||||
super(context, DB_NAME, null, DB_VER);
|
||||
@@ -24,7 +24,7 @@ public class Database extends SQLiteAssetHelper {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
String[] sqlSelect = {"ID", "ProductName", "ProductId", "Quantity", "Price", "Discount"};
|
||||
String[] sqlSelect = {"ID", "ProductName", "ProductId", "Quantity", "Price", "Discount", "Image"};
|
||||
String sqlTable = "OrderDetail";
|
||||
|
||||
qb.setTables(sqlTable);
|
||||
@@ -39,7 +39,8 @@ public class Database extends SQLiteAssetHelper {
|
||||
c.getString(c.getColumnIndexOrThrow("ProductName")),
|
||||
c.getString(c.getColumnIndexOrThrow("Quantity")),
|
||||
c.getString(c.getColumnIndexOrThrow("Price")),
|
||||
c.getString(c.getColumnIndexOrThrow("Discount"))
|
||||
c.getString(c.getColumnIndexOrThrow("Discount")),
|
||||
c.getString(c.getColumnIndexOrThrow("Image"))
|
||||
));
|
||||
} while (c.moveToNext());
|
||||
}
|
||||
@@ -48,12 +49,13 @@ public class Database extends SQLiteAssetHelper {
|
||||
|
||||
public void addToCart(Order order) {
|
||||
SQLiteDatabase db = getReadableDatabase();
|
||||
String query = String.format("INSERT INTO OrderDetail(ProductId, ProductName, Quantity, Price,Discount) VALUES ('%s', '%s','%s','%s','%s');",
|
||||
String query = String.format("INSERT INTO OrderDetail(ProductId, ProductName, Quantity, Price,Discount,Image) VALUES ('%s', '%s','%s','%s','%s','%s');",
|
||||
order.getProductId(),
|
||||
order.getProductName(),
|
||||
order.getQuantity(),
|
||||
order.getPrice(),
|
||||
order.getDiscount());
|
||||
order.getDiscount(),
|
||||
order.getImage());
|
||||
db.execSQL(query);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,8 @@ public class FoodDetail extends AppCompatActivity implements RatingDialogListene
|
||||
currentFood.getName(),
|
||||
numberButton.getNumber(),
|
||||
currentFood.getPrice(),
|
||||
currentFood.getDiscount()
|
||||
currentFood.getDiscount(),
|
||||
currentFood.getImage()
|
||||
));
|
||||
|
||||
Toast.makeText(FoodDetail.this, "Đã thêm vào giỏ hàng!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -258,7 +258,8 @@ public class FoodList extends AppCompatActivity {
|
||||
model.getName(),
|
||||
"1",
|
||||
model.getPrice(),
|
||||
model.getDiscount()
|
||||
model.getDiscount(),
|
||||
model.getImage()
|
||||
));
|
||||
|
||||
Toast.makeText(FoodList.this, "Đã thêm vào giỏ hàng!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
@@ -8,25 +8,28 @@ public class Order {
|
||||
private String Quantity;
|
||||
private String Price;
|
||||
private String Discount;
|
||||
private String Image;
|
||||
|
||||
public Order() {
|
||||
}
|
||||
|
||||
public Order(String productId, String productName, String quantity, String price, String discount) {
|
||||
public Order(String productId, String productName, String quantity, String price, String discount, String image) {
|
||||
ProductId = productId;
|
||||
ProductName = productName;
|
||||
Quantity = quantity;
|
||||
Price = price;
|
||||
Discount = discount;
|
||||
Image = image;
|
||||
}
|
||||
|
||||
public Order(int ID, String productId, String productName, String quantity, String price, String discount) {
|
||||
public Order(int ID, String productId, String productName, String quantity, String price, String discount, String image) {
|
||||
this.ID = ID;
|
||||
ProductId = productId;
|
||||
ProductName = productName;
|
||||
Quantity = quantity;
|
||||
Price = price;
|
||||
Discount = discount;
|
||||
Image = image;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
@@ -76,4 +79,12 @@ public class Order {
|
||||
public void setDiscount(String discount) {
|
||||
Discount = discount;
|
||||
}
|
||||
|
||||
public String getImage() {
|
||||
return Image;
|
||||
}
|
||||
|
||||
public void setImage(String image) {
|
||||
Image = image;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Cart;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Database.Database;
|
||||
@@ -32,6 +33,7 @@ class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickList
|
||||
|
||||
public TextView txt_card_item, txt_price;
|
||||
public ElegantNumberButton btn_quantity;
|
||||
public ImageView cart_image;
|
||||
|
||||
private ItemClickListener itemClickListener;
|
||||
|
||||
@@ -44,6 +46,8 @@ class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickList
|
||||
txt_card_item = (TextView) itemView.findViewById(R.id.cart_item_name);
|
||||
txt_price = (TextView) itemView.findViewById(R.id.cart_item_Price);
|
||||
btn_quantity = (ElegantNumberButton) itemView.findViewById(R.id.btn_quantity);
|
||||
cart_image = (ImageView) itemView.findViewById(R.id.cart_image);
|
||||
|
||||
itemView.setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
@@ -79,8 +83,12 @@ public class CartAdapter extends RecyclerView.Adapter<CartViewHolder>{
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull CartViewHolder holder, final int position) {
|
||||
// TextDrawable drawable = TextDrawable.builder().buildRound("" + listData.get(position).getQuantity(), Color.RED);
|
||||
// holder.img_cart_count.setImageDrawable(drawable);
|
||||
|
||||
Picasso.with(cart.getBaseContext())
|
||||
.load(listData.get(position).getImage())
|
||||
.resize(70,70)
|
||||
.centerCrop()
|
||||
.into(holder.cart_image);
|
||||
|
||||
holder.btn_quantity.setNumber(listData.get(position).getQuantity());
|
||||
holder.btn_quantity.setOnValueChangeListener(new ElegantNumberButton.OnValueChangeListener() {
|
||||
|
||||
@@ -16,8 +16,15 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/cart_image"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_weight="9"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
Reference in New Issue
Block a user