diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5e788e4..360e1e3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -93,18 +93,6 @@
-
-
-
-
-
-
-
-
cartItems; // Declare cartItems here
+ private List cartItems; // Declare cartItems here
+
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detailed_product);
-
CartDatabaseHelper cartDBHelper = new CartDatabaseHelper(this, "cart.db", null, 1);
cartItems = cartDBHelper.getAllRecords();
+
// Toolbar title set
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("Product Details");
@@ -71,6 +72,7 @@ public void onClick(View v) {
// Check if the item already exists in the cart
boolean itemExists = false;
+ cartItems = cartDBHelper.getAllRecords();
for (CartItem cartItem : cartItems) {
if (cartItem.getProductName().equals(productName)) {
// If the item exists, update its quantity
diff --git a/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java b/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
index 43b2618..f01db4e 100644
--- a/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
+++ b/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
@@ -21,7 +21,6 @@
import com.BugBazaar.R;
import com.BugBazaar.ui.cart.CartActivity;
-import com.BugBazaar.ui.cart.CartItem;
import com.google.android.material.navigation.NavigationView;
import java.util.ArrayList;
@@ -35,6 +34,7 @@ public class NavigationDrawer_Dashboard extends AppCompatActivity {
private Toolbar toolbar;
private GridView productGridView;
private List productList;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -85,56 +85,6 @@ protected void onCreate(Bundle savedInstanceState) {
productList.add(new Product("Spy TWS", getString(R.string.desc_cycle), R.drawable.item_tws,4200));
productList.add(new Product("VR device", getString(R.string.desc_cycle), R.drawable.item_vr,8340));
- // Pass the List to Class B
- //Intent intentB = new Intent(this, Deeplink.class);
- //intentB.putStringArrayListExtra("productList", (ArrayList) productList); // Need to convert productList to ArrayList data type first
-
- // Convert List to List of product names in Class A
- /* List productNames = new ArrayList<>();
- for (Product product : productList) {
- productNames.add(product.getName()); // Assuming 'getName()' returns the product name as a String
- }*/
- //Get string extra from Class B
- //intentB.putStringArrayListExtra("productNames", (ArrayList) productNames);
- boolean isItemPresent = false;
- Intent get_item = getIntent();
- if (get_item.hasExtra("fetched_item")) {
- // Retrieve the "fetched_item" string extra & Check if deeplink_item is present in the product list
- String deeplink_item = get_item.getStringExtra("fetched_item");
- for (Product product : productList) {
- if (product.getName().equals(deeplink_item)) {
- Log.d("Product found:", product.getName());
- Intent detailed_product = new Intent(this, DetailedProductActivity.class);
- detailed_product.putExtra("product", product);
- detailed_product.putExtra("autostart", true);
- this.startActivity(detailed_product);
- //Sending intent to CartItem class
- //Intent intToCartItem = new Intent(this, CartItem.class);
- //intToCartItem.putExtra("product", product);
- //this.startActivity(intToCartItem);
- break; // No need to continue searching if found
- }
- }
- //Check if deeplink_item is present in the product list
- /* if (productNames == null) {
- Log.d("Empty productNames list:", "productNames list is null");
- isItemPresent = false;
- }
- else {
- for (String product : productNames) {
- if (product.equals(deeplink_item)) {
- isItemPresent = true;
- Log.d("Product name:", product);
- break; // No need to continue searching if found
- }
- }
- }
- if (isItemPresent) {
- Log.d("Condition pass:", "Item found");
- } else {
- Log.d("Condition fail:", "Item not found");
- } */
- }
// Create and set the adapter for the GridView
ProductAdapter adapter = new ProductAdapter(this, productList);
@@ -170,7 +120,7 @@ public void onClick(View v) {
}
//DO NOT REMOVEIf you search for empty searchbox and app crashed, it is intentional. It is a "Improper Exception Handling" bug
String filteredList = null;
- Log.d("Exception",filteredList);
+ Log.d("Excpetion",filteredList);
}
});
@@ -237,10 +187,7 @@ else if (itemId == R.id.itemCart) {
return true;
});
}
- public void fetch_product()
- {
- }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java b/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java
index 1b4be14..f09549b 100644
--- a/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java
+++ b/app/src/main/java/com/BugBazaar/ui/cart/CartDatabaseHelper.java
@@ -80,8 +80,10 @@ public void removeCartItem(CartItem cartItem) {
Log.d("removeid",String.valueOf(cartItem.getId()));
// Quantity is zero, delete the item from the database
db.delete(CartItemDBModel.CartItemEntry.TABLE_NAME,
- CartItemDBModel.CartItemEntry._ID + " = ?",
- new String[]{String.valueOf(cartItem.getId())});
+ COLUMN_PRODUCT_NAME + " = ?",
+ new String[]{String.valueOf(cartItem.getProductName())});
+ //CartItemDBModel.CartItemEntry._ID + " = ?",
+ //new String[]{String.valueOf(cartItem.getId())});
db.close();
}
diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartItem.java b/app/src/main/java/com/BugBazaar/ui/cart/CartItem.java
index 950616a..ee98ec4 100644
--- a/app/src/main/java/com/BugBazaar/ui/cart/CartItem.java
+++ b/app/src/main/java/com/BugBazaar/ui/cart/CartItem.java
@@ -74,7 +74,6 @@ public void setId(long id) {
this.id = id;
}
-
// Increment the quantity by 1
public void incrementQuantity(Context context) {
if (quantity < Integer.MAX_VALUE) { // To avoid overflow
@@ -93,6 +92,7 @@ public void decrementQuantity(Context context) {
// Remove the product from the database if quantity becomes 0
CartDatabaseHelper dbHelper = new CartDatabaseHelper(context, "cart.db", null, 1);
dbHelper.removeCartItem(this); // Pass the item's ID for removal
+ //clear_item("",0);
} else {
// Update the database with the new quantity
CartDatabaseHelper dbHelper = new CartDatabaseHelper(context, "cart.db", null, 1);
@@ -104,7 +104,8 @@ public void removeItem(Context context){
quantity=0;
// Update the database with the new quantity
CartDatabaseHelper dbHelper = new CartDatabaseHelper(context, "cart.db", null, 1);
- dbHelper.updateCartItem(this);
+ dbHelper.removeCartItem(this); // Added removeCartItem instead of updateCartItem that was called earlier
+ // dbHelper.updateCartItem(this);
}