Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2022-1321 Register screen functionality (validation) #27

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
P2022-1426 Login screen / Fix bug / Amendments
  • Loading branch information
AdrianPat committed Mar 7, 2022
commit 1ad6543d4eef04ffc78508f06fb2e02110fd9cae
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SignUpFragment : Fragment() {
val bind = FragmentSignUpBinding.inflate(layoutInflater)

bind.SignUpButton.setOnClickListener {
if (isEmailOK() and isPasswordOK() and isRepeatPasswordOK()) {
if (isValid()) {
val intent = Intent(this.requireContext(), MainActivity::class.java)
startActivity(intent)
}
Expand All @@ -32,7 +32,7 @@ class SignUpFragment : Fragment() {
private fun isEmailOK(): Boolean {
val editText = requireView().findViewById<EditText>(R.id.loginEditText)
if (!isEmailValid(editText.text.toString())) {
editText.error = "This is not an e-mail address"
editText.error = getString(R.string.emailValidMessage)
return false
} else {
return true
Expand All @@ -54,7 +54,7 @@ class SignUpFragment : Fragment() {
private fun isPasswordOK(): Boolean {
val editText = requireView().findViewById<EditText>(R.id.passwordEditText)
if (editText.text.length < 5) {
editText.error = "Password must be at least 5 characters long"
editText.error = getString(R.string.passwordValidMessage)
return false
} else {
return true
Expand All @@ -65,10 +65,12 @@ class SignUpFragment : Fragment() {
val password = requireView().findViewById<EditText>(R.id.passwordEditText)
val repeatPassword = requireView().findViewById<EditText>(R.id.repeatPassword)
if (password.text.toString() != repeatPassword.text.toString()) {
repeatPassword.error = "Passwords do not match"
repeatPassword.error = getString(R.string.repeatPassValidMessage)
return false
} else {
return true
}
}

private fun isValid() = isEmailOK() and isPasswordOK() and isRepeatPasswordOK()
}
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<string name="series">Series</string>
<string name="kids">Kids</string>
<string name="forgotPasswordText">Forgot password</string>

<string name="emailValidMessage">This is not an e-mail address</string>
<string name="passwordValidMessage">Password must be at least 5 characters long</string>
<string name="repeatPassValidMessage">Passwords do not match</string>
</resources>