mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-13 09:48:47 +00:00
Changed log in code to Kotlin
This commit is contained in:
parent
a9bfd86ed5
commit
1a58b9213d
@ -1,82 +0,0 @@
|
||||
package com.example.listify.ui;
|
||||
|
||||
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 static com.example.listify.MainActivity.am;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class LoginPage extends AppCompatActivity {
|
||||
private Button button1; //Sign up page button
|
||||
private Button button2; //Forgot password button
|
||||
private Button button3; //Log in button
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
String prev = getIntent().getStringExtra("prev");
|
||||
|
||||
if (prev != null && (prev.equals("Sign up") || prev.equals("Forgot password"))) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
|
||||
button1 = (Button) findViewById(R.id.button1);
|
||||
button1.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(LoginPage.this, SignupPage.class);
|
||||
intent.putExtra("prev", "Log in");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
button2 = (Button) findViewById(R.id.button2);
|
||||
button2.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(LoginPage.this, ForgotPasswordPage.class);
|
||||
intent.putExtra("prev", "Log in");
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
button3 = (Button) findViewById(R.id.button3);
|
||||
button3.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditText emailText = (EditText) findViewById(R.id.editTextTextPersonName);
|
||||
EditText passwordText = (EditText) findViewById(R.id.editTextTextPassword);
|
||||
|
||||
String email = emailText.getText().toString();
|
||||
String password = passwordText.getText().toString();
|
||||
|
||||
try {
|
||||
am.signIn(email, password);
|
||||
Intent intent = new Intent(LoginPage.this, MainActivity.class);
|
||||
intent.putExtra("prev", "Login");
|
||||
startActivity(intent);
|
||||
}
|
||||
catch(Exception e) {
|
||||
am.nullify();
|
||||
Log.i("Authentication", e.toString());
|
||||
TextView invalidCred = findViewById(R.id.textView5);
|
||||
invalidCred.setText("Incorrect email or password. Please try again.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
package com.example.listify.ui
|
||||
|
||||
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 LoginPage : AppCompatActivity() {
|
||||
private var button1 //Sign up page button
|
||||
: Button? = null
|
||||
private var button2 //Forgot password button
|
||||
: Button? = null
|
||||
private var button3 //Log in button
|
||||
: Button? = null
|
||||
|
||||
override fun onBackPressed() {
|
||||
val prev = intent.getStringExtra("prev")
|
||||
if (prev != null && (prev == "Sign up" || prev == "Forgot password")) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_login)
|
||||
button1 = findViewById<View>(R.id.button1) as Button
|
||||
button1!!.setOnClickListener {
|
||||
val intent = Intent(this@LoginPage, SignupPage::class.java)
|
||||
intent.putExtra("prev", "Log in")
|
||||
startActivity(intent)
|
||||
}
|
||||
button2 = findViewById<View>(R.id.button2) as Button
|
||||
button2!!.setOnClickListener {
|
||||
val intent = Intent(this@LoginPage, ForgotPasswordPage::class.java)
|
||||
intent.putExtra("prev", "Log in")
|
||||
startActivity(intent)
|
||||
}
|
||||
button3 = findViewById<View>(R.id.button3) as Button
|
||||
button3!!.setOnClickListener {
|
||||
val emailText = findViewById<View>(R.id.editTextTextPersonName) as EditText
|
||||
val passwordText = findViewById<View>(R.id.editTextTextPassword) as EditText
|
||||
val email = emailText.text.toString()
|
||||
val password = passwordText.text.toString()
|
||||
try {
|
||||
MainActivity.am.signIn(email, password)
|
||||
val intent = Intent(this@LoginPage, MainActivity::class.java)
|
||||
intent.putExtra("prev", "Login")
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
MainActivity.am.nullify()
|
||||
Log.i("Authentication", e.toString())
|
||||
val invalidCred = findViewById<TextView>(R.id.textView5)
|
||||
invalidCred.text = "Incorrect email or password. Please try again."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user