From ffb8b10f666c31906420daf71d751fabdbf55cf4 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 13 Jul 2022 13:58:39 +0100 Subject: [PATCH] adding extension for acting on textinputlayout text changes --- .../im/vector/app/core/extensions/TextInputLayout.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt index d3ee765780..e555f97ebb 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/TextInputLayout.kt @@ -44,11 +44,18 @@ fun TextInputLayout.content() = editText().text.toString() fun TextInputLayout.hasContent() = !editText().text.isNullOrEmpty() fun TextInputLayout.clearErrorOnChange(lifecycleOwner: LifecycleOwner) { - editText().textChanges() + editText() + .textChanges() .onEach { error = null } .launchIn(lifecycleOwner.lifecycleScope) } +fun TextInputLayout.onTextChange(lifecycleOwner: LifecycleOwner, action: (CharSequence) -> Unit) { + editText().textChanges() + .onEach(action) + .launchIn(lifecycleOwner.lifecycleScope) +} + fun TextInputLayout.associateContentStateWith(button: View, enabledPredicate: (String) -> Boolean = { it.isNotEmpty() }) { button.isEnabled = enabledPredicate(content()) editText().addTextChangedListener(object : SimpleTextWatcher() {