summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-22 21:16:40 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-23 18:02:34 +0000
commit88fe74eca7a3bab33c092b2007b2dc896b88ce92 (patch)
tree31fd1a41b929b4ee326d37ddcb54eaeef8b95230 /android/src/main
parent878240b7fd8690e2178d56f5f59449d91d30799a (diff)
downloadmullvadvpn-88fe74eca7a3bab33c092b2007b2dc896b88ce92.tar.xz
mullvadvpn-88fe74eca7a3bab33c092b2007b2dc896b88ce92.zip
Disable connect button on key generation issues
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectActionButton.kt27
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt3
2 files changed, 27 insertions, 3 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectActionButton.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectActionButton.kt
index a430ab84c7..b66a170c32 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectActionButton.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectActionButton.kt
@@ -3,12 +3,35 @@ package net.mullvad.mullvadvpn
import android.view.View
import android.widget.Button
+import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.model.TunnelState
class ConnectActionButton(val parentView: View) {
private val button: Button = parentView.findViewById(R.id.action_button)
- var state: TunnelState = TunnelState.Disconnected()
+ private var enabled = true
+ set(value) {
+ if (field != value) {
+ field = value
+
+ button.setEnabled(value)
+ button.setAlpha(if (value) 1.0F else 0.5F)
+ }
+ }
+
+ var keyState: KeygenEvent? = null
+ set(value) {
+ when (value) {
+ null -> enabled = true
+ is KeygenEvent.NewKey -> enabled = true
+ is KeygenEvent.TooManyKeys -> enabled = false
+ is KeygenEvent.GenerationFailure -> enabled = false
+ }
+
+ field = value
+ }
+
+ var tunnelState: TunnelState = TunnelState.Disconnected()
set(value) {
when (value) {
is TunnelState.Disconnected -> disconnected()
@@ -30,7 +53,7 @@ class ConnectActionButton(val parentView: View) {
}
private fun action() {
- when (state) {
+ when (tunnelState) {
is TunnelState.Disconnected -> onConnect?.invoke()
is TunnelState.Disconnecting -> onConnect?.invoke()
is TunnelState.Connecting -> onCancel?.invoke()
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
index 1a3d2bbeae..a5f14cfa92 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
@@ -120,7 +120,7 @@ class ConnectFragment : Fragment() {
locationInfoCache.state = realState
headerBar.setState(realState)
- actionButton.state = uiState
+ actionButton.tunnelState = uiState
switchLocationButton.state = uiState
notificationBanner.tunnelState = uiState
status.setState(uiState)
@@ -128,6 +128,7 @@ class ConnectFragment : Fragment() {
private fun updateKeyStatus(keyStatus: KeygenEvent?) = GlobalScope.launch(Dispatchers.Main) {
notificationBanner.keyState = keyStatus
+ actionButton.keyState = keyStatus
}
private fun openSwitchLocationScreen() {