Skip to content

Commit 9f06896

Browse files
authored
Merge pull request #32 from banditAmit/vedant
Vedant
2 parents b8dc0d5 + c57598e commit 9f06896

File tree

11 files changed

+535
-67
lines changed

11 files changed

+535
-67
lines changed

.idea/misc.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
tools:targetApi="31">
4242
<activity
4343
android:name=".ui.Wallet"
44-
android:exported="false" />
44+
android:exported="true" />
4545
<activity
4646
android:name=".ui.myorders.OrderHistoryActivity"
4747
android:exported="true" />
@@ -89,16 +89,9 @@
8989
android:name=".ui.NavigationDrawer_Dashboard"
9090
android:exported="true">
9191
<intent-filter>
92-
<category android:name="android.intent.category.LAUNCHER" />
93-
94-
<action android:name="android.intent.action.VIEW" />
95-
96-
<category android:name="android.intent.category.BROWSABLE" />
92+
<action android:name="android.intent.action.MAIN" />
9793

98-
<data
99-
android:host="bugbazaar"
100-
android:pathPrefix="/dashboard"
101-
android:scheme="bb" />
94+
<category android:name="android.intent.category.LAUNCHER" />
10295
</intent-filter>
10396
</activity>
10497
<activity
@@ -120,11 +113,7 @@
120113
android:name=".ui.Signin"
121114
android:clearTaskOnLaunch="true"
122115
android:exported="true">
123-
<intent-filter>
124-
<action android:name="android.intent.action.MAIN" />
125116

126-
<category android:name="android.intent.category.LAUNCHER" />
127-
</intent-filter>
128117
</activity>
129118
<activity
130119
android:name=".ui.Deeplink"

app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ protected void onCreate(Bundle savedInstanceState) {
7878

7979
}
8080

81-
82-
//////////// first check !!!!!!!
83-
84-
85-
86-
87-
88-
8981
/////
9082
// Rest of your activity initialization code
9183

@@ -213,7 +205,10 @@ public void onClick(View v) {
213205
drawerLayout.closeDrawer(GravityCompat.START);
214206
return true;
215207
} else if (itemId == R.id.itemWallet) {
216-
Toast.makeText(this, "Wallet is clicked", Toast.LENGTH_SHORT).show();
208+
Intent intent = new Intent(NavigationDrawer_Dashboard.this, Wallet.class);
209+
startActivity(intent);
210+
drawerLayout.closeDrawer(GravityCompat.START);
211+
return true;
217212
}
218213
else if (itemId == R.id.itemCart) {
219214
Intent intent =new Intent(this, CartActivity.class);
@@ -261,22 +256,23 @@ public void onDiscountCalculated(double discountedPrice) {
261256
}
262257

263258
private void handleDiscountedPrice(double discountedPrice) {
259+
double finalDiscount=discountedPrice*100;
264260

265-
Toast.makeText(this, "Discounted Price: $" + discountedPrice, Toast.LENGTH_SHORT).show();
266261
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,new Intent(),0);
267262
// This is the first run, show your notification
268263
AppInitializationManager.showNotification(this);
269-
CustomDialog.showCustomDialog(this, " \uD83C\uDF89 Congratulations \uD83C\uDF89", "You've received a "+ discountedPrice+"voucher.Login to Redeem",pendingIntent);
264+
CustomDialog.showCustomDialog(this, " \uD83C\uDF89 Congratulations!! \uD83C\uDF89", "You've received a "+ finalDiscount+" wallet balance. Login to Redeem.",pendingIntent);
270265
AppInitializationManager.markFirstRunDone(this);
271266

267+
//When click on OK, navigate to Sign-in activity.
268+
Intent intent=new Intent(this,Signin.class);
269+
intent.putExtra("discountedPrice",finalDiscount);
270+
startActivity(intent);
272271

273-
272+
Intent intentz=new Intent(this,Wallet.class);
273+
intentz.putExtra("discountedPrice",finalDiscount);
274274
}
275275

276-
public void fetch_product()
277-
{
278-
279-
}
280276
@Override
281277
public boolean onOptionsItemSelected(MenuItem item) {
282278
if (item.getItemId() == android.R.id.home) {

app/src/main/java/com/BugBazaar/ui/Signin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected void onCreate(Bundle savedInstanceState) {
2929
setContentView(R.layout.activity_main);
3030

3131

32-
3332
UserAuthSave userAuthSave = new UserAuthSave(getApplicationContext()); // 'this' refers to the Activity's context
3433

3534

app/src/main/java/com/BugBazaar/ui/Wallet.java

Lines changed: 232 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,254 @@
22

33
import androidx.appcompat.app.AppCompatActivity;
44

5+
import android.content.Context;
6+
import android.content.SharedPreferences;
57
import android.os.Bundle;
8+
import android.text.Editable;
9+
import android.text.TextWatcher;
10+
import android.util.Log;
611
import android.view.View;
12+
import android.widget.CompoundButton;
713
import android.widget.TextView;
814

915
import com.BugBazaar.R;
16+
import android.widget.Button;
17+
import android.widget.CheckBox;
18+
import android.widget.EditText;
19+
import android.widget.RadioButton;
20+
import android.widget.RadioGroup;
21+
import android.widget.Toast;
1022

11-
public class Wallet extends AppCompatActivity {
23+
import com.BugBazaar.ui.payment.OrderSummary;
24+
import com.razorpay.Checkout;
25+
import com.razorpay.PaymentResultListener;
26+
import org.json.JSONObject;
27+
28+
public class Wallet extends AppCompatActivity implements PaymentResultListener {
29+
private static final String WALLET_BALANCE_KEY = "wallet_balance";
30+
private TextView walletBalanceW;
31+
private RadioGroup rbGroupPaymentOptionsW;
32+
33+
private SharedPreferences sharedPreferences;
34+
private int newAmount;
35+
private EditText enterAmountW;
36+
private TextView finalAmountW;
37+
private int edtWalletAmount=0;
38+
int additionalAmount=0;
39+
int promoCodeAmount=10000;
1240

1341
@Override
1442
protected void onCreate(Bundle savedInstanceState) {
1543
super.onCreate(savedInstanceState);
1644
setContentView(R.layout.activity_wallet);
1745

18-
//Toolbar title set
46+
// Initialize SharedPreferences
47+
sharedPreferences = getSharedPreferences("MyWalletPrefs", Context.MODE_PRIVATE);
48+
49+
// Toolbar title set
1950
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
2051
toolbarTitle.setText("Wallet");
52+
53+
walletBalanceW = findViewById(R.id.walletBalanceW);
54+
finalAmountW = findViewById(R.id.finalAmountW);
55+
enterAmountW = findViewById(R.id.enterAmountW);
56+
CheckBox promoCheckboxW = findViewById(R.id.promoCheckboxW);
57+
RadioButton walletPayViaRazorpayW = findViewById(R.id.walletPayViaRazorpayW);
58+
Button btnProceedWallet = findViewById(R.id.btnProceedWallet);
59+
rbGroupPaymentOptionsW = findViewById(R.id.rbGroupPaymentOptionsW);
60+
61+
// Set the wallet balance from SharedPreferences
62+
int initialBalance = sharedPreferences.getInt(WALLET_BALANCE_KEY, 12000);
63+
String wallBalanceStr = String.valueOf(initialBalance);
64+
wallBalanceStr = formatPrice(initialBalance);
65+
walletBalanceW.setText(wallBalanceStr); // Display the balance
66+
67+
// Initialize Razorpay with your API key
68+
Checkout.preload(getApplicationContext());
69+
Checkout checkout = new Checkout();
70+
checkout.setKeyID("rzp_test_YEExgm42Uvy0u1");
71+
72+
// Add a text change listener to the EditText
73+
enterAmountW.addTextChangedListener(new TextWatcher() {
74+
@Override
75+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
76+
}
77+
78+
@Override
79+
public void onTextChanged(CharSequence s, int start, int before, int count) {
80+
// Update finalAmountW as the user types or modifies the amount
81+
updateFinalAmount(s.toString());
82+
}
83+
84+
@Override
85+
public void afterTextChanged(Editable s) {
86+
}
87+
});
88+
89+
// Add a listener for the promoCheckbox
90+
promoCheckboxW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
91+
@Override
92+
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
93+
try {
94+
int enteredAmount = Integer.parseInt(enterAmountW.getText().toString());
95+
if (isChecked) {
96+
enteredAmount += 10000;
97+
}
98+
// Calculate the new amount in paise
99+
newAmount = enteredAmount * 100;
100+
updateFinalAmount(Integer.toString(enteredAmount));
101+
} catch (NumberFormatException e) {
102+
Toast.makeText(getApplicationContext(), "Invalid amount entered.", Toast.LENGTH_SHORT).show();
103+
}
104+
}
105+
});
106+
enterAmountW.addTextChangedListener(new TextWatcher() {
107+
@Override
108+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
109+
}
110+
111+
@Override
112+
public void onTextChanged(CharSequence s, int start, int before, int count) {
113+
try {
114+
int enteredAmount = Integer.parseInt(s.toString());
115+
if (promoCheckboxW.isChecked()) {
116+
enteredAmount += 10000;
117+
}
118+
// Calculate the new amount in paise
119+
newAmount = enteredAmount * 100;
120+
updateFinalAmount(Integer.toString(enteredAmount));
121+
} catch (NumberFormatException e) {
122+
Toast.makeText(getApplicationContext(), "Invalid amount entered.", Toast.LENGTH_SHORT).show();
123+
}
124+
}
125+
126+
@Override
127+
public void afterTextChanged(Editable s) {
128+
}
129+
});
130+
int selectedRadioButtonId = rbGroupPaymentOptionsW.getCheckedRadioButtonId();
131+
132+
if (selectedRadioButtonId == R.id.walletPayViaRazorpayW) {
133+
134+
int amountInPaise = edtWalletAmount * 100;
135+
additionalAmount=edtWalletAmount;
136+
newAmount = amountInPaise; // Store the amount for later use
137+
138+
// Calculate the final amount
139+
int finalAmount = amountInPaise;
140+
141+
// Update the final amount TextView
142+
finalAmountW.setText(formatPrice(finalAmount));
143+
}
144+
145+
btnProceedWallet.setOnClickListener(new View.OnClickListener() {
146+
@Override
147+
public void onClick(View view) {
148+
String enteredValue = enterAmountW.getText().toString();
149+
if (!enteredValue.isEmpty()) {
150+
try {
151+
edtWalletAmount = Integer.parseInt(enteredValue);
152+
if (promoCheckboxW.isChecked()) {
153+
edtWalletAmount += promoCodeAmount;
154+
}
155+
int amountInPaise = edtWalletAmount * 100;
156+
newAmount = amountInPaise;
157+
// Continue with the rest of your code to open Razorpay with the newAmount
158+
} catch (NumberFormatException e) {
159+
Toast.makeText(getApplicationContext(), "Invalid amount entered.", Toast.LENGTH_SHORT).show();
160+
}
161+
} else {
162+
Toast.makeText(getApplicationContext(), "Please enter an amount.", Toast.LENGTH_SHORT).show();
163+
}
164+
try {
165+
// You need to pass a JSONObject with payment details to Razorpay
166+
JSONObject options = new JSONObject();
167+
options.put("name", "BugBazaar Private Limited"); // Replace with your company name
168+
options.put("description", "Add money to wallet");
169+
options.put("currency", "INR"); // Replace with the appropriate currency code
170+
Log.d("newAmount2",String.valueOf(newAmount));
171+
options.put("amount", newAmount); // Amount should be in paise
172+
options.put("prefill.email", "customer@example.com");
173+
options.put("prefill.contact", "1234567890");
174+
175+
// Callback URL (optional, can be used for handling payment success or failure)
176+
// options.put("callback_url", "your_callback_url");
177+
checkout.open(Wallet.this, options);
178+
179+
} catch (Exception e) {
180+
e.printStackTrace();
181+
}
182+
}
183+
});
21184
}
22185

23-
//Code to handle backbutton
186+
public void onPaymentSuccess(String s) {
187+
// Clear the EditText after a successful payment
188+
EditText enterAmountEditText = findViewById(R.id.enterAmountW);
189+
enterAmountEditText.setText("");
190+
enterAmountEditText.clearFocus();
191+
CheckBox promoCheckboxW=findViewById(R.id.promoCheckboxW);
192+
promoCheckboxW.clearFocus();
193+
promoCheckboxW.setChecked(false);
194+
195+
// Retrieve the current wallet balance from SharedPreferences
196+
int currentBalance = sharedPreferences.getInt(WALLET_BALANCE_KEY, 12000);
197+
198+
// Calculate the new wallet balance
199+
int updatedBalance = currentBalance + edtWalletAmount;
200+
201+
202+
// Save the updated wallet balance back to SharedPreferences
203+
SharedPreferences.Editor editor = sharedPreferences.edit();
204+
editor.putInt(WALLET_BALANCE_KEY, updatedBalance);
205+
editor.apply();
206+
207+
// Update the displayed wallet balance
208+
walletBalanceW.setText(formatPrice(updatedBalance));
209+
210+
Toast.makeText(this, "Added money to the wallet.", Toast.LENGTH_SHORT).show();
211+
}
212+
213+
public void onPaymentError(int code, String response) {
214+
// Clear the EditText after a successful payment
215+
EditText enterAmountEditText = findViewById(R.id.enterAmountW);
216+
enterAmountEditText.setText("");
217+
218+
switch (code) {
219+
case Checkout.NETWORK_ERROR:
220+
Toast.makeText(this, "Network Error: Please check the internet connection.", Toast.LENGTH_LONG).show();
221+
break;
222+
case Checkout.INVALID_OPTIONS:
223+
// Handle invalid payment options
224+
break;
225+
case Checkout.PAYMENT_CANCELED:
226+
Toast.makeText(this, "Payment Error: Payment Canceled by the user.", Toast.LENGTH_LONG).show();
227+
break;
228+
// Add more cases for specific error codes as needed
229+
}
230+
}
231+
232+
private String formatPrice(int price) {
233+
return String.format("₹%,d", price);
234+
}
235+
236+
// Code to handle the back button
24237
public void onBackButtonClick(View view) {
25238
onBackPressed(); // Navigate back to the previous activity
26239
}
27-
}
240+
241+
// Update finalAmountW with the entered amount
242+
private void updateFinalAmount(String enteredValue) {
243+
if (!enteredValue.isEmpty()) {
244+
try {
245+
int edtWalletAmount = Integer.parseInt(enteredValue);
246+
// Perform any calculations if needed
247+
finalAmountW.setText(formatPrice(edtWalletAmount));
248+
} catch (NumberFormatException e) {
249+
finalAmountW.setText("Invalid amount");
250+
}
251+
} else {
252+
finalAmountW.setText("₹");
253+
}
254+
}
255+
}

0 commit comments

Comments
 (0)