prevent empty hashtag in TabPreferenceActivity (#1160)

This commit is contained in:
Konrad Pozniak 2019-03-28 21:10:53 +01:00 committed by GitHub
parent 51a3e0ea5e
commit 29455d5ccd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -192,14 +192,19 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
.create()
editText.onTextChanged { s, _, _, _ ->
val input = s.trim()
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = input.isNotEmpty() && hashtagRegex.matcher(input).matches()
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = validateHashtag(s)
}
dialog.show()
dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled = validateHashtag(editText.text)
editText.requestFocus()
}
private fun validateHashtag(input: CharSequence?): Boolean {
val trimmedInput = input?.trim() ?: ""
return trimmedInput.isNotEmpty() && hashtagRegex.matcher(trimmedInput).matches()
}
private fun updateAvailableTabs() {
val addableTabs: MutableList<TabData> = mutableListOf()