Skip to content

Commit db88558

Browse files
committed
1. Added promocode check:
- Promocode checkbox will appear only for the first time.
1 parent d337e0b commit db88558

File tree

5 files changed

+151
-20
lines changed

5 files changed

+151
-20
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
tools:ignore="ScopedStorage" />
88
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
99
<uses-permission android:name="android.permission.INTERNET" />
10-
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
10+
<uses-permission android:name="android.permission.READ_CONTACTS" />
1111

1212
<permission
1313
android:name="com.BugBazaar.permission.contacts"
@@ -22,7 +22,6 @@
2222
</queries>
2323

2424
<application
25-
2625
android:allowBackup="true"
2726
android:allowTaskReparenting="true"
2827
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -39,6 +38,9 @@
3938
tools:ignore="CustomPermissionTypo"
4039
tools:replace="android:fullBackupContent"
4140
tools:targetApi="31">
41+
<activity
42+
android:name=".ui.Address"
43+
android:exported="true" />
4244
<activity
4345
android:name=".ui.Wallet"
4446
android:exported="true" />
@@ -112,9 +114,7 @@
112114
<activity
113115
android:name=".ui.Signin"
114116
android:clearTaskOnLaunch="true"
115-
android:exported="true">
116-
117-
</activity>
117+
android:exported="true"></activity>
118118
<activity
119119
android:name=".ui.Deeplink"
120120
android:exported="true">
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.BugBazaar.ui;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
import com.BugBazaar.R;
10+
11+
public class Address extends AppCompatActivity {
12+
13+
@Override
14+
protected void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_address);
17+
//Toolbar title set
18+
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
19+
toolbarTitle.setText("Addresses");
20+
21+
22+
23+
}
24+
//Code to handle backbutton
25+
public void onBackButtonClick(View view) {
26+
onBackPressed(); // Navigate back to the previous activity
27+
}
28+
}

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ public class Wallet extends AppCompatActivity implements PaymentResultListener {
3838
private TextView finalAmountW;
3939
private int edtWalletAmount=0;
4040
int additionalAmount=0;
41-
boolean promoredeem;
41+
boolean promoredeem=true;
4242
double promoCodeAmount = DiscountDataManager.getInstance().getDiscountPrice();
4343

4444
// Now you can use the 'discountPrice' in your destination activity.
4545

46-
4746
@Override
4847
protected void onCreate(Bundle savedInstanceState) {
4948
super.onCreate(savedInstanceState);
@@ -52,6 +51,9 @@ protected void onCreate(Bundle savedInstanceState) {
5251
// Initialize SharedPreferences
5352
sharedPreferences = getSharedPreferences("MyWalletPrefs", Context.MODE_PRIVATE);
5453

54+
// Fetch the promoredeem value from shared preferences with a default of false
55+
promoredeem = sharedPreferences.getBoolean("promoredeem", false);
56+
5557
// Toolbar title set
5658
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
5759
toolbarTitle.setText("Wallet");
@@ -94,22 +96,32 @@ public void afterTextChanged(Editable s) {
9496

9597
// Add a listener for the promoCheckbox
9698

97-
99+
if(!promoredeem){
100+
CheckBox promoCheckboxWW=findViewById(R.id.promoCheckboxW);
101+
promoCheckboxWW.setVisibility(View.VISIBLE);
102+
promoCheckboxWW.setChecked(true);
103+
}
98104

99105

100106
promoCheckboxW.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
101107
@Override
102108
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
103-
try {
104-
int enteredAmount = Integer.parseInt(enterAmountW.getText().toString());
105-
if (isChecked) {
106-
enteredAmount += promoCodeAmount*100;
109+
if (!promoredeem) {
110+
try {
111+
int enteredAmount = Integer.parseInt(enterAmountW.getText().toString());
112+
if (isChecked) {
113+
enteredAmount += promoCodeAmount * 100;
114+
115+
}
116+
// Calculate the new amount in paise
117+
newAmount = enteredAmount * 100;
118+
updateFinalAmount(Integer.toString(enteredAmount));
119+
} catch (NumberFormatException e) {
120+
Toast.makeText(getApplicationContext(), "Invalid amount entered.", Toast.LENGTH_SHORT).show();
107121
}
108-
// Calculate the new amount in paise
109-
newAmount = enteredAmount * 100;
110-
updateFinalAmount(Integer.toString(enteredAmount));
111-
} catch (NumberFormatException e) {
112-
Toast.makeText(getApplicationContext(), "Invalid amount entered.", Toast.LENGTH_SHORT).show();
122+
}
123+
else{
124+
promoCheckboxW.setVisibility(View.GONE);
113125
}
114126
}
115127
});
@@ -163,7 +175,7 @@ public void onClick(View view) {
163175
try {
164176
edtWalletAmount = Integer.parseInt(enteredValue);
165177
if (promoCheckboxW.isChecked()) {
166-
edtWalletAmount += promoCodeAmount;
178+
edtWalletAmount += promoCodeAmount*100;
167179
}
168180
int amountInPaise = edtWalletAmount * 100;
169181
newAmount = amountInPaise;
@@ -197,7 +209,15 @@ public void onClick(View view) {
197209
}
198210

199211
public void onPaymentSuccess(String s) {
200-
promoredeem =true;
212+
if (!promoredeem) { // Only set it to true if it's not already true
213+
promoredeem = true; // Set promoredeem to true
214+
215+
// Store the updated promoredeem value in SharedPreferences
216+
SharedPreferences.Editor editor = sharedPreferences.edit();
217+
editor.putBoolean("promoredeem", true);
218+
editor.apply();
219+
220+
}
201221

202222
// Clear the EditText after a successful payment
203223
EditText enterAmountEditText = findViewById(R.id.enterAmountW);
@@ -267,4 +287,13 @@ private void updateFinalAmount(String enteredValue) {
267287
finalAmountW.setText("₹");
268288
}
269289
}
290+
private void setPromoRedeem(boolean value) {
291+
SharedPreferences.Editor editor = sharedPreferences.edit();
292+
editor.putBoolean("promoredeem", value);
293+
editor.apply();
294+
}
295+
private boolean getPromoRedeem() {
296+
return sharedPreferences.getBoolean("promoredeem", false); // The second parameter is the default value if it's not found in shared preferences
297+
}
298+
270299
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".ui.Address"
8+
android:orientation="vertical">
9+
<include
10+
layout="@layout/nav_toolbar_sub"
11+
android:layout_height="wrap_content"
12+
android:layout_width="match_parent"></include>
13+
<LinearLayout
14+
android:id="@+id/addNewAddress"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:orientation="vertical"
18+
android:background="@drawable/summary_box"
19+
android:paddingBottom="10dp">
20+
<TextView
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:paddingTop="10dp"
24+
android:paddingStart="10dp"
25+
android:paddingBottom="10dp"
26+
android:text="Add new address"
27+
android:textColor="@color/main_theme"
28+
android:textSize="35sp"
29+
android:textStyle="bold"
30+
></TextView>
31+
<LinearLayout
32+
android:layout_width="match_parent"
33+
android:layout_height="wrap_content"
34+
android:orientation="horizontal"
35+
android:paddingBottom="10dp">
36+
<EditText
37+
android:layout_weight="2"
38+
android:layout_width="0dp"
39+
android:layout_height="wrap_content"
40+
android:paddingTop="10dp"
41+
android:paddingStart="10dp"
42+
android:textSize="20sp"
43+
android:hint="Enter new address"
44+
android:textStyle="bold"
45+
></EditText>
46+
47+
<Button
48+
android:layout_width="wrap_content"
49+
android:layout_height="wrap_content"
50+
android:text="Save"></Button>
51+
52+
</LinearLayout>
53+
</LinearLayout>
54+
<LinearLayout
55+
android:layout_width="match_parent"
56+
android:layout_height="wrap_content"
57+
android:orientation="vertical"
58+
android:background="@drawable/summary_box"
59+
android:paddingBottom="10dp">
60+
<TextView
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:paddingTop="10dp"
64+
android:paddingStart="10dp"
65+
android:paddingBottom="10dp"
66+
android:text="Your saved addresses"
67+
android:textColor="@color/main_theme"
68+
android:textSize="35sp"
69+
android:textStyle="bold"
70+
></TextView>
71+
</LinearLayout>
72+
73+
</LinearLayout>

app/src/main/res/layout/activity_wallet.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
android:layout_marginLeft="10dp"
103103
android:paddingStart="10dp"
104104
android:textSize="15dp"
105-
android:text="Apply promocode"></CheckBox>
105+
android:text="Apply promocode"
106+
android:visibility="gone"></CheckBox>
106107
</LinearLayout>
107108
<LinearLayout
108109
android:layout_width="match_parent"

0 commit comments

Comments
 (0)