Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vedant #36

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

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

10 changes: 3 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
tools:ignore="CustomPermissionTypo"
tools:replace="android:fullBackupContent"
tools:targetApi="31">
<activity
android:name=".ui.BaseActivity"
android:exported="false" />
<activity
android:name=".ui.RASPSettings"
android:exported="false" />
Expand All @@ -56,9 +59,6 @@
<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 Down Expand Up @@ -134,10 +134,6 @@
</intent-filter>
</activity>

<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />

<service
android:name=".MyFirebaseInstanceIDService"
android:exported="true">
Expand Down
24 changes: 10 additions & 14 deletions app/src/main/java/com/BugBazaar/controller/UserAuthSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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, "");
}
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/BaseActivity.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/BugBazaar/ui/Contact_us.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/BugBazaar/ui/ContactsPack/ReferUs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 3 additions & 16 deletions app/src/main/java/com/BugBazaar/ui/CreatePasscode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.List;


public class DetailedProductActivity extends AppCompatActivity {
public class DetailedProductActivity extends BaseActivity {

private List<CartItem> cartItems; // Declare cartItems here
protected void onCreate(Bundle savedInstanceState) {
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/BugBazaar/ui/MyProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
52 changes: 42 additions & 10 deletions app/src/main/java/com/BugBazaar/ui/NavigationDrawer_Dashboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,20 +44,26 @@ public class NavigationDrawer_Dashboard extends AppCompatActivity implements che
private Toolbar toolbar;
private GridView productGridView;
private List<Product> 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 {
Expand Down Expand Up @@ -192,6 +199,7 @@ public void onClick(View v) {




//Adding actions for each items in navigation drawer
navigationView.setNavigationItemSelectedListener(item -> {
int itemId = item.getItemId();
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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.

}
Expand Down
56 changes: 56 additions & 0 deletions app/src/main/java/com/BugBazaar/ui/RASPSettings.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading