summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-02 19:18:16 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-27 16:21:51 +0000
commitb5b6962ff9db341320e48fbefe367de9050e7e92 (patch)
treea90fc7cce342805c73dd792f17cb3c0351cbe45d /android/src
parent8465274743fab5a6bbfc001c968d618220c4e9f4 (diff)
downloadmullvadvpn-b5b6962ff9db341320e48fbefe367de9050e7e92.tar.xz
mullvadvpn-b5b6962ff9db341320e48fbefe367de9050e7e92.zip
Change how key status message is shown
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt83
-rw-r--r--android/src/main/res/values/strings.xml4
2 files changed, 55 insertions, 32 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
index 53fadccf63..c571be29dd 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
@@ -51,6 +51,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
set(value) {
if (field != value) {
field = value
+ updateStatus()
updateButtons()
}
}
@@ -59,6 +60,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
set(value) {
if (field != value) {
field = value
+ updateStatus()
}
}
@@ -66,6 +68,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
set(value) {
if (field != value) {
field = value
+ updateStatus()
updateButtons()
}
}
@@ -199,8 +202,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
}
private fun updateViews() {
- clearErrorMessage()
-
when (val keyState = keyStatus) {
null -> {
publicKey.information = null
@@ -214,22 +215,63 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
publicKey.information = publicKeyString.substring(0, 20) + "..."
keyAge.information = timeAgoFormatter.format(publicKeyAge)
+ }
+ }
+ }
- keyState.verified?.let { verified ->
- if (verified) {
- setStatusMessage(R.string.wireguard_key_valid, R.color.green)
+ private fun updateStatus() {
+ uiJobTracker.newJob("updateStatus", GlobalScope.launch(Dispatchers.Main) {
+ verifyingKeySpinner.visibility = when (actionState) {
+ ActionState.Verifying -> View.VISIBLE
+ else -> View.INVISIBLE
+ }
+
+ when (actionState) {
+ ActionState.Idle -> {
+ if (hasConnectivity) {
+ updateKeyStatus(keyStatus)
} else {
- setStatusMessage(R.string.wireguard_key_invalid, R.color.red)
+ updateOfflineStatus()
}
}
-
- keyState.replacementFailure?.let { error -> showKeygenFailure(error) }
+ ActionState.Verifying -> {
+ statusMessage.visibility = View.INVISIBLE
+ verifyingKeySpinner.visibility = View.VISIBLE
+ }
+ ActionState.Generating -> {
+ statusMessage.visibility = View.INVISIBLE
+ verifyingKeySpinner.visibility = View.INVISIBLE
+ }
}
- else -> {
- showKeygenFailure(keyState.failure())
+ })
+ }
+
+ private fun updateOfflineStatus() {
+ if (reconnectionExpected) {
+ setStatusMessage(R.string.wireguard_key_reconnecting, R.color.green)
+ } else {
+ setStatusMessage(R.string.wireguard_key_blocked_state_message, R.color.red)
+ }
+ }
+
+ private fun updateKeyStatus(keyStatus: KeygenEvent?) {
+ if (keyStatus is KeygenEvent.NewKey) {
+ if (keyStatus.replacementFailure != null) {
+ showKeygenFailure(keyStatus.replacementFailure)
+ } else {
+ updateKeyIsValid(keyStatus.verified)
}
+ } else {
+ statusMessage.visibility = View.INVISIBLE
+ }
+ }
+
+ private fun updateKeyIsValid(verified: Boolean?) {
+ when (verified) {
+ true -> setStatusMessage(R.string.wireguard_key_valid, R.color.green)
+ false -> setStatusMessage(R.string.wireguard_key_invalid, R.color.red)
+ null -> statusMessage.visibility = View.INVISIBLE
}
- drawNoConnectionState()
}
private fun updateButtons() {
@@ -249,10 +291,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
statusMessage.visibility = View.VISIBLE
}
- private fun clearErrorMessage() {
- statusMessage.visibility = View.GONE
- }
-
private fun showKeygenFailure(failure: KeygenFailure?) {
when (failure) {
is KeygenFailure.TooManyKeys -> {
@@ -272,21 +310,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
}
}
- private fun drawNoConnectionState() {
- manageKeysButton.setEnabled(true)
-
- when (tunnelState) {
- is TunnelState.Connecting, is TunnelState.Disconnecting -> {
- if (!reconnectionExpected) {
- setStatusMessage(R.string.wireguard_key_connectivity, R.color.red)
- }
- }
- is TunnelState.Error -> {
- setStatusMessage(R.string.wireguard_key_blocked_state_message, R.color.red)
- }
- }
- }
-
private fun onGenerateKeyPress() {
currentJob?.cancel()
diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml
index cc554393f0..ce6c81e8a3 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -159,8 +159,8 @@
<string name="wireguard_replace_key">Regenerate key</string>
<string name="wireguard_manage_keys">Manage keys</string>
<string name="wireguard_key_age">Key generated on</string>
- <string name="wireguard_key_connectivity">Connectivity required
- to manage your key.</string>
+ <string name="wireguard_key_reconnecting">Reconnecting with new
+ WireGuard key...</string>
<string name="wireguard_key_blocked_state_message">Can\'t
manage keys in blocked state</string>
<string name="wireguard_key_valid">Key is valid</string>