diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-09-01 19:09:04 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-09-02 13:15:27 +0000 |
| commit | 1954b768740bdbf2ffe4cc828761dd9cf83f88a6 (patch) | |
| tree | a53163c68f4bede7c7bfdc4822c17142a4759ecd /android | |
| parent | d5efe264ccbd198fa8c9a0cecf97510f07a51517 (diff) | |
| download | mullvadvpn-1954b768740bdbf2ffe4cc828761dd9cf83f88a6.tar.xz mullvadvpn-1954b768740bdbf2ffe4cc828761dd9cf83f88a6.zip | |
Emit focus change events from the account input
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt index 72bfd39d6c..f3e2d3493c 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountInput.kt @@ -7,12 +7,14 @@ import android.text.style.MetricAffectingSpan import android.util.AttributeSet import android.view.LayoutInflater import android.view.View +import android.view.View.OnFocusChangeListener import android.widget.ImageButton import android.widget.LinearLayout import android.widget.TextView import kotlin.properties.Delegates.observable import net.mullvad.mullvadvpn.R import net.mullvad.mullvadvpn.ui.LoginState +import net.mullvad.talpid.util.EventNotifier const val MIN_ACCOUNT_TOKEN_LENGTH = 10 @@ -41,6 +43,10 @@ class AccountInput : LinearLayout { private val input = container.findViewById<TextView>(R.id.login_input).apply { addTextChangedListener(inputWatcher) + + onFocusChangeListener = OnFocusChangeListener { view, inputHasFocus -> + hasFocus = inputHasFocus && view.isEnabled + } } private val button = container.findViewById<ImageButton>(R.id.login_button).apply { @@ -49,6 +55,9 @@ class AccountInput : LinearLayout { } } + val onFocusChanged = EventNotifier(false) + private var hasFocus by onFocusChanged.notifiable() + var loginState by observable(LoginState.Initial) { _, _, state -> when (state) { LoginState.Initial -> initialState() @@ -90,6 +99,7 @@ class AccountInput : LinearLayout { input.apply { setTextColor(enabledTextColor) setEnabled(true) + setFocusableInTouchMode(true) visibility = View.VISIBLE } @@ -101,8 +111,8 @@ class AccountInput : LinearLayout { input.apply { setTextColor(disabledTextColor) setEnabled(false) + setFocusable(false) visibility = View.VISIBLE - clearFocus() } button.visibility = View.GONE @@ -121,10 +131,11 @@ class AccountInput : LinearLayout { setButtonEnabled(false) input.apply { - findFocus() setTextColor(errorTextColor) setEnabled(true) + setFocusableInTouchMode(true) visibility = View.VISIBLE + requestFocus() } } |
