mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Connected auth API to UI
This commit is contained in:
parent
fb7fb9b98f
commit
a013a75924
@ -70,6 +70,7 @@ public class AuthManager {
|
|||||||
|
|
||||||
public void setAuthSignUpResult(AuthSignUpResult toSet) {
|
public void setAuthSignUpResult(AuthSignUpResult toSet) {
|
||||||
authSignUpResult = toSet;
|
authSignUpResult = toSet;
|
||||||
|
waiting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthSignInResult(AuthSignInResult toSet) {
|
public void setAuthSignInResult(AuthSignInResult toSet) {
|
||||||
|
|||||||
@ -1,39 +1,70 @@
|
|||||||
package com.example.listify.ui;
|
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.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import com.example.listify.AuthManager;
|
||||||
import com.example.listify.R;
|
import com.example.listify.R;
|
||||||
|
import com.example.listify.MainActivity;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.app.AppCompatDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatDialogFragment;
|
||||||
|
|
||||||
public class CodePage extends AppCompatActivity {
|
public class CodePage extends AppCompatDialogFragment {
|
||||||
private Button button1; //Reset password page button
|
private EditText ediTextCode;
|
||||||
private Button button2; //Cancel button
|
|
||||||
|
private CodeDialogListener listener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
setContentView(R.layout.activity_code);
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
|
View view = inflater.inflate(R.layout.activity_code, null);
|
||||||
|
|
||||||
button1 = (Button) findViewById(R.id.button1);
|
builder.setView(view)
|
||||||
button1.setOnClickListener(new View.OnClickListener() {
|
.setTitle("Verification code")
|
||||||
@Override
|
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
|
||||||
public void onClick(View v) {
|
@Override
|
||||||
Intent intent = new Intent(CodePage.this, ResetPasswordPage.class);
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
startActivity(intent);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
button2 = (Button) findViewById(R.id.button2);
|
ediTextCode = view.findViewById(R.id.editTextCode);
|
||||||
button2.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
return builder.create();
|
||||||
public void onClick(View v) {
|
}
|
||||||
Intent intent = new Intent(CodePage.this, LoginPage.class);
|
|
||||||
startActivity(intent);
|
@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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@ package com.example.listify.ui;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
@ -9,7 +10,7 @@ import com.example.listify.R;
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class ForgotPasswordPage extends AppCompatActivity {
|
public class ForgotPasswordPage extends AppCompatActivity implements CodePage.CodeDialogListener {
|
||||||
private Button button1; //Code page button
|
private Button button1; //Code page button
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -21,9 +22,27 @@ public class ForgotPasswordPage extends AppCompatActivity {
|
|||||||
button1.setOnClickListener(new View.OnClickListener() {
|
button1.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(ForgotPasswordPage.this, CodePage.class);
|
openDialog();
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openDialog() {
|
||||||
|
CodePage codePage = new CodePage();
|
||||||
|
codePage.show(getSupportFragmentManager(), "Verification code");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendCode(String code, boolean cancel) {
|
||||||
|
Intent intent;
|
||||||
|
|
||||||
|
if(cancel) {
|
||||||
|
intent = new Intent(ForgotPasswordPage.this, LoginPage.class);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
intent = new Intent(ForgotPasswordPage.this, ResetPasswordPage.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -2,10 +2,13 @@ package com.example.listify.ui;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.example.listify.R;
|
import com.example.listify.R;
|
||||||
|
import com.example.listify.AuthManager;
|
||||||
import com.example.listify.MainActivity;
|
import com.example.listify.MainActivity;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@ -42,8 +45,22 @@ public class LoginPage extends AppCompatActivity {
|
|||||||
button3.setOnClickListener(new View.OnClickListener() {
|
button3.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(LoginPage.this, MainActivity.class);
|
EditText emailText = (EditText) findViewById(R.id.editTextTextPersonName);
|
||||||
startActivity(intent);
|
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
|
||||||
|
|
||||||
|
String email = emailText.getText().toString();
|
||||||
|
String password = passwordText.getText().toString();
|
||||||
|
|
||||||
|
AuthManager authManager = new AuthManager();
|
||||||
|
|
||||||
|
try {
|
||||||
|
authManager.signIn(email, password);
|
||||||
|
//Intent intent = new Intent(LoginPage.this, LoginPage.class);
|
||||||
|
//startActivity(intent);
|
||||||
|
}
|
||||||
|
catch(Exception ex) {
|
||||||
|
//Display "Incorrect email or password" message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,18 +2,23 @@ package com.example.listify.ui;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.example.listify.R;
|
import com.example.listify.R;
|
||||||
|
import com.example.listify.AuthManager;
|
||||||
import com.example.listify.MainActivity;
|
import com.example.listify.MainActivity;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class SignupPage extends AppCompatActivity {
|
public class SignupPage extends AppCompatActivity implements CodePage.CodeDialogListener {
|
||||||
private Button button1; //Log in page button
|
private Button button1; //Log in page button
|
||||||
private Button button2; //Sign up button
|
private Button button2; //Sign up button
|
||||||
|
|
||||||
|
AuthManager authManager = new AuthManager();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -32,9 +37,43 @@ public class SignupPage extends AppCompatActivity {
|
|||||||
button2.setOnClickListener(new View.OnClickListener() {
|
button2.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(SignupPage.this, MainActivity.class);
|
EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress);
|
||||||
startActivity(intent);
|
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
|
||||||
|
|
||||||
|
String email = emailText.getText().toString();
|
||||||
|
String password = passwordText.getText().toString();
|
||||||
|
|
||||||
|
try {
|
||||||
|
authManager.startSignUp(email, password);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void openDialog() {
|
||||||
|
CodePage codePage = new CodePage();
|
||||||
|
codePage.show(getSupportFragmentManager(), "Verification code");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendCode(String code, boolean cancel) {
|
||||||
|
if(cancel) {
|
||||||
|
//Remove user from database
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
authManager.confirmSignUp(code);
|
||||||
|
//Intent intent = new Intent(SignupPage.this, MainActivity.class);
|
||||||
|
//startActivity(intent);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
//Remove user from database
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -5,44 +5,16 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button1"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:text="Submit"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/editTextNumber" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/button2"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="22dp"
|
|
||||||
android:text="Cancel"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/button1"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/button1" />
|
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editTextNumber"
|
android:id="@+id/editTextCode"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="17dp"
|
android:layout_marginTop="16dp"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="Code"
|
android:hint="Code"
|
||||||
android:inputType="number"
|
android:inputType="textPersonName"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/textView3" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textView3"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="31dp"
|
|
||||||
android:layout_marginTop="260dp"
|
|
||||||
android:text="Please enter the 6-digit code from the email sent to you."
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
@ -27,15 +27,15 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editTextTextEmailAddress"
|
android:id="@+id/editTextTextPersonName"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="24dp"
|
android:layout_marginTop="24dp"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="Username"
|
android:hint="Username"
|
||||||
android:inputType="textEmailAddress"
|
android:inputType="textPersonName"
|
||||||
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName"
|
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName" />
|
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editTextTextPassword"
|
android:id="@+id/editTextTextPassword"
|
||||||
@ -45,17 +45,17 @@
|
|||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="Password"
|
android:hint="Password"
|
||||||
android:inputType="textPassword"
|
android:inputType="textPassword"
|
||||||
app:layout_constraintStart_toStartOf="@+id/editTextTextEmailAddress"
|
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/editTextTextEmailAddress" />
|
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/editTextTextPersonName"
|
android:id="@+id/editTextTextEmailAddress"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="28dp"
|
android:layout_marginTop="28dp"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
android:hint="Email"
|
android:hint="Email"
|
||||||
android:inputType="textPersonName"
|
android:inputType="textEmailAddress"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/button1" />
|
app:layout_constraintTop_toBottomOf="@+id/button1" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user