mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-03-23 22:39:02 +03:00
Client side validation of alias max length
This commit is contained in:
parent
e0a6e82661
commit
3da5641e2b
6 changed files with 20 additions and 1 deletions
changelog.d
matrix-sdk-android/src/main/java/org/matrix/android/sdk/api
vector/src/main/java/im/vector/app/features
form
roomdirectory/createroom
spaces/create
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 {
|
fun candidateAliasFromRoomName(name: String): String {
|
||||||
return Regex("\\s").replace(name.lowercase(), "_").let {
|
return Regex("\\s").replace(name.lowercase(), "_").let {
|
||||||
"[^a-z0-9._%#@=+-]".toRegex().replace(it, "")
|
"[^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
|
package im.vector.app.features.form
|
||||||
|
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
|
import android.text.InputFilter
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
@ -77,6 +78,9 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var suffixText: String? = null
|
var suffixText: String? = null
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var maxLength: Int? = null
|
||||||
|
|
||||||
private val onTextChangeListener = object : SimpleTextWatcher() {
|
private val onTextChangeListener = object : SimpleTextWatcher() {
|
||||||
override fun afterTextChanged(s: Editable) {
|
override fun afterTextChanged(s: Editable) {
|
||||||
onTextChange?.invoke(s.toString())
|
onTextChange?.invoke(s.toString())
|
||||||
|
@ -109,6 +113,15 @@ abstract class FormEditTextItem : VectorEpoxyModel<FormEditTextItem.Holder>() {
|
||||||
holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener)
|
holder.textInputEditText.addTextChangedListenerOnce(onTextChangeListener)
|
||||||
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
holder.textInputEditText.setOnEditorActionListener(editorActionListener)
|
||||||
holder.textInputEditText.onFocusChangeListener = onFocusChangedListener
|
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 {
|
override fun shouldSaveViewState(): Boolean {
|
||||||
|
|
|
@ -141,6 +141,7 @@ class CreateRoomController @Inject constructor(
|
||||||
value(viewState.aliasLocalPart)
|
value(viewState.aliasLocalPart)
|
||||||
suffixText(":" + viewState.homeServerName)
|
suffixText(":" + viewState.homeServerName)
|
||||||
prefixText("#")
|
prefixText("#")
|
||||||
|
maxLength(255)
|
||||||
hint(host.stringProvider.getString(R.string.room_alias_address_hint))
|
hint(host.stringProvider.getString(R.string.room_alias_address_hint))
|
||||||
errorMessage(
|
errorMessage(
|
||||||
host.roomAliasErrorFormatter.format(
|
host.roomAliasErrorFormatter.format(
|
||||||
|
|
|
@ -56,7 +56,7 @@ import timber.log.Timber
|
||||||
class CreateRoomViewModel @AssistedInject constructor(@Assisted private val initialState: CreateRoomViewState,
|
class CreateRoomViewModel @AssistedInject constructor(@Assisted private val initialState: CreateRoomViewState,
|
||||||
private val session: Session,
|
private val session: Session,
|
||||||
private val rawService: RawService,
|
private val rawService: RawService,
|
||||||
private val vectorPreferences: VectorPreferences
|
vectorPreferences: VectorPreferences
|
||||||
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
) : VectorViewModel<CreateRoomViewState, CreateRoomAction, CreateRoomViewEvents>(initialState) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
|
|
|
@ -94,6 +94,8 @@ class SpaceDetailEpoxyController @Inject constructor(
|
||||||
hint(host.stringProvider.getString(R.string.create_space_alias_hint))
|
hint(host.stringProvider.getString(R.string.create_space_alias_hint))
|
||||||
suffixText(":" + data.homeServerName)
|
suffixText(":" + data.homeServerName)
|
||||||
prefixText("#")
|
prefixText("#")
|
||||||
|
// spaces alias are limited to 255
|
||||||
|
maxLength(255)
|
||||||
onFocusChange { hasFocus ->
|
onFocusChange { hasFocus ->
|
||||||
host.aliasTextIsFocused = hasFocus
|
host.aliasTextIsFocused = hasFocus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue