Skip to content

Commit

Permalink
Added Deeplink activity
Browse files Browse the repository at this point in the history
Added "add to cart via deeplink feature" in NavigationDrawer_Dashboard
Bug fixes in DetailedProductActivity w.r.t remove cart item(s)
  • Loading branch information
banditAkshay committed Oct 10, 2023
1 parent 608cf84 commit c09573c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 73 deletions.
12 changes: 0 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.Deeplink"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="bb"
android:host="bugbazaar"
android:path="/cart/add"/>
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@

public class DetailedProductActivity extends AppCompatActivity {

private List<CartItem> cartItems; // Declare cartItems here
private List<CartItem> 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");
Expand Down Expand Up @@ -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
Expand Down
57 changes: 2 additions & 55 deletions app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +34,7 @@ public class NavigationDrawer_Dashboard extends AppCompatActivity {
private Toolbar toolbar;
private GridView productGridView;
private List<Product> productList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -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<String> to Class B
//Intent intentB = new Intent(this, Deeplink.class);
//intentB.putStringArrayListExtra("productList", (ArrayList<String>) productList); // Need to convert productList to ArrayList<String> data type first

// Convert List<Product> to List<String> of product names in Class A
/* List<String> 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<String>) 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);
Expand Down Expand Up @@ -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);
}

});
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/BugBazaar/ui/cart/CartItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
}


Expand Down

0 comments on commit c09573c

Please sign in to comment.