diff --git a/app/src/main/java/com/displaynone/acss/ui/auth/AuthFragment.kt b/app/src/main/java/com/displaynone/acss/ui/auth/AuthFragment.kt
index 8c0dbe2..bf2aef0 100644
--- a/app/src/main/java/com/displaynone/acss/ui/auth/AuthFragment.kt
+++ b/app/src/main/java/com/displaynone/acss/ui/auth/AuthFragment.kt
@@ -56,18 +56,17 @@ class AuthFragment: Fragment(R.layout.fragment_auth) {
@SuppressLint("ResourceAsColor")
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
binding.error.visibility = View.GONE
- val username = s.toString()
- val valid = isUsernameValid(username)
-
- if (valid) {
- binding.hint.visibility = View.INVISIBLE
- }else{
- binding.login.error = getString(R.string.login_hint)
- }
+// val username = s.toString()
+// val valid = isUsernameValid(username)
+//
+// if (valid) {
+// binding.hint.visibility = View.INVISIBLE
+// }else{
+// binding.login.error = getString(R.string.login_hint)
+// }
// binding.hint.visibility = if(valid) View.INVISIBLE else View.VISIBLE
- binding.next.isEnabled = valid
- val color = if (valid) R.color.primary else R.color.secondary
- binding.next.backgroundTintList = ContextCompat.getColorStateList(requireContext(), color)
+// binding.next.isEnabled = valid
+
}
override fun afterTextChanged(s: Editable?) {}
@@ -94,37 +93,95 @@ class AuthFragment: Fragment(R.layout.fragment_auth) {
// })
}
private fun getPasswordValidError(password: String): String {
- if (password.length < 8){ return "LenError" }
- val letterRegex = Regex("^(?=.*[A-Z]).+$")
- if(!letterRegex.matches(password)){ return "UpperCaseError"}
- val digitRegex = Regex("^(?=.*\\\\d).+$")
- if(!digitRegex.matches(password)){ return "DigitCaseError"}
-
+ if (password.length < 8) {
+ return "LenError"
+ }
return "NoErrors"
}
- private fun isUsernameValid(username: String): Boolean {
+ private fun validatePasswordAndSetError(password: String) {
+ val errorType = getPasswordValidError(password)
+
+ when (errorType) {
+ "LenError" -> {
+ binding.password.error = getString(R.string.error_password_too_short)
+ }
+
+ "NoErrors" -> {
+ binding.password.error = null
+ }
+ }
+ }
+ private fun getLoginValidError(username: String): String {
val alf = "^[a-zA-Z0-9_]+$".toRegex()
- return username.isNotEmpty() &&
- username.length >= 3 &&
- !username[0].isDigit() &&
- alf.matches(username)
- }
- private fun isPasswordValid(password: String): Boolean {
- return password.isNotEmpty() &&
- password.length >= 8
+ if (username.isEmpty()) {
+ return "EmptyError"
+ }
+ if (username.length < 3) {
+ return "LenError"
+ }
+ if (username[0].isDigit()) {
+ return "StartsWithDigitError"
+ }
+ if (!alf.matches(username)) {
+ return "InvalidCharactersError"
+ }
+ return "NoErrors"
}
+// private fun isPasswordValid(password: String): Boolean {
+// return password.isNotEmpty() &&
+// password.length >= 8
+// }
// private fun subscribe() {
// viewModel.state.collectWhenStarted(this) { state ->
// binding.login.setOnClickListener(this::onLoginButtonClicked)
// }
// }
+private fun validateLoginAndSetError(username: String) {
+ val errorType = getLoginValidError(username)
+ when (errorType) {
+ "EmptyError" -> {
+ binding.login.error = getString(R.string.error_login_empty)
+ }
+ "LenError" -> {
+ binding.login.error = getString(R.string.error_login_too_short)
+ }
+ "StartsWithDigitError" -> {
+ binding.login.error = getString(R.string.error_login_starts_with_digit)
+ }
+ "InvalidCharactersError" -> {
+ binding.login.error = getString(R.string.error_login_invalid_characters)
+ }
+ "NoErrors" -> {
+ binding.login.error = null
+ }
+ }
+}
private fun onLoginButtonClicked(view: View) {
val login = binding.login.text.toString()
val password = binding.password.text.toString()
- if (login.isEmpty()) return
+ if (getPasswordValidError(password) != "NoErrors") {
+
+
+ val color = R.color.secondary
+ binding.next.backgroundTintList = ContextCompat.getColorStateList(requireContext(), color)
+ validatePasswordAndSetError(password)
+ }else{
+ val color = R.color.primary
+ binding.next.backgroundTintList = ContextCompat.getColorStateList(requireContext(), color)
+ }
+// if (login.isEmpty()) return
+ if (getLoginValidError(login) != "NoErrors") {
+ val color = R.color.secondary
+ binding.next.backgroundTintList = ContextCompat.getColorStateList(requireContext(), color)
+ validateLoginAndSetError(login)
+ }else{
+ val color = R.color.primary
+ binding.next.backgroundTintList = ContextCompat.getColorStateList(requireContext(), color)
+
+ }
viewModel.login(login, password)
}
diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml
index 7be0e0a..ab89cea 100644
--- a/app/src/main/res/layout/fragment_profile.xml
+++ b/app/src/main/res/layout/fragment_profile.xml
@@ -36,19 +36,29 @@
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingTop="50dp">
+
+
+
Profile
Server is unavailable
Checking the session employee
+ The password must contain at least 8 characters
+ The password must contain at least one uppercase letter
+ The password must contain at least one digit
+ The username cannot be empty
+ Login must contain at least 3 characters
+ Login cannot start with a digit
+ Login can contain only letters, numbers, and underscores
\ No newline at end of file
diff --git a/app/src/main/res/values-ru/strings-ru.xml b/app/src/main/res/values-ru/strings-ru.xml
index a2fcece..60f25fa 100644
--- a/app/src/main/res/values-ru/strings-ru.xml
+++ b/app/src/main/res/values-ru/strings-ru.xml
@@ -1,6 +1,6 @@
- AS
+ AS
Введите логин
Введите пароль
Здравствуйте!
@@ -15,13 +15,19 @@
Логина не существует или неверный
ОК
Ошибка
- Введите логин пользователя
- Поиск
- Профиль
- Изменить права входа с помощью смартфона
- Панель администратора
- Log in to your account
- QR code scanning
- Scan result
- Checking the session employee
+ Введите логин пользователя
+ Поиск
+ Профиль
+ Изменить права входа с помощью смартфона
+ Панель администратора
+ Профиль
+ Войдите в свою учетную запись
+ Сканирование QR-кода
+ Результат проверки
+ Проверка сотрудника
+ Нет связи с интернетом
+ Сервер недоступен
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7e51d96..e7ff264 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -25,7 +25,12 @@
QR code scanning
Scan result
Profile
-
+ The password must contain at least 8 characters
+ The password must contain at least one uppercase letter
+ The password must contain at least one digit
Checking the session employee
-
+ The username cannot be empty
+ Login must contain at least 3 characters
+ Login cannot start with a digit
+ Login can contain only letters, numbers, and underscores
\ No newline at end of file