diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-09-02 21:45:20 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-09-03 10:13:36 +0000 |
| commit | 3c2a26187ea9f757e09101b92a641010568c90b9 (patch) | |
| tree | ba9b0fc3db267b51073ccd4dcbeb299537870f05 /android/src | |
| parent | 37a8f67af8cb67abb68728094443b03e415e8c18 (diff) | |
| download | mullvadvpn-3c2a26187ea9f757e09101b92a641010568c90b9.tar.xz mullvadvpn-3c2a26187ea9f757e09101b92a641010568c90b9.zip | |
Remove obsoleted `SwitchLocationButton` controller
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SwitchLocationButton.kt | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SwitchLocationButton.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SwitchLocationButton.kt deleted file mode 100644 index 89eaf2cad8..0000000000 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/SwitchLocationButton.kt +++ /dev/null @@ -1,118 +0,0 @@ -package net.mullvad.mullvadvpn.ui - -import android.content.res.Resources -import android.graphics.drawable.Drawable -import android.text.TextUtils.TruncateAt -import android.view.View -import android.view.ViewGroup.MarginLayoutParams -import android.widget.Button -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.launch -import net.mullvad.mullvadvpn.R -import net.mullvad.mullvadvpn.model.TunnelState -import net.mullvad.mullvadvpn.relaylist.RelayItem -import net.mullvad.talpid.tunnel.ActionAfterDisconnect - -class SwitchLocationButton(val parentView: View, val resources: Resources) { - private val button: Button = parentView.findViewById(R.id.switch_location) - private val chevron: Drawable = button.compoundDrawables[2] - - private val normalButtonHeight = resources.getDimensionPixelSize(R.dimen.normal_button_height) - private val tallButtonHeight = resources.getDimensionPixelSize(R.dimen.tall_button_height) - private val topMargin = tallButtonHeight - normalButtonHeight - - private var tall = false - private var updateJob: Job? = null - - var location: RelayItem? = null - set(value) { - field = value - update() - } - - var state: TunnelState = TunnelState.Disconnected() - set(value) { - field = value - update() - } - - var onClick: (() -> Unit)? = null - - init { - button.setOnClickListener { onClick?.invoke() } - button.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> resizeIfNecessary() } - } - - fun onDestroy() { - updateJob?.cancel() - } - - private fun update() { - updateJob?.cancel() - updateJob = GlobalScope.launch(Dispatchers.Main) { - val state = this@SwitchLocationButton.state - - when (state) { - is TunnelState.Disconnected -> showLocation() - is TunnelState.Disconnecting -> { - when (state.actionAfterDisconnect) { - ActionAfterDisconnect.Nothing -> showLocation() - ActionAfterDisconnect.Block -> showLocation() - ActionAfterDisconnect.Reconnect -> showLabel() - } - } - is TunnelState.Connecting -> showLabel() - is TunnelState.Connected -> showLabel() - is TunnelState.Error -> showLocation() - } - } - } - - private fun showLabel() { - button.setText(R.string.switch_location) - button.setCompoundDrawables(null, null, null, null) - resizeIfNecessary() - } - - private fun showLocation() { - val locationName = location?.locationName - - if (locationName == null) { - showLabel() - } else { - button.setText(locationName) - button.setCompoundDrawables(null, null, chevron, null) - resizeIfNecessary() - } - } - - private fun resizeIfNecessary() { - val layoutParams = button.layoutParams - - if (button.lineCount > 1 && !tall) { - tall = true - - if (layoutParams is MarginLayoutParams) { - layoutParams.height = tallButtonHeight - layoutParams.topMargin = 0 - } - - button.maxLines = 2 - button.ellipsize = TruncateAt.END - button.requestLayout() - } else if (button.lineCount <= 1 && tall) { - tall = false - - if (layoutParams is MarginLayoutParams) { - layoutParams.height = normalButtonHeight - layoutParams.topMargin = topMargin - } - - button.maxLines = -1 - button.ellipsize = null - button.requestLayout() - } - } -} |
