From 29455d5ccdb01f5b243415cf987951fb006b1bd0 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Thu, 28 Mar 2019 21:10:53 +0100 Subject: [PATCH] prevent empty hashtag in TabPreferenceActivity (#1160) --- .../com/keylesspalace/tusky/TabPreferenceActivity.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt index 918d361da..d341ee1c8 100644 --- a/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/TabPreferenceActivity.kt @@ -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 = mutableListOf()