diff --git a/forage-android/src/main/java/com/joinforage/forage/android/core/ui/textwatcher/PinTextWatcher.kt b/forage-android/src/main/java/com/joinforage/forage/android/core/ui/textwatcher/PinTextWatcher.kt index ab137407..0957cad3 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/core/ui/textwatcher/PinTextWatcher.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/core/ui/textwatcher/PinTextWatcher.kt @@ -2,11 +2,8 @@ package com.joinforage.forage.android.core.ui.textwatcher import android.text.Editable import android.text.TextWatcher -import android.widget.EditText -internal class PinTextWatcher( - private val editText: EditText -) : TextWatcher { +internal class PinTextWatcher : TextWatcher { private var onInputChangeEvent: ((Boolean, Boolean) -> Unit)? = null fun onInputChangeEvent(callback: (Boolean, Boolean) -> Unit) { @@ -22,8 +19,9 @@ internal class PinTextWatcher( } override fun afterTextChanged(editable: Editable) { - val isValidAndComplete = editText.length() == 4 - val isEmpty = editText.length() == 0 + val len = editable.toString().length + val isValidAndComplete = len == 4 + val isEmpty = len == 0 onInputChangeEvent?.invoke(isValidAndComplete, isEmpty) } } diff --git a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/rosetta/RosettaPinElement.kt b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/rosetta/RosettaPinElement.kt index 2f671d20..4d90e0c1 100644 --- a/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/rosetta/RosettaPinElement.kt +++ b/forage-android/src/main/java/com/joinforage/forage/android/ecom/ui/vault/rosetta/RosettaPinElement.kt @@ -200,7 +200,7 @@ internal class RosettaPinElement @JvmOverloads constructor( } private fun registerTextWatcher() { - val pinTextWatcher = PinTextWatcher(_editText) + val pinTextWatcher = PinTextWatcher() pinTextWatcher.onInputChangeEvent { isComplete, isEmpty -> inputState = inputState.handleChangeEvent( isComplete = isComplete, diff --git a/forage-android/src/test/java/com/joinforage/forage/android/ui/PinTextWatcherTest.kt b/forage-android/src/test/java/com/joinforage/forage/android/ui/PinTextWatcherTest.kt index b42be755..9fd4f2f2 100644 --- a/forage-android/src/test/java/com/joinforage/forage/android/ui/PinTextWatcherTest.kt +++ b/forage-android/src/test/java/com/joinforage/forage/android/ui/PinTextWatcherTest.kt @@ -13,7 +13,7 @@ class PinTextWatcherTest { @Test fun `ensure afterTextChanged event is fired correctly`() { val editText = EditText(ApplicationProvider.getApplicationContext()) - val watcher = PinTextWatcher(editText) + val watcher = PinTextWatcher() editText.addTextChangedListener(watcher) // mutable state to help us test the callback