diff --git a/Listify/app/src/main/java/com/example/listify/ui/LoginPage.java b/Listify/app/src/main/java/com/example/listify/ui/LoginPage.java deleted file mode 100644 index c1d18a7..0000000 --- a/Listify/app/src/main/java/com/example/listify/ui/LoginPage.java +++ /dev/null @@ -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."); - } - } - }); - } -} \ No newline at end of file diff --git a/Listify/app/src/main/java/com/example/listify/ui/LoginPage.kt b/Listify/app/src/main/java/com/example/listify/ui/LoginPage.kt new file mode 100644 index 0000000..5297abd --- /dev/null +++ b/Listify/app/src/main/java/com/example/listify/ui/LoginPage.kt @@ -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(R.id.button1) as Button + button1!!.setOnClickListener { + val intent = Intent(this@LoginPage, SignupPage::class.java) + intent.putExtra("prev", "Log in") + startActivity(intent) + } + button2 = findViewById(R.id.button2) as Button + button2!!.setOnClickListener { + val intent = Intent(this@LoginPage, ForgotPasswordPage::class.java) + intent.putExtra("prev", "Log in") + startActivity(intent) + } + button3 = findViewById(R.id.button3) as Button + button3!!.setOnClickListener { + val emailText = findViewById(R.id.editTextTextPersonName) as EditText + val passwordText = findViewById(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(R.id.textView5) + invalidCred.text = "Incorrect email or password. Please try again." + } + } + } +} \ No newline at end of file