@@ -5,6 +5,8 @@ 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
9
+ import simform.gitexcercise.android.validation.Validator.ValidCredentials
8
10
9
11
class LoginActivity : AppCompatActivity () {
10
12
@@ -19,15 +21,40 @@ class LoginActivity : AppCompatActivity() {
19
21
20
22
private fun setupOnClicks () = with (binding) {
21
23
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 )
24
+ performLogin()
25
+ }
26
+ tvForgotPassword.setOnClickListener {
27
+ startActivity(Intent (this @LoginActivity, ForgotPasswordActivity ::class .java))
28
+ }
29
+ }
30
+
31
+ private fun performLogin () = with (binding) {
32
+ val txtEmail = etEmail.text.trim().toString()
33
+ val txtPassword = etPassword.text.trim().toString()
34
+ when (Validator .isValidCredentials(email = txtEmail, password = txtPassword)) {
35
+ ValidCredentials .VALID -> {
36
+ Toast .makeText(
37
+ this @LoginActivity,
38
+ getString(R .string.msg_login_successfully),
39
+ Toast .LENGTH_SHORT
40
+ ).show()
41
+ gotoProfile()
42
+ }
43
+
44
+ ValidCredentials .INVALID_EMAIL -> {
45
+ etEmail.error = getString(R .string.errr_valid_email)
29
46
}
30
- startActivity(intent)
47
+
48
+ ValidCredentials .INVALID_PASSWORD -> {
49
+ etPassword.error = getString(R .string.err_password_8_chars)
50
+ }
51
+ }
52
+ }
53
+
54
+ private fun gotoProfile () {
55
+ val intent = Intent (this @LoginActivity, ProfileActivity ::class .java).apply {
56
+ addFlags(Intent .FLAG_ACTIVITY_NEW_TASK or Intent .FLAG_ACTIVITY_CLEAR_TASK )
31
57
}
58
+ startActivity(intent)
32
59
}
33
60
}
0 commit comments