mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-22 23:58:47 +01:00
Client side validation of alias max length
This commit is contained in:
parent
e0a6e82661
commit
3da5641e2b
1
changelog.d/3934.bugfix
Normal file
1
changelog.d/3934.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Validate public space address length when user clicks away from
|
@ -165,6 +165,8 @@ object MatrixPatterns {
|
||||
fun candidateAliasFromRoomName(name: String): String {
|
||||
return Regex("\\s").replace(name.lowercase(), "_").let {
|
||||
"[^a-z0-9._%#@=+-]".toRegex().replace(it, "")
|
||||
}.let { alias ->
|
||||
if (alias.length > 255) alias.substring(0, 255) else alias
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
package im.vector.app.features.form
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.InputFilter
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.TextView
|
||||
@ -77,6 +78,9 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||
@EpoxyAttribute
|
||||
var suffixText: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var maxLength: Int? = null
|
||||
|
||||
private val onTextChangeListener = object : SimpleTextWatcher() {
|
||||
override fun afterTextChanged(s: Editable) {
|
||||
onTextChange?.invoke(s.toString())
|
||||
@ -109,6 +113,15 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||
holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener)
|
||||
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
||||
holder.textInputEditText.onFocusChangeListener = onFocusChangedListener
|
||||
|
||||
if (maxLength != null) {
|
||||
holder.textInputEditText.filters = arrayOf(InputFilter.LengthFilter(maxLength!!))
|
||||
holder.textInputLayout.isCounterEnabled = true
|
||||
holder.textInputLayout.counterMaxLength = maxLength!!
|
||||
} else {
|
||||
holder.textInputEditText.filters = arrayOf()
|
||||
holder.textInputLayout.isCounterEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldSaveViewState(): Boolean {
|
||||
|
@ -141,6 +141,7 @@ class CreateRoomController @Inject constructor(
|
||||
value(viewState.aliasLocalPart)
|
||||
suffixText(":" + viewState.homeServerName)
|
||||
prefixText("#")
|
||||
maxLength(255)
|
||||
hint(host.stringProvider.getString(R.string.room_alias_address_hint))
|
||||
errorMessage(
|
||||
host.roomAliasErrorFormatter.format(
|
||||
|
@ -56,7 +56,7 @@ import timber.log.Timber
|
||||
class CreateRoomViewModel @AssistedInject constructor(@Assisted private val initialState: CreateRoomViewState,
|
||||
private val session: Session,
|
||||
private val rawService: RawService,
|
||||
private val vectorPreferences: VectorPreferences
|
||||
vectorPreferences: VectorPreferences
|
||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||
|
||||
@AssistedFactory
|
||||
|
@ -94,6 +94,8 @@ class SpaceDetailEpoxyController @Inject constructor(
|
||||
hint(host.stringProvider.getString(R.string.create_space_alias_hint))
|
||||
suffixText(":" + data.homeServerName)
|
||||
prefixText("#")
|
||||
// spaces alias are limited to 255
|
||||
maxLength(255)
|
||||
onFocusChange { hasFocus ->
|
||||
host.aliasTextIsFocused = hasFocus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user