diff --git a/.idea/misc.xml b/.idea/misc.xml index 21f362b..7d78d96 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 93ca219..b6e9dc6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,6 +38,9 @@ tools:ignore="CustomPermissionTypo" tools:replace="android:fullBackupContent" tools:targetApi="31"> + @@ -56,9 +59,6 @@ - @@ -134,10 +134,6 @@ - - diff --git a/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java b/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java index e2d6d45..e511a39 100644 --- a/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java +++ b/app/src/main/java/com/BugBazaar/controller/UserAuthSave.java @@ -3,34 +3,33 @@ import android.content.Context; import android.content.SharedPreferences; +import com.BugBazaar.ui.SessionManager; + public class UserAuthSave { - private static final String USER_PREFERENCES = "user_auth"; + private static final String USER_PREFERENCES = "user_auth"; // shared_pref name + private static final String KEY_LOGGED_IN = "logged_in"; private static final String KEY_USERNAME = "username"; private static final String KEY_PASSWORD = "password"; - private static final String KEY_LOGGED_IN = "logged_in"; - private static final String keypasscode = "passcode"; private static final String keypasscode_flag = "passcode_flag"; - - private static SharedPreferences sharedPreferences; + private SessionManager sessionManager; // Move the initialization to a constructor public UserAuthSave(Context context) { sharedPreferences = context.getSharedPreferences(USER_PREFERENCES, Context.MODE_PRIVATE); + sessionManager = new SessionManager(context); // Initialize SessionManager in the constructor } - public static void saveUserCredentials(String username, String password, boolean loggedIn) { - + public void saveUserData(String randomToken, boolean loggedIn) { SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString(KEY_USERNAME, username); - editor.putString(KEY_PASSWORD, password); - editor.putBoolean(KEY_LOGGED_IN, loggedIn); + // Use SessionManager to save the user token and login state + sessionManager.setUserToken(randomToken); + sessionManager.setLoggedIn(loggedIn); editor.apply(); } - public static SharedPreferences getSharedPreferences() { return sharedPreferences; } @@ -40,15 +39,12 @@ public static void setSharedPreferences(SharedPreferences sharedPreferences) { } public static void savepasscode(int passcode) { - SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(keypasscode, String.valueOf(passcode)); editor.putBoolean(keypasscode_flag, true); editor.apply(); } - - public static String getSavedUsername() { return sharedPreferences.getString(KEY_USERNAME, ""); } diff --git a/app/src/main/java/com/BugBazaar/ui/BaseActivity.java b/app/src/main/java/com/BugBazaar/ui/BaseActivity.java new file mode 100644 index 0000000..a67dff6 --- /dev/null +++ b/app/src/main/java/com/BugBazaar/ui/BaseActivity.java @@ -0,0 +1,27 @@ +package com.BugBazaar.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import com.BugBazaar.ui.Signin; + +public class BaseActivity extends AppCompatActivity { + protected SessionManager sessionManager; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Initialize the SessionManager in your base activity + sessionManager = new SessionManager(this); + + // Check the session status + if (sessionManager.getUserToken() == null) { + Toast.makeText(this, "Please login first", Toast.LENGTH_SHORT).show(); + startActivity(new Intent(this, Signin.class)); + finish(); + } + } +} diff --git a/app/src/main/java/com/BugBazaar/ui/Contact_us.java b/app/src/main/java/com/BugBazaar/ui/Contact_us.java index 806908d..2c666bb 100644 --- a/app/src/main/java/com/BugBazaar/ui/Contact_us.java +++ b/app/src/main/java/com/BugBazaar/ui/Contact_us.java @@ -26,7 +26,7 @@ import java.util.HashMap; import java.util.Map; -public class Contact_us extends AppCompatActivity { +public class Contact_us extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/BugBazaar/ui/ContactsPack/ReferUs.java b/app/src/main/java/com/BugBazaar/ui/ContactsPack/ReferUs.java index 0607785..e80481d 100644 --- a/app/src/main/java/com/BugBazaar/ui/ContactsPack/ReferUs.java +++ b/app/src/main/java/com/BugBazaar/ui/ContactsPack/ReferUs.java @@ -15,9 +15,10 @@ import android.widget.Toast; import com.BugBazaar.R; +import com.BugBazaar.ui.BaseActivity; import com.BugBazaar.ui.ContactsPack.SelectContacts; -public class ReferUs extends AppCompatActivity { +public class ReferUs extends BaseActivity { Button btnCopyLink; Button btnSendEmail; diff --git a/app/src/main/java/com/BugBazaar/ui/CreatePasscode.java b/app/src/main/java/com/BugBazaar/ui/CreatePasscode.java index c728dc2..5dfd943 100644 --- a/app/src/main/java/com/BugBazaar/ui/CreatePasscode.java +++ b/app/src/main/java/com/BugBazaar/ui/CreatePasscode.java @@ -64,30 +64,17 @@ public void onClick(View view) { String enteredPasscode = editTextPasscode.getText().toString(); if(enteredPasscode.length()!=4){ - Toast.makeText(CreatePasscode.this, "Passcode of 4 numbers!", Toast.LENGTH_SHORT).show(); return; + }else{ + UserAuthSave.savepasscode(Integer.parseInt(enteredPasscode)); + Toast.makeText(CreatePasscode.this, " New Passcode created!", Toast.LENGTH_SHORT).show(); } - - UserAuthSave.savepasscode(Integer.parseInt(enteredPasscode)); - Toast.makeText(CreatePasscode.this, " New Passcode created!", Toast.LENGTH_SHORT).show(); - CreateSessiontoken(UserAuthSave.getSavedUsername(),UserAuthSave.getpasscode(),UserAuthSave.getpasscode()); - - - // have to change startActivity(new Intent(getApplicationContext(),NavigationDrawer_Dashboard.class)); - - } }); - } - - private void CreateSessiontoken(String savedUsername, String getpasscode, String getpasscode1) { - - - } //Numpad click handling diff --git a/app/src/main/java/com/BugBazaar/ui/DetailedProductActivity.java b/app/src/main/java/com/BugBazaar/ui/DetailedProductActivity.java index 35bf051..b6723db 100644 --- a/app/src/main/java/com/BugBazaar/ui/DetailedProductActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/DetailedProductActivity.java @@ -23,7 +23,7 @@ import java.util.List; -public class DetailedProductActivity extends AppCompatActivity { +public class DetailedProductActivity extends BaseActivity { private List cartItems; // Declare cartItems here protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/BugBazaar/ui/MyProfile.java b/app/src/main/java/com/BugBazaar/ui/MyProfile.java index e9aa6b3..b51f2b9 100644 --- a/app/src/main/java/com/BugBazaar/ui/MyProfile.java +++ b/app/src/main/java/com/BugBazaar/ui/MyProfile.java @@ -34,7 +34,7 @@ import java.util.HashMap; import java.util.Map; -public class MyProfile extends AppCompatActivity { +public class MyProfile extends BaseActivity { private FirebaseStorage firebaseStorage; private static final int SELECT_PHOTO_REQUEST = 1; @@ -69,14 +69,14 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_myprofile); - UserAuthSave userAuthSave = new UserAuthSave(getApplicationContext()); - - if (!UserAuthSave.isLoggedIn()) { - - startActivity(new Intent(this, Signin.class)); - - - } +// UserAuthSave userAuthSave = new UserAuthSave(getApplicationContext()); +// +// if (!UserAuthSave.isLoggedIn()) { +// +// startActivity(new Intent(this, Signin.class)); +// +// +// } //Firebase 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 3adacc5..8fb1d2c 100644 --- a/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java +++ b/app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java @@ -11,6 +11,7 @@ import android.net.Uri; import android.os.Bundle; import android.util.Log; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -43,20 +44,26 @@ public class NavigationDrawer_Dashboard extends AppCompatActivity implements che private Toolbar toolbar; private GridView productGridView; private List productList; + private SessionManager sessionManager; // Move the initialization to a constructor @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_navigation_drawer_dashboard); - -///// first check !!!!!! - + //session Check + sessionManager = new SessionManager(this); + if(sessionManager.getUserToken()!=null){ + sessionManager.setLoggedIn(true); + updateLoginMenuItem(sessionManager.isLoggedIn()); + }else{ + sessionManager.setLoggedIn(false); + updateLoginMenuItem(sessionManager.isLoggedIn()); + } + ///// first check !!!!!! if (AppInitializationManager.isFirstRun(this)) { - - checkWorker check = new checkWorker(this); try { @@ -192,6 +199,7 @@ public void onClick(View v) { + //Adding actions for each items in navigation drawer navigationView.setNavigationItemSelectedListener(item -> { int itemId = item.getItemId(); @@ -242,12 +250,19 @@ else if (itemId == R.id.itemCart) { drawerLayout.closeDrawer(GravityCompat.START); return true; } - else if (itemId == R.id.itemLoginLogout) { - + else if (itemId == R.id.itemLoginButton) { + if(sessionManager.isLoggedIn()) { + //Logout the user + sessionManager.setLoggedIn(false); + sessionManager.setUserToken(null); + Toast.makeText(getApplicationContext(),"You have been logged out successfully!!",Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(NavigationDrawer_Dashboard.this, Signin.class); + startActivity(intent); + }else{ Intent intent = new Intent(NavigationDrawer_Dashboard.this, Signin.class); startActivity(intent); drawerLayout.closeDrawer(GravityCompat.START); - return true; + return true;} }else if (itemId == R.id.itemRASP_Settings){ Intent intent = new Intent(NavigationDrawer_Dashboard.this, RASPSettings.class); startActivity(intent); @@ -257,9 +272,24 @@ else if (itemId == R.id.itemLoginLogout) { drawerLayout.closeDrawer(GravityCompat.START); return true; }); - } + } + private void updateLoginMenuItem(boolean isLoggedIn) { + Menu menu = navigationView.getMenu(); + MenuItem loginMenuItem = menu.findItem(R.id.itemLoginButton); + + if (loginMenuItem != null) { + if (isLoggedIn) { + loginMenuItem.setTitle("Logout"); + loginMenuItem.setIcon(R.drawable.baseline_logout_24); + } else { + loginMenuItem.setTitle("Login"); + loginMenuItem.setIcon(R.drawable.baseline_login_24); + } + } + } + @Override public void onDiscountCalculated(double discountedPrice) { // Now you can access and use the discountedPrice in your activity @@ -272,9 +302,11 @@ private void handleDiscountedPrice(double discountedPrice) { PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,new Intent(this,Signin.class),0); // This is the first run, show your notification AppInitializationManager.showNotification(this); - CustomDialog.showCustomDialog(this, " \uD83C\uDF89 Congratulations!! \uD83C\uDF89", "You've received a ₹"+ finalDiscount+" wallet balance. Login to Redeem.",pendingIntent); + CustomDialog.showCustomDialog(this, " \uD83C\uDF89 Congratulations!! \uD83C\uDF89", "You've received a ₹"+ finalDiscount+" worth of promotional wallet balance. Login and goto Wallet to redeem.",pendingIntent); AppInitializationManager.markFirstRunDone(this); + sessionManager = new SessionManager(this); + sessionManager.setKeyPromotionalNotifSent(true); //When click on OK, navigate to Sign-in activity. } diff --git a/app/src/main/java/com/BugBazaar/ui/RASPSettings.java b/app/src/main/java/com/BugBazaar/ui/RASPSettings.java index 1f97b20..7954ce4 100644 --- a/app/src/main/java/com/BugBazaar/ui/RASPSettings.java +++ b/app/src/main/java/com/BugBazaar/ui/RASPSettings.java @@ -1,5 +1,7 @@ package com.BugBazaar.ui; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; import android.widget.CompoundButton; @@ -30,6 +32,60 @@ protected void onCreate(Bundle savedInstanceState) { switch1.setOnCheckedChangeListener(new SwitchListener()); switch2.setOnCheckedChangeListener(new SwitchListener()); switch3.setOnCheckedChangeListener(new SwitchListener()); + + // Get SharedPreferences + SharedPreferences sharedPreferences = getSharedPreferences("SwitchStatePrefs", Context.MODE_PRIVATE); + // Set the initial state of each switch based on the stored values + switch1.setChecked(sharedPreferences.getBoolean("switch1_state", false)); + switch2.setChecked(sharedPreferences.getBoolean("switch2_state", false)); + switch3.setChecked(sharedPreferences.getBoolean("switch3_state", false)); + switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Store the state of switch1 in SharedPreferences + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean("switch1_state", isChecked); + editor.apply(); + + // If switch1 is turned on, turn off other switches + if (isChecked) { + switch2.setChecked(false); + switch3.setChecked(false); + } + } + }); + switch2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Store the state of switch1 in SharedPreferences + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean("switch2_state", isChecked); + editor.apply(); + + // If switch1 is turned on, turn off other switches + if (isChecked) { + switch1.setChecked(false); + switch3.setChecked(false); + } + } + }); + switch3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + // Store the state of switch1 in SharedPreferences + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putBoolean("switch3_state", isChecked); + editor.apply(); + + // If switch1 is turned on, turn off other switches + if (isChecked) { + switch1.setChecked(false); + switch2.setChecked(false); + } + } + }); + + } private class SwitchListener implements CompoundButton.OnCheckedChangeListener { diff --git a/app/src/main/java/com/BugBazaar/ui/SessionManager.java b/app/src/main/java/com/BugBazaar/ui/SessionManager.java new file mode 100644 index 0000000..8a8fdd2 --- /dev/null +++ b/app/src/main/java/com/BugBazaar/ui/SessionManager.java @@ -0,0 +1,50 @@ +package com.BugBazaar.ui; + +import android.content.Context; +import android.content.SharedPreferences; + +public class SessionManager { + private static final String PREF_NAME = "SessionStorage"; + private static final String KEY_USER_TOKEN = "userToken"; + private static final String KEY_LOGGED_IN = "loggedIn"; + private static final String KEY_PROMOTIONAL_NOTIF_SENT="isPromotionalNotifSent"; + + private SharedPreferences sharedPreferences; + private SharedPreferences.Editor editor; + + public SessionManager(Context context) { + sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); + editor = sharedPreferences.edit(); + } + + public void setLoggedIn(boolean loggedIn) { + editor.putBoolean(KEY_LOGGED_IN, loggedIn); + editor.apply(); + } + public void setKeyPromotionalNotifSent(boolean isPromotionalNotifSent){ + editor.putBoolean(KEY_PROMOTIONAL_NOTIF_SENT,isPromotionalNotifSent); + editor.apply(); + } + + public boolean isLoggedIn() { + return sharedPreferences.getBoolean(KEY_LOGGED_IN, false); + } + + public void setUserToken(String token) { + editor.putString(KEY_USER_TOKEN, token); + editor.apply(); + } + + public String getUserToken() { + return sharedPreferences.getString(KEY_USER_TOKEN, null); + } + public boolean getIsPromotionalNotifSent(){return sharedPreferences.getBoolean(KEY_PROMOTIONAL_NOTIF_SENT,false);} + + public void logout() { + editor.remove(KEY_LOGGED_IN); + editor.remove(KEY_USER_TOKEN); + editor.apply(); + } +} + + diff --git a/app/src/main/java/com/BugBazaar/ui/Signin.java b/app/src/main/java/com/BugBazaar/ui/Signin.java index 31e519d..d4c4372 100644 --- a/app/src/main/java/com/BugBazaar/ui/Signin.java +++ b/app/src/main/java/com/BugBazaar/ui/Signin.java @@ -15,6 +15,9 @@ import com.BugBazaar.utils.PermissionManager; import com.BugBazaar.utils.PermissionCallback; +import java.math.BigInteger; +import java.security.SecureRandom; + public class Signin extends AppCompatActivity implements PermissionCallback { private com.BugBazaar.controller.LoginController loginController; @@ -27,39 +30,31 @@ public class Signin extends AppCompatActivity implements PermissionCallback { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - - + usernameEditText = findViewById(R.id.editUsername); + passwordEditText = findViewById(R.id.editPassword); + loginButton = findViewById(R.id.btnLogin); + // Initialize the SessionManager in your activity + SessionManager sessionManager = new SessionManager(this); + String randomToken = TokenGenerator.generateRandomToken(64); UserAuthSave userAuthSave = new UserAuthSave(getApplicationContext()); // 'this' refers to the Activity's context - - if(UserAuthSave.isLoggedIn()){ + if(sessionManager.isLoggedIn()){ Toast.makeText(Signin.this, "Welcome back !!", Toast.LENGTH_SHORT).show(); + //If getpasscode_flag is true, navigate to "Enter passcode" activity - Log.d("passcodemait", String.valueOf(UserAuthSave.getpasscode_flag())); - - if(UserAuthSave.getpasscode_flag()){ - + if(userAuthSave.getpasscode_flag()){ startActivity(new Intent(this,PasscodeActivity.class)); } - + //If getpasscode_flag is false, navigate to "Create passcode" activity else { + Toast.makeText(getApplicationContext(),"Please create 4 digit passcode",Toast.LENGTH_SHORT).show(); startActivity(new Intent(this,CreatePasscode.class)); - - } - return; - - - - - - } loginController = new com.BugBazaar.controller.LoginController(); - permissionManager = new PermissionManager(this, this); @@ -72,38 +67,49 @@ protected void onCreate(Bundle savedInstanceState) { } - - - usernameEditText = findViewById(R.id.editUsername); - passwordEditText = findViewById(R.id.editPassword); - loginButton = findViewById(R.id.btnLogin); - loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String username = usernameEditText.getText().toString().trim(); String password = passwordEditText.getText().toString().trim(); + //This will fetch hex username and password from CredentialLoader and compare it with user provided values class. + // It will return true if values are correct. Will return false if values are incorrect. boolean isLoggedin= loginController.validateLogin(username, password); - - if (isLoggedin) { - - UserAuthSave.saveUserCredentials(username,password, true); - + if (isLoggedin==true) { + sessionManager.setLoggedIn(true); + userAuthSave.saveUserData( randomToken,isLoggedin); // Successful login, do something (e.g., start a new activity) Toast.makeText(Signin.this, "Login successful!", Toast.LENGTH_SHORT).show(); - - startActivity(new Intent(getApplicationContext(),CreatePasscode.class)); + startActivity(new Intent(getApplicationContext(),CreatePasscode.class)); } else { - -// UserAuthSave.saveUserCredentials(username,password, false); +// UserAuthSave.saveUserData(randomToken,false); // Failed login, show an error message Toast.makeText(Signin.this, "Invalid credentials!", Toast.LENGTH_SHORT).show(); } } }); } + public static class TokenGenerator { + + public static String generateRandomToken(int length) { + SecureRandom random = new SecureRandom(); + byte[] bytes = new byte[length / 2]; + random.nextBytes(bytes); + BigInteger tokenValue = new BigInteger(1, bytes); + + // Convert the random bytes to a hexadecimal string + String token = tokenValue.toString(16); + + // If the generated token is shorter than the desired length, pad with zeros + while (token.length() < length) { + token = "0" + token; + } + + return token; + } + } @Override public void onPermissionGranted() { diff --git a/app/src/main/java/com/BugBazaar/ui/Wallet.java b/app/src/main/java/com/BugBazaar/ui/Wallet.java index 5eeafa0..5e62afd 100644 --- a/app/src/main/java/com/BugBazaar/ui/Wallet.java +++ b/app/src/main/java/com/BugBazaar/ui/Wallet.java @@ -3,6 +3,7 @@ import androidx.appcompat.app.AppCompatActivity; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.text.Editable; @@ -27,12 +28,13 @@ import com.razorpay.PaymentResultListener; import org.json.JSONObject; -public class Wallet extends AppCompatActivity implements PaymentResultListener { +public class Wallet extends BaseActivity implements PaymentResultListener { private static final String WALLET_BALANCE_KEY = "wallet_balance"; private TextView walletBalanceW; private RadioGroup rbGroupPaymentOptionsW; private SharedPreferences sharedPreferences; + private SharedPreferences sessionManager; private int newAmount; private EditText enterAmountW; private TextView finalAmountW; @@ -40,7 +42,6 @@ public class Wallet extends AppCompatActivity implements PaymentResultListener { int additionalAmount=0; boolean promoredeem=true; double promoCodeAmount = DiscountDataManager.getInstance().getDiscountPrice(); - // Now you can use the 'discountPrice' in your destination activity. @Override @@ -93,13 +94,14 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { public void afterTextChanged(Editable s) { } }); - + SessionManager sessionManager=new SessionManager (this); + boolean isPromotionNofiyToUser = sessionManager.getIsPromotionalNotifSent(); + Log.d("isPromotionNofiyToUser",String.valueOf(isPromotionNofiyToUser)); // Add a listener for the promoCheckbox - if(!promoredeem){ + if(!promoredeem && isPromotionNofiyToUser==true){ CheckBox promoCheckboxWW=findViewById(R.id.promoCheckboxW); promoCheckboxWW.setVisibility(View.VISIBLE); - promoCheckboxWW.setChecked(true); } @@ -295,5 +297,4 @@ private void setPromoRedeem(boolean value) { private boolean getPromoRedeem() { return sharedPreferences.getBoolean("promoredeem", false); // The second parameter is the default value if it's not found in shared preferences } - } diff --git a/app/src/main/java/com/BugBazaar/ui/addresses/Address.java b/app/src/main/java/com/BugBazaar/ui/addresses/Address.java index 6df50c8..4813ead 100644 --- a/app/src/main/java/com/BugBazaar/ui/addresses/Address.java +++ b/app/src/main/java/com/BugBazaar/ui/addresses/Address.java @@ -1,4 +1,5 @@ package com.BugBazaar.ui.addresses; +import android.content.Intent; import android.database.sqlite.SQLiteDatabase; import android.database.Cursor; import android.content.ContentValues; @@ -16,10 +17,14 @@ import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import com.BugBazaar.R; -import java.util.List; +import com.BugBazaar.ui.BaseActivity; +import com.BugBazaar.ui.SessionManager; +import com.BugBazaar.ui.Signin; -public class Address extends AppCompatActivity { +import java.util.List; +public class Address extends BaseActivity { + private SessionManager sessionManager; private EditText editTextNewAddrNickName; private EditText editTextNewAddress; private EditText searchBoxEditText; @@ -33,6 +38,15 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_address); addressListLayout = findViewById(R.id.addressListLayout); + //Session check + sessionManager = new SessionManager(this); + if (sessionManager.getUserToken()==null) { + Toast.makeText(getApplicationContext(),"Please login first",Toast.LENGTH_SHORT).show(); + // The user is not logged in; redirect to the login activity + startActivity(new Intent(this, Signin.class)); + finish(); // Prevent going back to the previous activity + } + //Toolbar title set TextView toolbarTitle = findViewById(R.id.toolbarTitle); toolbarTitle.setText("Addresses"); diff --git a/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java b/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java index ed721fe..2066df6 100644 --- a/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/cart/CartActivity.java @@ -13,12 +13,13 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.BugBazaar.R; +import com.BugBazaar.ui.BaseActivity; import com.BugBazaar.ui.payment.OrderSummary; import java.util.List; import java.util.Locale; -public class CartActivity extends AppCompatActivity { +public class CartActivity extends BaseActivity { private RecyclerView cartRecyclerView; private CartAdapter cartAdapter; diff --git a/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryActivity.java b/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryActivity.java index 77d650f..801f515 100644 --- a/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryActivity.java +++ b/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryActivity.java @@ -18,9 +18,10 @@ import java.util.List; import com.BugBazaar.R; +import com.BugBazaar.ui.BaseActivity; import com.BugBazaar.ui.NavigationDrawer_Dashboard; -public class OrderHistoryActivity extends AppCompatActivity { +public class OrderHistoryActivity extends BaseActivity { private EditText searchBoxOrders; private RecyclerView recyclerView; private Button btnSearchOrders; @@ -64,7 +65,7 @@ public void onClick(View view) { String searchText = searchBoxOrders.getText().toString(); // Check if the search text contains the blocked characters (single quote or hyphen) SQLi Challange. - if (!searchText.contains("'") && !searchText.contains("-")) { + if (!searchText.contains("'--") && !searchText.contains("' or ''='")&& !searchText.contains("' OR ''='") && !searchText.contains("' Or ''='") && !searchText.contains("' oR ''='")) { // If the search text is valid, perform the search filterOrdersByOrderID(searchText); } else { diff --git a/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryDatabaseHelper.java b/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryDatabaseHelper.java index afa37d4..78c8c7f 100644 --- a/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryDatabaseHelper.java +++ b/app/src/main/java/com/BugBazaar/ui/myorders/OrderHistoryDatabaseHelper.java @@ -203,7 +203,7 @@ public String findLastOrderID(SQLiteDatabase db) { } private void insertInitialOrders(SQLiteDatabase db) { String[][] initialData = { - {"ORDER-99", "Product Name 1", "3", "200"} + {"ORDER-99", "Hidden Secret Order.Yay!! you found it!! ", "2", "200"} // Add more initial data here }; diff --git a/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java b/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java deleted file mode 100644 index 4383fd5..0000000 --- a/app/src/main/java/com/BugBazaar/ui/payment/TestRazorPay.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.BugBazaar.ui.payment; - -import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.Toast; - -import com.BugBazaar.ui.cart.NotificationHelper; -import com.razorpay.Checkout; -import com.razorpay.PaymentResultListener; // Import the PaymentResultListener -import com.BugBazaar.R; -import org.json.JSONException; -import org.json.JSONObject; - -public class TestRazorPay extends AppCompatActivity implements PaymentResultListener { // Implement the interface - private Button btnProceedPayment; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_test_razor_pay); - btnProceedPayment = findViewById(R.id.btnProceedPayment); - - // Initialize Razorpay with your API key - Checkout.preload(getApplicationContext()); - Checkout checkout = new Checkout(); - checkout.setKeyID("rzp_test_YEExgm42Uvy0u1"); - - btnProceedPayment.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - // Create payment options - JSONObject options = new JSONObject(); - try { - options.put("name", "BugBazaar Retailers"); - options.put("description", "Purchase Description"); - //options.put("image", "YOUR_LOGO_URL"); - options.put("currency", "INR"); // Change to your currency code - options.put("amount", "10000"); // Change to the actual amount in paise - //options.put("order_id", "23287827788382387231923921392173123123213"); // The order ID received from your server - options.put("prefill.email", "customer@example.com"); - options.put("prefill.contact", "1234567890"); - } catch (JSONException e) { - e.printStackTrace(); - // Handle JSON exception here - } - - // Open Razorpay payment dialog - try { - checkout.open(TestRazorPay.this, options); - } catch (Exception e) { - e.printStackTrace(); - // Handle any exceptions that may occur while opening the payment dialog - } - } - }); - } - - public void onPaymentSuccess(String s) { - - - - } - - @Override - public void onPaymentError(int code, String response) { - // Handle payment error - // This method is called when there is a payment error - - // Log the error code and response for debugging - Log.e("Razorpay Error", "Error Code: " + code); - Log.e("Razorpay Error", "Error Response: " + response); - - // You can display an error message to the user or take appropriate action based on the error code and response - // For example, you can show a Toast message with the error details: - Toast.makeText(this, "Payment Error: " + response, Toast.LENGTH_SHORT).show(); - - // You can also perform additional error handling based on the error code if needed - switch (code) { - case Checkout.NETWORK_ERROR: - // Handle network-related errors - break; - case Checkout.INVALID_OPTIONS: - // Handle invalid payment options - break; - case Checkout.PAYMENT_CANCELED: - // Handle payment cancellation by the user - break; - // Add more cases for specific error codes as needed - } - } -} diff --git a/app/src/main/res/font/PlaypenSans.ttf b/app/src/main/res/font/PlaypenSans.ttf new file mode 100644 index 0000000..7117fb4 Binary files /dev/null and b/app/src/main/res/font/PlaypenSans.ttf differ diff --git a/app/src/main/res/font/aldrich.xml b/app/src/main/res/font/aldrich.xml deleted file mode 100644 index 537af3e..0000000 --- a/app/src/main/res/font/aldrich.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/app/src/main/res/font/coolvetica.otf b/app/src/main/res/font/coolvetica.otf deleted file mode 100644 index fd49379..0000000 Binary files a/app/src/main/res/font/coolvetica.otf and /dev/null differ diff --git a/app/src/main/res/font/font_family.xml b/app/src/main/res/font/font_family.xml new file mode 100644 index 0000000..98770a1 --- /dev/null +++ b/app/src/main/res/font/font_family.xml @@ -0,0 +1,7 @@ + + + + diff --git a/app/src/main/res/font/ptsansregular.ttf b/app/src/main/res/font/ptsansregular.ttf new file mode 100644 index 0000000..adaf671 Binary files /dev/null and b/app/src/main/res/font/ptsansregular.ttf differ diff --git a/app/src/main/res/font/secular_one.xml b/app/src/main/res/font/secular_one.xml deleted file mode 100644 index 8a6552d..0000000 --- a/app/src/main/res/font/secular_one.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/app/src/main/res/font/tiltneon.ttf b/app/src/main/res/font/tiltneon.ttf new file mode 100644 index 0000000..a8b01e6 Binary files /dev/null and b/app/src/main/res/font/tiltneon.ttf differ diff --git a/app/src/main/res/font/ubunturegular.ttf b/app/src/main/res/font/ubunturegular.ttf new file mode 100644 index 0000000..f98a2da Binary files /dev/null and b/app/src/main/res/font/ubunturegular.ttf differ diff --git a/app/src/main/res/layout/activity_create_passcode.xml b/app/src/main/res/layout/activity_create_passcode.xml index 6a401bf..b62908d 100644 --- a/app/src/main/res/layout/activity_create_passcode.xml +++ b/app/src/main/res/layout/activity_create_passcode.xml @@ -19,8 +19,9 @@ android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:text="Create New Passcode" - android:textSize="27dp" - android:textStyle="bold" /> + android:textSize="29dp" + android:textStyle="bold" + android:textColor="@color/main_theme"/> + app:layout_constraintVertical_bias="0.081"> @@ -260,6 +259,7 @@ android:layout_height="149dp" android:layout_weight="0" android:ems="30" + android:paddingTop="10dp" android:inputType="textMultiLine" android:visibility="gone" app:layout_constraintBottom_toBottomOf="@+id/txtViewName2" @@ -302,9 +302,7 @@ android:id="@+id/imageView7" android:layout_width="40dp" android:layout_height="35dp" - android:clickable="true" android:focusable="true" - android:onClick="onProfileImageClick" app:layout_constraintBottom_toBottomOf="@+id/imageView" app:layout_constraintEnd_toEndOf="@+id/imageView" app:layout_constraintHorizontal_bias="0.497" diff --git a/app/src/main/res/layout/activity_order_summary.xml b/app/src/main/res/layout/activity_order_summary.xml index 04d6c09..646a8c2 100644 --- a/app/src/main/res/layout/activity_order_summary.xml +++ b/app/src/main/res/layout/activity_order_summary.xml @@ -218,7 +218,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pay Via Wallet" - android:textSize="20dp" + android:textSize="19dp" android:layout_marginStart="5dp" android:layout_marginBottom="10dp" android:textStyle="bold" @@ -230,7 +230,7 @@ android:layout_width="250dp" android:layout_height="wrap_content" android:text="Pay Via Razorpay" - android:textSize="20dp" + android:textSize="19dp" android:layout_marginStart="5dp" android:textStyle="bold" android:layout_gravity="center_vertical"/> diff --git a/app/src/main/res/layout/activity_passcode.xml b/app/src/main/res/layout/activity_passcode.xml index 92f40a8..4475217 100644 --- a/app/src/main/res/layout/activity_passcode.xml +++ b/app/src/main/res/layout/activity_passcode.xml @@ -19,8 +19,9 @@ android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:text="Enter Passcode" - android:textSize="34sp" - android:textStyle="bold" /> + android:textSize="30sp" + android:textStyle="bold" + android:textColor="@color/main_theme"/> + android:textStyle="bold" + android:textColor="@color/main_theme"> - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_wallet.xml b/app/src/main/res/layout/activity_wallet.xml index 1e976a2..2f601bd 100644 --- a/app/src/main/res/layout/activity_wallet.xml +++ b/app/src/main/res/layout/activity_wallet.xml @@ -99,10 +99,10 @@ android:id="@+id/promoCheckboxW" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="10dp" - android:paddingStart="10dp" + android:layout_marginLeft="8dp" + android:paddingStart="4dp" android:textSize="15dp" - android:text="Apply promocode" + android:text="Apply promotional balance" android:visibility="gone"> + - - - @font/aldrich - @font/secular_one - - diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index c92438d..5e5c0a4 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -11,5 +11,8 @@ @color/black #3a5e7d + + + @font/font_family \ No newline at end of file