summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-02 19:40:14 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-04-27 16:21:51 +0000
commit850dc84775e467db366776c6124ab1b71745cd09 (patch)
tree6a973406cd2878b2e7001850c3aa8374cf04b00f /android/src
parent6022071177979e80827803c13d1e513ce6042782 (diff)
downloadmullvadvpn-850dc84775e467db366776c6124ab1b71745cd09.tar.xz
mullvadvpn-850dc84775e467db366776c6124ab1b71745cd09.zip
Refactor how key information is shown
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt67
1 files changed, 25 insertions, 42 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 7ad2a5ef9f..9df06f44b6 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/WireguardKeyFragment.kt
@@ -42,7 +42,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
private lateinit var timeAgoFormatter: TimeAgoFormatter
private var currentJob: Job? = null
- private var updateViewsJob: Job? = null
private var tunnelStateListener: Int? = null
private var tunnelState: TunnelState = TunnelState.Disconnected()
private lateinit var urlController: BlockingController
@@ -51,6 +50,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
set(value) {
if (field != value) {
field = value
+ updateKeyInformation()
updateStatus()
updateButtons()
}
@@ -60,6 +60,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
set(value) {
if (field != value) {
field = value
+ updateKeyInformation()
updateStatus()
}
}
@@ -151,8 +152,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
urlController.action()
}
- updateViews()
-
return view
}
@@ -171,15 +170,10 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
uiState is TunnelState.Disconnected ||
(uiState is TunnelState.Error && !uiState.errorState.isBlocking)
}
-
- updateViewsJob?.cancel()
- updateViewsJob = updateViewJob()
}
keyStatusListener.onKeyStatusChange = { newKeyStatus ->
keyStatus = newKeyStatus
- updateViewsJob?.cancel()
- updateViewsJob = updateViewJob()
}
}
@@ -190,33 +184,30 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
keyStatusListener.onKeyStatusChange = null
currentJob?.cancel()
- updateViewsJob?.cancel()
resetReconnectionExpectedJob?.cancel()
actionState = ActionState.Idle
urlController.onPause()
uiJobTracker.cancelAllJobs()
}
- private fun updateViewJob() = GlobalScope.launch(Dispatchers.Main) {
- updateViews()
- }
-
- private fun updateViews() {
- when (val keyState = keyStatus) {
- null -> {
- publicKey.information = null
- }
-
- 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)
+ private fun updateKeyInformation() {
+ uiJobTracker.newJob("updateKeyInformation", GlobalScope.launch(Dispatchers.Main) {
+ 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)
+ publicKey.information = publicKeyString.substring(0, 20) + "..."
+ keyAge.information = timeAgoFormatter.format(publicKeyAge)
+ }
+ null -> {
+ publicKey.information = null
+ keyAge.information = null
+ }
}
- }
+ })
}
private fun updateStatus() {
@@ -280,7 +271,7 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
generateKeyButton.setEnabled(isIdle && hasConnectivity)
verifyKeyButton.setEnabled(isIdle && hasConnectivity)
- manageKeysButton.setEnabled(hasConnectivity && hasKey)
+ manageKeysButton.setEnabled(hasConnectivity)
})
}
@@ -312,28 +303,22 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
private fun onGenerateKeyPress() {
currentJob?.cancel()
- synchronized(this) {
- actionState = ActionState.Generating
- reconnectionExpected = !(tunnelState is TunnelState.Disconnected)
- }
-
- updateViews()
-
- currentJob = GlobalScope.launch(Dispatchers.Main) {
- publicKey.information = null
- keyAge.information = null
+ currentJob = GlobalScope.launch(Dispatchers.Default) {
+ synchronized(this) {
+ actionState = ActionState.Generating
+ reconnectionExpected = !(tunnelState is TunnelState.Disconnected)
+ }
+ keyStatus = null
keyStatusListener.generateKey().join()
actionState = ActionState.Idle
- updateViews()
}
}
private fun onValidateKeyPress() {
currentJob?.cancel()
actionState = ActionState.Verifying
- updateViews()
currentJob = GlobalScope.launch(Dispatchers.Main) {
statusMessage.visibility = View.GONE
@@ -354,7 +339,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
}
}
}
- updateViews()
}
}
@@ -364,7 +348,6 @@ class WireguardKeyFragment : ServiceDependentFragment(OnNoService.GoToLaunchScre
if (reconnectionExpected) {
reconnectionExpected = false
- updateViews()
}
}
}