diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-01 17:38:04 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-04-27 16:21:51 +0000 |
| commit | 58d0a30dd4928fc6f2d58ba796b3938dc15f8759 (patch) | |
| tree | 0e6313eee7787503508690f9a805cfca865d0731 | |
| parent | a1417ded2c92e3c3e73456c7832ff4f57dd7973a (diff) | |
| download | mullvadvpn-58d0a30dd4928fc6f2d58ba796b3938dc15f8759.tar.xz mullvadvpn-58d0a30dd4928fc6f2d58ba796b3938dc15f8759.zip | |
Refactor to move pause and resume methods
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt | 72 |
1 files changed, 36 insertions, 36 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 19358ab990..b5dbb60f17 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt @@ -131,6 +131,42 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre return view } + override fun onSafelyResume() { + tunnelStateListener = connectionProxy.onUiStateChange.subscribe { uiState -> + synchronized(this@WireguardKeyFragment) { + tunnelState = uiState + + if (generatingKey) { + reconnectionExpected = !(tunnelState is TunnelState.Disconnected) + } else if (tunnelState is TunnelState.Connected) { + reconnectionExpected = false + } + } + + updateViewsJob?.cancel() + updateViewsJob = updateViewJob() + } + + keyStatusListener.onKeyStatusChange = { newKeyStatus -> + updateViewsJob?.cancel() + updateViewsJob = updateViewJob() + } + } + + override fun onSafelyPause() { + tunnelStateListener?.let { listener -> + connectionProxy.onUiStateChange.unsubscribe(listener) + } + + keyStatusListener.onKeyStatusChange = null + currentJob?.cancel() + updateViewsJob?.cancel() + resetReconnectionExpectedJob?.cancel() + validatingKey = false + generatingKey = false + urlController.onPause() + } + private fun updateViewJob() = GlobalScope.launch(Dispatchers.Main) { updateViews() } @@ -277,40 +313,4 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre updateViews() } } - - override fun onSafelyPause() { - tunnelStateListener?.let { listener -> - connectionProxy.onUiStateChange.unsubscribe(listener) - } - - keyStatusListener.onKeyStatusChange = null - currentJob?.cancel() - updateViewsJob?.cancel() - resetReconnectionExpectedJob?.cancel() - validatingKey = false - generatingKey = false - urlController.onPause() - } - - override fun onSafelyResume() { - tunnelStateListener = connectionProxy.onUiStateChange.subscribe { uiState -> - synchronized(this@WireguardKeyFragment) { - tunnelState = uiState - - if (generatingKey) { - reconnectionExpected = !(tunnelState is TunnelState.Disconnected) - } else if (tunnelState is TunnelState.Connected) { - reconnectionExpected = false - } - } - - updateViewsJob?.cancel() - updateViewsJob = updateViewJob() - } - - keyStatusListener.onKeyStatusChange = { _ -> - updateViewsJob?.cancel() - updateViewsJob = updateViewJob() - } - } } |
