Skip to content

Commit

Permalink
1. Order Summary Module In-progress.
Browse files Browse the repository at this point in the history
2. Wallet and Razorpay integration pending
  • Loading branch information
banditVedant committed Oct 10, 2023
1 parent c7cb06e commit 273b63b
Show file tree
Hide file tree
Showing 22 changed files with 637 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation group: 'com.cloudinary', name: 'cloudinary-android', version: '1.24.0'
implementation 'com.google.android.material:material:1.4.0' // Use the latest version


implementation 'com.razorpay:checkout:1.6.33'

}
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.READ_CONTACTS" />

<queries>
<intent>
Expand All @@ -31,6 +31,15 @@
android:usesCleartextTraffic="true"
tools:replace="android:fullBackupContent"
tools:targetApi="31">
<activity
android:name=".ui.payment.OrderSummary"
android:exported="true" />
<activity
android:name=".ui.TestActivity"
android:exported="true" />
<activity
android:name=".ui.payment.TestRazorPay"
android:exported="true" />
<activity
android:name=".ui.ContactsPack.SelectContacts"
android:exported="true" />
Expand All @@ -39,7 +48,7 @@
android:exported="true" />
<activity
android:name=".ui.cart.CartActivity"
android:exported="false" />
android:exported="true" />
<activity
android:name=".ui.cart.Cart"
android:exported="false" />
Expand All @@ -60,7 +69,7 @@
android:exported="false" />
<activity
android:name=".ui.CreatePasscode"
android:exported="true"></activity>
android:exported="true" />
<activity
android:name=".ui.NavigationDrawer_Dashboard"
android:exported="true">
Expand All @@ -74,7 +83,7 @@
<data
android:host="bugbazaar"
android:pathPrefix="/dashboard"
android:scheme="bb"></data>
android:scheme="bb" />
</intent-filter>
</activity>
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public void onClick(View v) {
String filteredList = null;
Log.d("Excpetion",filteredList);
}

});

//Drawer and Navigation bar layout view find
Expand Down
32 changes: 28 additions & 4 deletions app/src/main/java/com/BugBazaar/ui/TestActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.BugBazaar.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

import com.BugBazaar.R;

Expand All @@ -12,5 +14,27 @@ public class TestActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

RadioGroup radioGroup = findViewById(R.id.radioGroup);
RadioButton radioButton1 = findViewById(R.id.radioButton1);
RadioButton radioButton2 = findViewById(R.id.radioButton2);

// Set OnClickListener for the first RadioButton
radioButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Show a toast when the first RadioButton is clicked
Toast.makeText(TestActivity.this, "First Clicked", Toast.LENGTH_SHORT).show();
}
});

// Set OnClickListener for the second RadioButton
radioButton2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Show a toast when the second RadioButton is clicked
Toast.makeText(TestActivity.this, "Second Clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/BugBazaar/ui/cart/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public Cart() {
private SQLiteDatabase database;



public long addCartItem(CartItem cartItem) {
ContentValues values = new ContentValues();
if (cartItems.containsKey(cartItem)) {
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.BugBazaar.ui.cart;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand All @@ -12,6 +13,8 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.BugBazaar.R;
import com.BugBazaar.ui.payment.OrderSummary;

import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -93,7 +96,9 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
// Perform the checkout action here
Toast.makeText(CartActivity.this, "Checkout clicked", Toast.LENGTH_SHORT).show();
Intent intentz=new Intent(CartActivity.this, OrderSummary.class);
intentz.putExtra("totalPrice",totalCost);
startActivity(intentz);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public long addCartItem(CartItem cartItem) {
return recordId;

}

//To Debug
public void removeCartItem(CartItem cartItem) {
SQLiteDatabase db = this.getWritableDatabase();
Log.d("removeid",String.valueOf(cartItem.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.provider.BaseColumns;


public final class CartItemDBModel {
// To prevent someone from accidentally instantiating the contract class,
// make the constructor private.
Expand Down
133 changes: 133 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/payment/OrderSummary.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.BugBazaar.ui.payment;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.BugBazaar.R;
import com.BugBazaar.ui.cart.CartDatabaseHelper;
import com.BugBazaar.ui.cart.CartItem;
import com.BugBazaar.ui.cart.CartItemDBModel;

import android.database.Cursor;
import android.widget.Toast;

import java.util.List;

public class OrderSummary extends AppCompatActivity {
private List<CartItem> cartItems;
private TextView txtProdQuantityOS;
private TextView txtTotalCostOS;
private TextView txtFinalCostOS;
private RadioGroup rbGroupPaymentOptions;
private RadioButton rbPayViaWallet;
private RadioButton rbPayViaRazorpay;
Button btnProceedPaymentOS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order_summary);
//Toolbar title set
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
toolbarTitle.setText("Order Summary");
txtProdQuantityOS=findViewById(R.id.txtProdQuantityOS);
txtTotalCostOS=findViewById(R.id.txtTotalCostOS);
txtFinalCostOS=findViewById(R.id.txtFinalCostOS);
btnProceedPaymentOS=findViewById(R.id.btnProceedPaymentOS);

// Initialize the RadioGroup and RadioButton elements
rbGroupPaymentOptions = findViewById(R.id.rbGroupPaymentOptions);
rbPayViaWallet = findViewById(R.id.rbPayViaWallet);
rbPayViaRazorpay = findViewById(R.id.rbPayViaRazorpay);

// Initialize your CartDatabaseHelper
CartDatabaseHelper cartDBHelper = new CartDatabaseHelper(this, "cart.db", null, 1);
// Initialize your cartItems list and populate it with all items from the database
cartItems = cartDBHelper.getAllRecords();
// Initialize prodQuantity to store the product quantity
int prodQuantity = 0;
// Iterate through the list of cart items and retrieve the product_quantity from the database
for (CartItem cartItem : cartItems) {
// Retrieve the product name for each item
String productName = cartItem.getProductName();

// Retrieve the product quantity from the database using a query
int quantity = getProductQuantityFromDatabase(cartDBHelper, productName);

// Add the quantity to prodQuantity
prodQuantity += quantity;
//Set the product quantity
txtProdQuantityOS.setText(String.valueOf(prodQuantity));


Intent intent = getIntent();
int totalCost = intent.getIntExtra("totalPrice", 0);
// Format the totalCost and set it in the TextView
String formattedTotalCost = formatPrice(totalCost);
txtTotalCostOS.setText(formattedTotalCost);

int deliveryCharges=536;

//Final Cost to be sent to Razorpay or wallet
int finalCost = totalCost + deliveryCharges;
String formattedFinalCost = formatPrice(finalCost);
txtFinalCostOS.setText(formattedFinalCost);

// Set an OnCheckedChangeListener to the RadioGroup
rbGroupPaymentOptions.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.d("RB Intitated","RB Intitated");
if (checkedId == R.id.rbPayViaWallet) {
rbPayViaWallet.setChecked(true); // Set the "Pay via Wallet" RadioButton as selected
rbPayViaRazorpay.setChecked(false); // Clear the selection of "Pay via Razorpay"
Toast.makeText(getApplicationContext(),"Pay Via Wallet",Toast.LENGTH_SHORT).show();
} else if (checkedId == R.id.rbPayViaRazorpay) {
rbPayViaWallet.setChecked(false);
rbPayViaRazorpay.setChecked(true);
Toast.makeText(getApplicationContext(),"Pay Via Razorpay",Toast.LENGTH_SHORT).show();
}else
Toast.makeText(getApplicationContext(),"No button selected",Toast.LENGTH_SHORT).show();
}
});

}
}
// Define a method to retrieve product_quantity from the database based on product name
private int getProductQuantityFromDatabase(CartDatabaseHelper dbHelper, String productName) {
int quantity = 0;
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.query(
CartItemDBModel.CartItemEntry.TABLE_NAME, // Table name
new String[]{CartItemDBModel.CartItemEntry.COLUMN_QUANTITY}, // Columns to retrieve
CartItemDBModel.CartItemEntry.COLUMN_PRODUCT_NAME + "=?", // Selection criteria
new String[]{productName}, // Selection arguments
null, // Group by
null, // Having
null // Order by
);

if (cursor != null && cursor.moveToFirst()) {
quantity = cursor.getInt(cursor.getColumnIndexOrThrow(CartItemDBModel.CartItemEntry.COLUMN_QUANTITY));
cursor.close();
}

return quantity;
}
private String formatPrice(int price) {
return String.format("₹%,d", price);
}
//Code to handle backbutton
public void onBackButtonClick(View view) {
onBackPressed(); // Navigate back to the previous activity
}
}
Loading

0 comments on commit 273b63b

Please sign in to comment.