Changed sign up code to Kotlin

This commit is contained in:
Aaron Sun 2021-02-16 19:39:24 -08:00
parent 1a58b9213d
commit 9801420be8
3 changed files with 86 additions and 153 deletions

View File

@ -22,36 +22,4 @@ class SplashActivity : AppCompatActivity() {
@JvmField
var showSplash = true
}
}
/*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
public void onBackPressed() {}
@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);
intent.putExtra("prev", "Splash");
startActivity(intent);
}
}, 3000);
}
}*/
}

View File

@ -1,120 +0,0 @@
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;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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 {
private Button button1; //Log in page button
private Button button2; //Sign up button
String email;
String password;
String confirmPassword;
@Override
public void onBackPressed() {
String prev = getIntent().getStringExtra("prev");
if (prev != null && (prev.equals("Log in") || prev.equals("Forgot password"))) {
super.onBackPressed();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signup);
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(SignupPage.this, LoginPage.class);
intent.putExtra("prev", "Sign up");
startActivity(intent);
}
});
button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText emailText = (EditText) findViewById(R.id.editTextTextEmailAddress);
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
EditText confirmPasswordText = (EditText) findViewById(R.id.editTextTextPassword2);
email = emailText.getText().toString();
password = passwordText.getText().toString();
confirmPassword = confirmPasswordText.getText().toString();
if(!password.equals(confirmPassword)) {
TextView invalidCred = findViewById(R.id.textView3);
invalidCred.setText("\"Confirm Password\" does not match \"Password\".");
return;
}
try {
am.startSignUp(email, password);
}
catch (Exception e) {
am.nullify();
Log.i("Authentication", e.toString());
TextView invalidCred = findViewById(R.id.textView3);
invalidCred.setText("Invalid credentials. Please try again.");
return;
}
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 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);
intent.putExtra("prev", "Sign up");
startActivity(intent);
}
catch (Exception e) {
am.nullify();
Log.i("Authentication", e.toString());
}
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
}
}

View File

@ -0,0 +1,85 @@
package com.example.listify.ui
import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.listify.MainActivity
import com.example.listify.R
class SignupPage : AppCompatActivity() {
private var button1 //Log in page button
: Button? = null
private var button2 //Sign up button
: Button? = null
var email: String? = null
var password: String? = null
var confirmPassword: String? = null
override fun onBackPressed() {
val prev = intent.getStringExtra("prev")
if (prev != null && (prev == "Log in" || prev == "Forgot password")) {
super.onBackPressed()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_signup)
button1 = findViewById<View>(R.id.button1) as Button
button1!!.setOnClickListener {
val intent = Intent(this@SignupPage, LoginPage::class.java)
intent.putExtra("prev", "Sign up")
startActivity(intent)
}
button2 = findViewById<View>(R.id.button2) as Button
button2!!.setOnClickListener(View.OnClickListener {
val emailText = findViewById<View>(R.id.editTextTextEmailAddress) as EditText
val passwordText = findViewById<View>(R.id.editTextTextPassword) as EditText
val confirmPasswordText = findViewById<View>(R.id.editTextTextPassword2) as EditText
email = emailText.text.toString()
password = passwordText.text.toString()
confirmPassword = confirmPasswordText.text.toString()
if (password != confirmPassword) {
val invalidCred = findViewById<TextView>(R.id.textView3)
invalidCred.text = "\"Confirm Password\" does not match \"Password\"."
return@OnClickListener
}
try {
MainActivity.am.startSignUp(email, password)
} catch (e: Exception) {
MainActivity.am.nullify()
Log.i("Authentication", e.toString())
val invalidCred = findViewById<TextView>(R.id.textView3)
invalidCred.text = "Invalid credentials. Please try again."
return@OnClickListener
}
val codeView = layoutInflater.inflate(R.layout.activity_code, null)
val builder = AlertDialog.Builder(this@SignupPage)
builder.setView(codeView)
builder.setTitle("Verification code")
builder.setMessage("Please enter the 6-digit verification code sent to your email.")
builder.setPositiveButton("Submit") { dialog, which ->
val codeText = codeView.findViewById<View>(R.id.editTextCode) as EditText
val code = codeText.text.toString()
try {
MainActivity.am.confirmSignUp(code)
MainActivity.am.signIn(email, password)
val intent = Intent(this@SignupPage, MainActivity::class.java)
intent.putExtra("prev", "Sign up")
startActivity(intent)
} catch (e: Exception) {
MainActivity.am.nullify()
Log.i("Authentication", e.toString())
}
}
builder.setNegativeButton("Cancel") { dialog, which -> }
val dialog = builder.create()
dialog.show()
})
}
}