Skip to content

Commit 54e0a2d

Browse files
authored
button state fixed while authenticating
button state fixed while authenticating
2 parents 97ae4bf + 128c5c8 commit 54e0a2d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

app/src/main/java/com/github/code/gambit/ui/fragment/auth/AuthFragment.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,20 @@ class AuthFragment : Fragment(R.layout.fragment_auth) {
8484
}.attach()
8585

8686
binding.buttonSubmit.setOnClickListener {
87+
disableInteraction()
8788
val fg = (binding.fragmentContainer.adapter as AuthFragmentAdapter).getFragment(
8889
currentPage
8990
)
9091
if (currentPage == 0) {
9192
val data = (fg as SignUpFragment).validate()
9293
if (data != null) {
9394
signUp(data)
94-
}
95+
} else { enableInteraction() }
9596
} else {
9697
val data = (fg as LoginFragment).validate()
97-
logIn(data)
98+
if (data != null) {
99+
logIn(data)
100+
} else { enableInteraction() }
98101
}
99102
}
100103

@@ -119,6 +122,7 @@ class AuthFragment : Fragment(R.layout.fragment_auth) {
119122
}
120123
}
121124
is AuthState.Error -> {
125+
enableInteraction()
122126
binding.progressBar.hide()
123127
if (this::dialog.isInitialized && dialog.isShowing) {
124128
revealShow(false, exit = true)
@@ -230,4 +234,12 @@ class AuthFragment : Fragment(R.layout.fragment_auth) {
230234

231235
private fun navigateToHome() =
232236
findNavController().navigate(R.id.action_authFragment_to_homeFragment)
237+
238+
private fun disableInteraction() {
239+
binding.buttonSubmit.isEnabled = false
240+
}
241+
242+
private fun enableInteraction() {
243+
binding.buttonSubmit.isEnabled = true
244+
}
233245
}

app/src/main/java/com/github/code/gambit/ui/fragment/auth/LoginFragment.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@ class LoginFragment : Fragment(R.layout.fragment_login) {
2222
}
2323

2424
// validates the input fields
25-
fun validate(): AuthData {
26-
val error = false
25+
fun validate(): AuthData? {
26+
var error = false
2727
if (username == "") {
2828
binding.usernameInput.error = "Username can't be empty"
29+
error = true
2930
} else {
3031
if (binding.usernameInput.isErrorEnabled) {
3132
binding.usernameInput.isErrorEnabled = false
3233
}
3334
}
3435
if (password == "") {
3536
binding.passwordInput.error = "Invalid password"
37+
error = true
3638
} else {
3739
if (binding.passwordInput.isErrorEnabled) {
3840
binding.passwordInput.isErrorEnabled = false
3941
}
4042
}
4143
if (error) {
4244
binding.root.snackbar("Validation error!!")
45+
return null
4346
}
4447
return AuthData("", username, password, null, null)
4548
}

0 commit comments

Comments
 (0)