summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-22 18:21:21 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-05-26 14:14:28 +0000
commitba5fd1dc93e45cb4407dfc0e3be3ce6f1b178c2f (patch)
treeeef931b7875f9bf92b4dd1904bfd44fa72494186 /android/src/main
parent1b7de9d13455ab1d56f2915beb09f36274f899d3 (diff)
downloadmullvadvpn-ba5fd1dc93e45cb4407dfc0e3be3ce6f1b178c2f.tar.xz
mullvadvpn-ba5fd1dc93e45cb4407dfc0e3be3ce6f1b178c2f.zip
Refactor `ConnectFragment` to use the job tracker
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt33
1 files changed, 8 insertions, 25 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
index f7cd2887c3..6b8fe59409 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
@@ -5,13 +5,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
-import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.R
-import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.model.TunnelState
import org.joda.time.DateTime
@@ -25,10 +20,6 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
private lateinit var status: ConnectionStatus
private lateinit var locationInfo: LocationInfo
- private lateinit var updateKeyStatusJob: Job
- private var updateLocationInfoJob: Job? = null
- private var updateTunnelStateJob: Job? = null
-
private var isTunnelInfoExpanded = false
override fun onCreate(savedInstanceState: Bundle?) {
@@ -68,8 +59,6 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
switchLocationButton = SwitchLocationButton(view, resources)
switchLocationButton.onClick = { openSwitchLocationScreen() }
- updateKeyStatusJob = updateKeyStatus(keyStatusListener.keyStatus)
-
return view
}
@@ -79,13 +68,13 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
notificationBanner.onResume()
keyStatusListener.onKeyStatusChange.subscribe(this) { keyStatus ->
- updateKeyStatusJob.cancel()
- updateKeyStatusJob = updateKeyStatus(keyStatus)
+ jobTracker.newUiJob("updateKeyStatus") {
+ notificationBanner.keyState = keyStatus
+ }
}
locationInfoCache.onNewLocation = { location ->
- updateLocationInfoJob?.cancel()
- updateLocationInfoJob = GlobalScope.launch(Dispatchers.Main) {
+ jobTracker.newUiJob("updateLocationInfo") {
locationInfo.location = location
}
}
@@ -96,8 +85,9 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
}
connectionProxy.onUiStateChange.subscribe(this) { uiState ->
- updateTunnelStateJob?.cancel()
- updateTunnelStateJob = updateTunnelState(uiState, connectionProxy.state)
+ jobTracker.newUiJob("updateTunnelState") {
+ updateTunnelState(uiState, connectionProxy.state)
+ }
}
accountCache.onAccountDataChange = { _, expiry ->
@@ -117,8 +107,6 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
keyStatusListener.onKeyStatusChange.unsubscribe(this)
connectionProxy.onUiStateChange.unsubscribe(this)
- updateLocationInfoJob?.cancel()
- updateTunnelStateJob?.cancel()
notificationBanner.onPause()
isTunnelInfoExpanded = locationInfo.isTunnelInfoExpanded
@@ -133,8 +121,7 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
state.putBoolean(KEY_IS_TUNNEL_INFO_EXPANDED, isTunnelInfoExpanded)
}
- private fun updateTunnelState(uiState: TunnelState, realState: TunnelState) =
- GlobalScope.launch(Dispatchers.Main) {
+ private fun updateTunnelState(uiState: TunnelState, realState: TunnelState) {
notificationBanner.tunnelState = realState
locationInfo.state = realState
headerBar.setState(realState)
@@ -144,10 +131,6 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
switchLocationButton.state = uiState
}
- private fun updateKeyStatus(keyStatus: KeygenEvent?) = GlobalScope.launch(Dispatchers.Main) {
- notificationBanner.keyState = keyStatus
- }
-
private fun openSwitchLocationScreen() {
fragmentManager?.beginTransaction()?.apply {
setCustomAnimations(