Skip to content
Snippets Groups Projects
Commit 01258bba authored by Kamal Bramwell's avatar Kamal Bramwell
Browse files

FE-954: Username input field repeats

parent 4ce8269f
No related branches found
No related tags found
2 merge requests!84Version 2.92 build 629,!83FE-954: Username input field repeats
......@@ -113,12 +113,12 @@ class UsernameRegistration @AssistedInject constructor(
override val usernameFilters: Array<InputFilter> =
arrayOf(
InputFilter { source, start, end, _, _, _ ->
val input = source?.subSequence(start, end)
val filtered = source?.subSequence(start, end)
?.replace(Regex(USERNAME_FILTER_REGEX), "")
if (filtered == input) null else filtered
},
// InputFilter { source, start, end, _, _, _ ->
// val input = source?.subSequence(start, end)
// val filtered = source?.subSequence(start, end)
// ?.replace(Regex(USERNAME_FILTER_REGEX), "")
// if (filtered == input) null else filtered
// },
InputFilter.LengthFilter(MAX_USERNAME_LENGTH)
)
......@@ -179,19 +179,25 @@ class UsernameRegistration @AssistedInject constructor(
this.equals(PLAY_STORE_DEMO_USERNAME, true)
private fun String?.isValidUsername(): Boolean {
if (isNullOrEmpty() || !isMinimumLength()) {
return when {
isNullOrEmpty() || !isMinimumLength() -> {
minimumLengthError()
return false
false
}
return if (this.matches(USERNAME_VALIDATION_REGEX.toRegex())) {
matches(USERNAME_VALIDATION_REGEX.toRegex()) -> {
error.value = null
true
} else {
}
contains(Regex(USERNAME_FILTER_REGEX)) -> {
invalidCharsInUsernameError()
false
}
else -> {
invalidUsernameError()
false
}
}
}
private fun String.isMinimumLength() = length > MIN_USERNAME_LENGTH
......@@ -203,6 +209,12 @@ class UsernameRegistration @AssistedInject constructor(
error.value = application.getString(R.string.registration_error_username_invalid)
}
private fun invalidCharsInUsernameError() {
error.postValue(
application.getString(R.string.registration_error_username_invalid_chars)
)
}
private fun registerUsername(username: String, isDemoAcct: Boolean = false) {
if (!loggedIn) {
getOrCreateSession()
......
......@@ -519,6 +519,7 @@
<string name="label_edit">Edit</string>
<string name="notification_group_request_text">Group request received</string>
<string name="registration_error_username_invalid">Username must start and end with an alphanumeric character.</string>
<string name="registration_error_username_invalid_chars">Username contains invalid characters.</string>
<string name="settings_confirm_delete_button">Confirm Delete</string>
<string name="settings_delete_account_confirm_username_hint">Username</string>
<string name="settings_account_recovery_dialog_title">Please note</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment