Merge branch 'master' into async-loading

This commit is contained in:
Clayton Wilson 2020-10-22 23:12:41 -04:00 committed by GitHub
commit e21913882c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 290 additions and 220 deletions

View File

@ -33,9 +33,9 @@
android:name=".SearchResults"
android:label=""
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity android:name="com.example.listify.SplashActivity" />
<activity android:name="com.example.listify.ui.SignupPage" />
<activity android:name="com.example.listify.ui.LoginPage" />
<activity android:name="com.example.listify.ui.ForgotPasswordPage" />

View File

@ -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,13 @@ public class AuthManager {
return authSession.getUserPoolTokens().getValue().getIdToken();
}
public String getEmail() {
return email;
}
public String getPassword() {
return password;
}
public void setAuthSession(AuthSession toSet) {
authSession = (AWSCognitoAuthSession) toSet;
@ -117,7 +123,6 @@ public class AuthManager {
error -> setAuthError(error)
);
throwIfAuthError();
}
public void confirmSignUp(String confirmationCode) throws AuthException {
@ -151,13 +156,15 @@ public class AuthManager {
public void signOutUser() throws AuthException {
authSession = null;
email = null;
password = null;
waiting = true;
Amplify.Auth.signOut(this::signOutSuccess, error -> setAuthError(error));
throwIfAuthError();
}
public void changePassword(String email) throws AuthException {
this.email = email;
//this.email = email;
//waiting = true;
Amplify.Auth.resetPassword(email, result -> setAuthResetPasswordResult(result), error -> setAuthError(error));
throwIfAuthError();

View File

@ -131,7 +131,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
ArrayList<Integer> pImages;
MyAdapter (Context c, ArrayList<String> names, ArrayList<String> stores, ArrayList<String> prices, ArrayList<String> quantity, ArrayList<Integer> 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;
@ -144,7 +144,7 @@ public class ListPage extends AppCompatActivity implements Requestor.Receiver {
@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);

View File

@ -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,16 @@ 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.example.listify.ui.LoginPage;
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 +34,30 @@ 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);
}
if(am.getEmail() == null) {
Intent intent = new Intent(MainActivity.this, LoginPage.class);
startActivity(intent);
}
//------------------------------Auth Testing---------------------------------------------//
@ -180,6 +202,24 @@ public class MainActivity extends AppCompatActivity implements CreateListDialogF
});
}
public void onClickSignout(MenuItem m) {
m.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
try {
am.signOutUser();
Intent intent = new Intent(MainActivity.this, com.example.listify.ui.LoginPage.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
return false;
}
});
}
@Override
public void sendNewListName(String name) {
Properties configs = new Properties();

View File

@ -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);
}
}

View File

@ -1,70 +0,0 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.listify.AuthManager;
import com.example.listify.R;
import com.example.listify.MainActivity;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
public class CodePage extends AppCompatDialogFragment {
private EditText ediTextCode;
private CodeDialogListener listener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.activity_code, null);
builder.setView(view)
.setTitle("Verification code")
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String code = ediTextCode.getText().toString();
listener.sendCode("" + code + "", false);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String code = ediTextCode.getText().toString();
listener.sendCode("" + code + "", true);
}
});
ediTextCode = view.findViewById(R.id.editTextCode);
return builder.create();
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
listener = (CodeDialogListener) context;
} catch (ClassCastException e) {
throw new ClassCastException("CodeDialogListener not implemented.");
}
}
public interface CodeDialogListener {
void sendCode(String code, boolean cancel);
}
}

View File

@ -1,5 +1,7 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -8,31 +10,46 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.example.listify.MainActivity;
import com.example.listify.R;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
public class ForgotPasswordPage extends AppCompatActivity implements CodePage.CodeDialogListener {
public class ForgotPasswordPage extends AppCompatActivity {
private Button button1; //Code page button
String email;
String newPassword;
String confirmNewPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgotpswd);
if(am.getEmail() != null) {
Intent intent = new Intent(ForgotPasswordPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
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,29 +58,39 @@ 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.");
}
openDialog();
}
});
}
public void openDialog() {
CodePage codePage = new CodePage();
codePage.show(getSupportFragmentManager(), "Verification code");
return;
}
View codeView = getLayoutInflater().inflate(R.layout.activity_code, null);
AlertDialog.Builder builder = new AlertDialog.Builder(ForgotPasswordPage.this);
builder.setView(codeView);
builder.setTitle("Verification code");
builder.setMessage("Please enter the 6-digit verification code sent to your email.");
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void sendCode(String code, boolean cancel) {
if(!cancel) {
public void onClick(DialogInterface dialog, int which) {
EditText codeText = (EditText) codeView.findViewById(R.id.editTextCode);
String code = codeText.getText().toString();
try {
am.confirmPasswordReset(newPassword, code);
Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
Intent intent = new Intent(ForgotPasswordPage.this, LoginPage.class);
startActivity(intent);
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}

View File

@ -25,6 +25,11 @@ public class LoginPage extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
if(am.getEmail() != null) {
Intent intent = new Intent(LoginPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
@ -57,6 +62,7 @@ public class LoginPage extends AppCompatActivity {
am.signIn(email, password);
Intent intent = new Intent(LoginPage.this, MainActivity.class);
startActivity(intent);
finish();
}
catch(Exception e) {
Log.i("Authentication", e.toString());

View File

@ -1,5 +1,7 @@
package com.example.listify.ui;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@ -11,19 +13,35 @@ import android.widget.TextView;
import com.example.listify.R;
import com.example.listify.AuthManager;
import com.example.listify.MainActivity;
import com.example.listify.Requestor;
import org.json.JSONException;
import java.io.IOException;
import java.util.Properties;
import static com.example.listify.MainActivity.am;
import androidx.appcompat.app.AppCompatActivity;
public class SignupPage extends AppCompatActivity implements CodePage.CodeDialogListener {
public class SignupPage extends AppCompatActivity {
private Button button1; //Log in page button
private Button button2; //Sign up button
String email;
String password;
String confirmPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
if(am.getEmail() != null) {
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
}
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
@ -41,9 +59,9 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
EditText confirmPasswordText = (EditText) findViewById(R.id.editTextTextPassword2);
String email = emailText.getText().toString();
String password = passwordText.getText().toString();
String confirmPassword = confirmPasswordText.getText().toString();
email = emailText.getText().toString();
password = passwordText.getText().toString();
confirmPassword = confirmPasswordText.getText().toString();
if(!password.equals(confirmPassword)) {
TextView invalidCred = findViewById(R.id.textView3);
@ -61,27 +79,37 @@ public class SignupPage extends AppCompatActivity implements CodePage.CodeDialog
return;
}
openDialog();
}
});
}
public void openDialog() {
CodePage codePage = new CodePage();
codePage.show(getSupportFragmentManager(), "Verification code");
}
View codeView = getLayoutInflater().inflate(R.layout.activity_code, null);
AlertDialog.Builder builder = new AlertDialog.Builder(SignupPage.this);
builder.setView(codeView);
builder.setTitle("Verification code");
builder.setMessage("Please enter the 6-digit verification code sent to your email.");
builder.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void sendCode(String code, boolean cancel) {
if(!cancel) {
public void onClick(DialogInterface dialog, int which) {
EditText codeText = (EditText) codeView.findViewById(R.id.editTextCode);
String code = codeText.getText().toString();
try {
am.confirmSignUp(code);
am.signIn(email, password);
Intent intent = new Intent(SignupPage.this, MainActivity.class);
startActivity(intent);
finish();
}
catch (Exception e) {
Log.i("Authentication", e.toString());
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
return;
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}

View File

@ -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;
@ -25,28 +29,26 @@ import java.io.IOException;
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);
toLoginPage = (Button) root.findViewById(R.id.button1);
toLoginPage.setOnClickListener(new View.OnClickListener() {
toDeleteAccountPage = (Button) root.findViewById(R.id.button);
toDeleteAccountPage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), com.example.listify.ui.LoginPage.class);
startActivity(intent);
}
});
toListPage = (Button) root.findViewById(R.id.button2);
toListPage.setOnClickListener(new View.OnClickListener() {
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(View v) {
//Intent intent = new Intent(HomeFragment.this.getActivity(), com.example.listify.ListPage.class);
//startActivity(intent);
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 {
@ -56,11 +58,25 @@ public class HomeFragment extends Fragment {
}
Requestor requestor = new Requestor(am, configs.getProperty("apiKey"));
am.deleteUser(requestor);
Intent intent = new Intent(getActivity(), com.example.listify.ui.LoginPage.class);
startActivity(intent);
getActivity().finish();
}
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();
}
});
return root;

View File

@ -11,8 +11,8 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="Code"
android:inputType="textPersonName"
android:hint=""
android:inputType="textPassword"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

View File

@ -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" />
<EditText
android:id="@+id/editTextTextEmailAddress2"
android:id="@+id/editTextTextEmailAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="295dp"
android:layout_marginTop="263dp"
android:ems="10"
android:hint="Email"
android:inputType="textEmailAddress"
app:layout_constraintStart_toStartOf="@+id/editTextTextPassword2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editTextTextPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="New Password"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />
<EditText
android:id="@+id/editTextTextPassword2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="31dp"
android:layout_marginTop="35dp"
android:ems="10"
android:hint="New Password"
android:hint="Confirm New Password"
android:inputType="textPassword"
app:layout_constraintEnd_toStartOf="@+id/textView6"
app:layout_constraintStart_toStartOf="@+id/textView6"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress2" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="34dp"
android:layout_marginEnd="2dp"
android:text="Please enter your email address."
app:layout_constraintBottom_toTopOf="@+id/editTextTextEmailAddress2"
app:layout_constraintEnd_toEndOf="@+id/editTextTextEmailAddress2" />
app:layout_constraintTop_toBottomOf="@+id/editTextTextPassword" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="46dp"
android:layout_marginEnd="2dp"
android:text="Please enter your email address."
app:layout_constraintBottom_toTopOf="@+id/editTextTextEmailAddress"
app:layout_constraintEnd_toEndOf="@+id/editTextTextEmailAddress" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -33,7 +33,7 @@
android:layout_marginTop="23dp"
android:ems="10"
android:hint="Password"
android:inputType="textPersonName"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />

View File

@ -7,42 +7,13 @@
tools:context=".ui.home.HomeFragment">
<Button
android:id="@+id/button1"
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:layout_marginEnd="25dp"
android:text="Log in"
app:layout_constraintBottom_toTopOf="@+id/button2"
app:layout_constraintEnd_toEndOf="@+id/button2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="148dp"
android:text="Delete Account"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Switch
android:id="@+id/switch1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="29dp"
android:text="Kroger"
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintStart_toStartOf="@+id/button1" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="31dp"
android:text="Search these stores:"
app:layout_constraintBottom_toTopOf="@+id/switch1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -24,6 +24,10 @@
<!-- android:id="@+id/nav_create_list"-->
<!-- android:icon="@drawable/ic_baseline_add_28"-->
<!-- android:title="Create New List"-->
<!-- android:onClick="onClickCreateList"/>-->
<!-- android:onClick="onClickCreateList" />-->
<item
android:id="@+id/nav_logout"
android:title="Sign out"
android:onClick="onClickSignout" />
</group>
</menu>

View File

@ -7,7 +7,7 @@
<string name="nav_header_desc">Navigation header</string>
<string name="action_settings">Settings</string>
<string name="menu_home">Home</string>
<string name="menu_home">Profile</string>
<string name="menu_gallery">Gallery</string>
<string name="menu_slideshow">Slideshow</string>