@@ -5,6 +5,7 @@ import android.os.Bundle
5
5
import android.widget.Toast
6
6
import androidx.appcompat.app.AppCompatActivity
7
7
import simform.gitexcercise.android.databinding.ActivityLoginBinding
8
+ import simform.gitexcercise.android.validation.Validator
8
9
9
10
class LoginActivity : AppCompatActivity () {
10
11
@@ -19,15 +20,36 @@ class LoginActivity : AppCompatActivity() {
19
20
20
21
private fun setupOnClicks () = with (binding) {
21
22
btnLogin.setOnClickListener {
22
- Toast .makeText(
23
- this @LoginActivity,
24
- getString(R .string.msg_login_successfully),
25
- Toast .LENGTH_SHORT
26
- ).show()
27
- val intent = Intent (this @LoginActivity, ProfileActivity ::class .java).apply {
28
- addFlags(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TASK )
23
+ performLogin()
24
+ }
25
+ tvForgotPassword.setOnClickListener {
26
+ startActivity(Intent (this @LoginActivity, ForgotPasswordActivity ::class .java))
27
+ }
28
+ }
29
+
30
+ private fun performLogin () = with (binding) {
31
+ val txtEmail = etEmail.text.trim().toString()
32
+ val txtPassword = etPassword.text.trim().toString()
33
+ if (Validator .isValidEmail(txtEmail)) {
34
+ if (Validator .isValidPassword(txtPassword)) {
35
+ Toast .makeText(
36
+ this @LoginActivity,
37
+ getString(R .string.msg_login_successfully),
38
+ Toast .LENGTH_SHORT
39
+ ).show()
40
+ gotoProfile()
41
+ } else {
42
+ etPassword.error = getString(R .string.err_password_8_chars)
29
43
}
30
- startActivity(intent)
44
+ } else {
45
+ etEmail.error = getString(R .string.errr_valid_email)
46
+ }
47
+ }
48
+
49
+ private fun gotoProfile () {
50
+ val intent = Intent (this @LoginActivity, ProfileActivity ::class .java).apply {
51
+ addFlags(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TASK )
31
52
}
53
+ startActivity(intent)
32
54
}
33
55
}
0 commit comments