diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-04 01:34:10 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-27 16:21:52 +0000 |
| commit | eef498cd099f8c6b16b1143186a1037f7cbcdae1 (patch) | |
| tree | 25259a826e609154fd4ddd3d6499777321a48fa4 /android | |
| parent | 8208fbed62c1f87de476de08961b23b0465a26d0 (diff) | |
| download | mullvadvpn-eef498cd099f8c6b16b1143186a1037f7cbcdae1.tar.xz mullvadvpn-eef498cd099f8c6b16b1143186a1037f7cbcdae1.zip | |
Spawn UI tasks when events are received
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt | 88 |
1 files changed, 43 insertions, 45 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 c9621ee4fb..e011a53d99 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt @@ -129,23 +129,27 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre override fun onSafelyResume() { tunnelStateListener = connectionProxy.onUiStateChange.subscribe { uiState -> - synchronized(this@WireguardKeyFragment) { - tunnelState = uiState + jobTracker.newUiJob("tunnelStateUpdate") { + synchronized(this@WireguardKeyFragment) { + tunnelState = uiState - if (actionState is ActionState.Generating) { - reconnectionExpected = !(tunnelState is TunnelState.Disconnected) - } else if (tunnelState is TunnelState.Connected) { - reconnectionExpected = false - } + if (actionState is ActionState.Generating) { + reconnectionExpected = !(tunnelState is TunnelState.Disconnected) + } else if (tunnelState is TunnelState.Connected) { + reconnectionExpected = false + } - hasConnectivity = uiState is TunnelState.Connected || - uiState is TunnelState.Disconnected || - (uiState is TunnelState.Error && !uiState.errorState.isBlocking) + hasConnectivity = uiState is TunnelState.Connected || + uiState is TunnelState.Disconnected || + (uiState is TunnelState.Error && !uiState.errorState.isBlocking) + } } } keyStatusListener.onKeyStatusChange = { newKeyStatus -> - keyStatus = newKeyStatus + jobTracker.newUiJob("keyStatusUpdate") { + keyStatus = newKeyStatus + } } } @@ -163,41 +167,37 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre } private fun updateKeyInformation() { - jobTracker.newUiJob("updateKeyInformation") { - when (val keyState = keyStatus) { - is KeygenEvent.NewKey -> { - val key = keyState.publicKey - val publicKeyString = Base64.encodeToString(key.key, Base64.NO_WRAP) - val publicKeyAge = - DateTime.parse(key.dateCreated, RFC3339_FORMAT).withZone(DateTimeZone.UTC) + when (val keyState = keyStatus) { + is KeygenEvent.NewKey -> { + val key = keyState.publicKey + val publicKeyString = Base64.encodeToString(key.key, Base64.NO_WRAP) + val publicKeyAge = + DateTime.parse(key.dateCreated, RFC3339_FORMAT).withZone(DateTimeZone.UTC) - publicKey.information = publicKeyString.substring(0, 20) + "..." - keyAge.information = timeAgoFormatter.format(publicKeyAge) - } - null -> { - publicKey.information = null - keyAge.information = null - } + publicKey.information = publicKeyString.substring(0, 20) + "..." + keyAge.information = timeAgoFormatter.format(publicKeyAge) + } + null -> { + publicKey.information = null + keyAge.information = null } } } private fun updateStatus() { - jobTracker.newUiJob("updateStatus") { - verifyingKeySpinner.visibility = when (actionState) { - is ActionState.Verifying -> View.VISIBLE - else -> View.GONE - } + verifyingKeySpinner.visibility = when (actionState) { + is ActionState.Verifying -> View.VISIBLE + else -> View.GONE + } - when (val state = actionState) { - is ActionState.Generating -> statusMessage.visibility = View.GONE - is ActionState.Verifying -> statusMessage.visibility = View.GONE - is ActionState.Idle -> { - if (hasConnectivity) { - updateKeyStatus(state.verified, keyStatus) - } else { - updateOfflineStatus() - } + when (val state = actionState) { + is ActionState.Generating -> statusMessage.visibility = View.GONE + is ActionState.Verifying -> statusMessage.visibility = View.GONE + is ActionState.Idle -> { + if (hasConnectivity) { + updateKeyStatus(state.verified, keyStatus) + } else { + updateOfflineStatus() } } } @@ -238,13 +238,11 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre } private fun updateButtons() { - jobTracker.newUiJob("updateButtons") { - val isIdle = actionState is ActionState.Idle + val isIdle = actionState is ActionState.Idle - generateKeyButton.setEnabled(isIdle && hasConnectivity) - verifyKeyButton.setEnabled(isIdle && hasConnectivity) - manageKeysButton.setEnabled(hasConnectivity) - } + generateKeyButton.setEnabled(isIdle && hasConnectivity) + verifyKeyButton.setEnabled(isIdle && hasConnectivity) + manageKeysButton.setEnabled(hasConnectivity) } private fun setStatusMessage(message: Int, color: Int) { |
