diff options
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt | 3 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/SwitchLocationButton.kt | 40 |
2 files changed, 43 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt index 39c535c1d7..60cb955496 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt @@ -87,6 +87,7 @@ class ConnectFragment : Fragment() { override fun onDestroyView() { locationInfo.onDestroy() + switchLocationButton.onDestroy() waitForDaemonJob?.cancel() attachListenerJob?.cancel() @@ -186,6 +187,8 @@ class ConnectFragment : Fragment() { private fun updateView(state: TunnelStateTransition) = GlobalScope.launch(Dispatchers.Main) { actionButton.state = state + switchLocationButton.state = state + headerBar.setState(state) notificationBanner.setState(state) status.setState(state) diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/SwitchLocationButton.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/SwitchLocationButton.kt index 72a33dc295..f3d2ac2b67 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/SwitchLocationButton.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/SwitchLocationButton.kt @@ -1,14 +1,54 @@ package net.mullvad.mullvadvpn +import kotlinx.coroutines.launch +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.Job + import android.view.View import android.widget.Button +import net.mullvad.mullvadvpn.model.TunnelStateTransition + class SwitchLocationButton(val parentView: View) { private val button: Button = parentView.findViewById(R.id.switch_location) + private var updateJob: Job? = null + + var state: TunnelStateTransition = TunnelStateTransition.Disconnected() + set(value) { + field = value + update() + } + var onClick: (() -> Unit)? = null init { button.setOnClickListener { onClick?.invoke() } } + + fun onDestroy() { + updateJob?.cancel() + } + + private fun update() { + updateJob?.cancel() + updateJob = GlobalScope.launch(Dispatchers.Main) { + when (state) { + is TunnelStateTransition.Disconnected -> showLocation() + is TunnelStateTransition.Disconnecting -> showLocation() + is TunnelStateTransition.Connecting -> showLabel() + is TunnelStateTransition.Connected -> showLabel() + is TunnelStateTransition.Blocked -> showLocation() + } + } + } + + private fun showLabel() { + button.setText(R.string.switch_location) + } + + private fun showLocation() { + showLabel() + } } |
