summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-10-09 13:56:31 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-10-19 11:51:48 +0000
commitbbcdd4d70bd574644d396fd86b731afe3618d9a6 (patch)
tree6d56ada9f0289987d2d8ffd3c5e589741f14f5bf
parent6c0982ac32b1ef67aa88b9a7ecb36bb8d55af3d4 (diff)
downloadmullvadvpn-bbcdd4d70bd574644d396fd86b731afe3618d9a6.tar.xz
mullvadvpn-bbcdd4d70bd574644d396fd86b731afe3618d9a6.zip
Listen for input and history focus events
This prevents the account history from collapsing when navigating from the input into one of the account history entries.
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt12
1 files changed, 9 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
index 3cc2935c21..9052a2e63e 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/AccountLogin.kt
@@ -17,12 +17,17 @@ import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.ui.ListItemDividerDecoration
import net.mullvad.mullvadvpn.ui.LoginState
import net.mullvad.mullvadvpn.ui.widget.AccountLoginBorder.BorderState
+import net.mullvad.mullvadvpn.util.Debouncer
class AccountLogin : RelativeLayout {
companion object {
private val MAX_ACCOUNT_HISTORY_ENTRIES = 3
}
+ private val focusDebouncer = Debouncer(false).apply {
+ listener = { hasFocus -> focused = hasFocus }
+ }
+
private val container =
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE).let { service ->
val inflater = service as LayoutInflater
@@ -36,6 +41,7 @@ class AccountLogin : RelativeLayout {
private val historyAdapter = AccountHistoryAdapter().apply {
onSelectEntry = { account -> input.loginWith(account) }
+ onChildFocusChanged = { _, hasFocus -> focusDebouncer.rawValue = hasFocus }
}
private val dividerHeight = resources.getDimensionPixelSize(R.dimen.account_history_divider)
@@ -70,7 +76,7 @@ class AccountLogin : RelativeLayout {
}
}
- private var inputHasFocus by observable(false) { _, _, hasFocus ->
+ private var focused by observable(false) { _, _, hasFocus ->
updateBorder()
shouldShowAccountHistory = hasFocus
@@ -137,7 +143,7 @@ class AccountLogin : RelativeLayout {
input.apply {
onFocusChanged.subscribe(this) { hasFocus ->
- inputHasFocus = hasFocus
+ focusDebouncer.rawValue = hasFocus
}
onTextChanged.subscribe(this) { _ ->
@@ -173,7 +179,7 @@ class AccountLogin : RelativeLayout {
private fun updateBorder() {
if (state == LoginState.Failure) {
border.borderState = BorderState.ERROR
- } else if (inputHasFocus) {
+ } else if (focused) {
border.borderState = BorderState.FOCUSED
} else {
border.borderState = BorderState.UNFOCUSED