diff --git a/Listify/app/src/main/AndroidManifest.xml b/Listify/app/src/main/AndroidManifest.xml index 73d5a0d..7389dd5 100644 --- a/Listify/app/src/main/AndroidManifest.xml +++ b/Listify/app/src/main/AndroidManifest.xml @@ -33,9 +33,9 @@ android:name=".SearchResults" android:label="" android:theme="@style/AppTheme.NoActionBar"> - - + + diff --git a/Listify/app/src/main/java/com/example/listify/AuthManager.java b/Listify/app/src/main/java/com/example/listify/AuthManager.java index 7e38e72..74096fe 100644 --- a/Listify/app/src/main/java/com/example/listify/AuthManager.java +++ b/Listify/app/src/main/java/com/example/listify/AuthManager.java @@ -28,7 +28,6 @@ public class AuthManager { String password = null; volatile boolean waiting = false; - void fetchAuthSession() throws AuthException { waiting = true; Amplify.Auth.fetchAuthSession( @@ -61,6 +60,9 @@ public class AuthManager { return authSession.getUserPoolTokens().getValue().getIdToken(); } + public String getPassword() { + return password; + } public void setAuthSession(AuthSession toSet) { authSession = (AWSCognitoAuthSession) toSet; @@ -117,7 +119,6 @@ public class AuthManager { error -> setAuthError(error) ); throwIfAuthError(); - } public void confirmSignUp(String confirmationCode) throws AuthException { diff --git a/Listify/app/src/main/java/com/example/listify/ListPage.java b/Listify/app/src/main/java/com/example/listify/ListPage.java index f81c481..fa449d2 100644 --- a/Listify/app/src/main/java/com/example/listify/ListPage.java +++ b/Listify/app/src/main/java/com/example/listify/ListPage.java @@ -123,7 +123,7 @@ public class ListPage extends AppCompatActivity { ArrayList pImages; MyAdapter (Context c, ArrayList names, ArrayList stores, ArrayList prices, ArrayList quantity, ArrayList images) { - super(c, R.layout.listproduct, R.id.productView, names); + super(c, R.layout.activity_listproductentry, R.id.productView, names); context = c; pNames = names; pStores = stores; @@ -136,7 +136,7 @@ public class ListPage extends AppCompatActivity { @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View listproduct = layoutInflater.inflate(R.layout.listproduct, parent,false); + View listproduct = layoutInflater.inflate(R.layout.activity_listproductentry, parent,false); decrQuan = (Button) listproduct.findViewById(R.id.buttonDecr); incrQuan = (Button) listproduct.findViewById(R.id.buttonIncr); diff --git a/Listify/app/src/main/java/com/example/listify/MainActivity.java b/Listify/app/src/main/java/com/example/listify/MainActivity.java index 0dfb9cc..d56bbee 100644 --- a/Listify/app/src/main/java/com/example/listify/MainActivity.java +++ b/Listify/app/src/main/java/com/example/listify/MainActivity.java @@ -2,6 +2,7 @@ package com.example.listify; import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import android.util.Log; import android.view.MenuItem; import android.view.View; @@ -14,12 +15,15 @@ import androidx.navigation.NavController; import androidx.navigation.Navigation; import androidx.navigation.ui.AppBarConfiguration; import androidx.navigation.ui.NavigationUI; + import com.amplifyframework.auth.AuthException; import com.example.listify.data.Item; import com.example.listify.data.ItemSearch; import com.example.listify.data.List; import com.example.listify.data.ListEntry; import com.google.android.material.navigation.NavigationView; +import static com.example.listify.SplashActivity.showSplash; + import org.json.JSONException; import java.io.IOException; import java.time.Instant; @@ -29,13 +33,25 @@ import java.util.Random; public class MainActivity extends AppCompatActivity implements CreateListDialogFragment.OnNewListListener { private AppBarConfiguration mAppBarConfiguration; - public static AuthManager am = new AuthManager(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if(showSplash) { + showSplash = false; + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + Intent intent = new Intent(MainActivity.this, SplashActivity.class); + startActivity(intent); + finish(); + } + }, 1); + } + //------------------------------Auth Testing---------------------------------------------// diff --git a/Listify/app/src/main/java/com/example/listify/SplashActivity.java b/Listify/app/src/main/java/com/example/listify/SplashActivity.java new file mode 100644 index 0000000..a5d9c2a --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/SplashActivity.java @@ -0,0 +1,28 @@ +package com.example.listify; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; + +public class SplashActivity extends AppCompatActivity { + public static boolean showSplash = true; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_splashscreen); + + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + showSplash = false; + Intent intent = new Intent(SplashActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + }, 3000); + } +} \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java index a06d23a..f30833b 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java +++ b/Listify/app/src/main/java/com/example/listify/ui/ForgotPasswordPage.java @@ -18,6 +18,7 @@ public class ForgotPasswordPage extends AppCompatActivity implements CodePage.Co String email; String newPassword; + String confirmNewPassword; @Override protected void onCreate(Bundle savedInstanceState) { @@ -28,11 +29,19 @@ public class ForgotPasswordPage extends AppCompatActivity implements CodePage.Co button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress2); - EditText newPasswordText = (EditText) findViewById(R.id.editTextTextPassword2); + EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress); + EditText newPasswordText = (EditText) findViewById(R.id.editTextTextPassword); + EditText confirmNewPasswordText = (EditText) findViewById(R.id.editTextTextPassword2); email = emailText.getText().toString(); newPassword = newPasswordText.getText().toString(); + confirmNewPassword = confirmNewPasswordText.getText().toString(); + + if(!newPassword.equals(confirmNewPassword)) { + TextView invalidCred = findViewById(R.id.textView6); + invalidCred.setText("\"Confirm New Password\" does not match \"New Password\"."); + return; + } try { am.changePassword(email); @@ -41,7 +50,9 @@ public class ForgotPasswordPage extends AppCompatActivity implements CodePage.Co Log.i("Authentication", e.toString()); TextView invalidCred = findViewById(R.id.textView6); invalidCred.setText("Password criteria not met. Please try again."); + return; } + openDialog(); } }); @@ -57,13 +68,12 @@ public class ForgotPasswordPage extends AppCompatActivity implements CodePage.Co if(!cancel) { try { am.confirmPasswordReset(newPassword, code); + Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class); + startActivity(intent); } catch (Exception e) { Log.i("Authentication", e.toString()); } } - - Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class); - startActivity(intent); } } \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java index 6e7b513..5565af8 100644 --- a/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java +++ b/Listify/app/src/main/java/com/example/listify/ui/home/HomeFragment.java @@ -1,5 +1,7 @@ package com.example.listify.ui.home; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.util.Log; @@ -8,6 +10,8 @@ import android.widget.Button; import android.view.ViewGroup; import android.view.LayoutInflater; +import android.widget.EditText; + import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -26,7 +30,7 @@ import java.util.Properties; public class HomeFragment extends Fragment { private Button toLoginPage; - private Button toListPage; + private Button toDeleteAccountPage; public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_home, container, false); @@ -40,26 +44,46 @@ public class HomeFragment extends Fragment { } }); - toListPage = (Button) root.findViewById(R.id.button2); - toListPage.setOnClickListener(new View.OnClickListener() { + toDeleteAccountPage = (Button) root.findViewById(R.id.button2); + toDeleteAccountPage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - //Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class); - //startActivity(intent); - - try { - Properties configs = new Properties(); - try { - configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json"); - } catch (IOException | JSONException e) { - e.printStackTrace(); + View passwordView = getLayoutInflater().inflate(R.layout.activity_code, null); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setView(passwordView); + builder.setTitle("Account deletion verification"); + builder.setMessage("Are you sure you want to delete your account? If so, enter your password below and hit \"Yes\"."); + builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + EditText passwordText = (EditText) passwordView.findViewById(R.id.editTextCode); + String password = passwordText.getText().toString(); + if(password.equals(am.getPassword())) { + try { + Properties configs = new Properties(); + try { + configs = AuthManager.loadProperties(getContext(), "android.resource://" + getActivity().getPackageName() + "/raw/auths.json"); + } catch (IOException | JSONException e) { + e.printStackTrace(); + } + Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); + am.deleteUser(requestor); + } + catch (Exception e) { + Log.i("Authentication", e.toString()); + } + } } - Requestor requestor = new Requestor(am, configs.getProperty("apiKey")); - am.deleteUser(requestor); - } - catch (Exception e) { - Log.i("Authentication", e.toString()); - } + }); + builder.setNegativeButton("No", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + return; + } + }); + + AlertDialog dialog = builder.create(); + dialog.show(); } }); diff --git a/Listify/app/src/main/res/layout/activity_forgotpswd.xml b/Listify/app/src/main/res/layout/activity_forgotpswd.xml index 8e4055c..7080bbd 100644 --- a/Listify/app/src/main/res/layout/activity_forgotpswd.xml +++ b/Listify/app/src/main/res/layout/activity_forgotpswd.xml @@ -9,51 +9,64 @@ android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="52dp" + android:layout_marginTop="51dp" android:text="Submit" app:layout_constraintEnd_toStartOf="@+id/textView6" app:layout_constraintStart_toStartOf="@+id/textView6" app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword2" /> + + - - + app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" /> + + \ No newline at end of file diff --git a/Listify/app/src/main/res/layout/listproduct.xml b/Listify/app/src/main/res/layout/activity_listproductentry.xml similarity index 100% rename from Listify/app/src/main/res/layout/listproduct.xml rename to Listify/app/src/main/res/layout/activity_listproductentry.xml diff --git a/Listify/app/src/main/res/layout/fragment_home.xml b/Listify/app/src/main/res/layout/fragment_home.xml index f43f76a..ecc63ce 100644 --- a/Listify/app/src/main/res/layout/fragment_home.xml +++ b/Listify/app/src/main/res/layout/fragment_home.xml @@ -10,39 +10,20 @@ android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginBottom="25dp" - android:layout_marginEnd="25dp" + android:layout_marginBottom="40dp" android:text="Log in" - app:layout_constraintBottom_toTopOf="@+id/button2" - app:layout_constraintEnd_toEndOf="@+id/button2" /> + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" />