summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-02-17 09:21:07 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-02-17 09:21:07 -0300
commit2165675f9e851c821d2e402cd81f3755154f3dd3 (patch)
treee676e4eb83c097cea859ec526c7203c983a65440 /android
parentc1b90b2f3ba996668b9e54f158ce7e9b07d7ad48 (diff)
parent173dd672c0afc0c2235b6db4232920989f18675f (diff)
downloadmullvadvpn-2165675f9e851c821d2e402cd81f3755154f3dd3.tar.xz
mullvadvpn-2165675f9e851c821d2e402cd81f3755154f3dd3.zip
Merge branch 'android-reconnect-button'
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt24
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt5
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectActionButton.kt67
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt1
-rw-r--r--android/src/main/res/drawable/icon_reload.xml11
-rw-r--r--android/src/main/res/drawable/transparent_red_left_half_button_background.xml22
-rw-r--r--android/src/main/res/drawable/transparent_red_right_half_button_background.xml22
-rw-r--r--android/src/main/res/layout/connect.xml25
8 files changed, 163 insertions, 14 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt
index 16b34b137d..e55c696a2b 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/ConnectionProxy.kt
@@ -66,6 +66,15 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
}
}
+ fun reconnect() {
+ if (anticipateReconnectingState()) {
+ cancelActiveAction()
+ activeAction = GlobalScope.launch(Dispatchers.Default) {
+ daemon.reconnect()
+ }
+ }
+ }
+
fun disconnect() {
if (anticipateDisconnectingState()) {
cancelActiveAction()
@@ -103,6 +112,21 @@ class ConnectionProxy(val context: Context, val daemon: MullvadDaemon) {
}
}
+ private fun anticipateReconnectingState(): Boolean {
+ synchronized(this) {
+ val currentState = uiState
+
+ if (currentState is TunnelState.Disconnecting &&
+ currentState.actionAfterDisconnect == ActionAfterDisconnect.Reconnect) {
+ return false
+ } else {
+ scheduleToResetAnticipatedState()
+ uiState = TunnelState.Disconnecting(ActionAfterDisconnect.Reconnect)
+ return true
+ }
+ }
+ }
+
private fun anticipateDisconnectingState(): Boolean {
synchronized(this) {
val currentState = uiState
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
index df608dab69..65d123e31a 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/MullvadDaemon.kt
@@ -81,6 +81,10 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
return getWireguardKey(daemonInterfaceAddress)
}
+ fun reconnect() {
+ reconnect(daemonInterfaceAddress)
+ }
+
fun setAccount(accountToken: String?) {
setAccount(daemonInterfaceAddress, accountToken)
}
@@ -124,6 +128,7 @@ class MullvadDaemon(val vpnService: MullvadVpnService) {
private external fun getState(daemonInterfaceAddress: Long): TunnelState
private external fun getVersionInfo(daemonInterfaceAddress: Long): AppVersionInfo?
private external fun getWireguardKey(daemonInterfaceAddress: Long): PublicKey?
+ private external fun reconnect(daemonInterfaceAddress: Long)
private external fun setAccount(daemonInterfaceAddress: Long, accountToken: String?)
private external fun setAllowLan(daemonInterfaceAddress: Long, allowLan: Boolean)
private external fun setAutoConnect(daemonInterfaceAddress: Long, alwaysOn: Boolean)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectActionButton.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectActionButton.kt
index 439c68ca38..dc427a5ac5 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectActionButton.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectActionButton.kt
@@ -1,18 +1,37 @@
package net.mullvad.mullvadvpn.ui
import android.view.View
+import android.view.ViewGroup.MarginLayoutParams
import android.widget.Button
+import android.widget.ImageButton
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.model.TunnelState
import net.mullvad.talpid.tunnel.ActionAfterDisconnect
class ConnectActionButton(val parentView: View) {
- private val button: Button = parentView.findViewById(R.id.action_button)
+ private val mainButton: Button = parentView.findViewById(R.id.action_button)
+ private val reconnectButton: ImageButton = parentView.findViewById(R.id.reconnect_button)
private val resources = parentView.context.resources
private val greenBackground = resources.getDrawable(R.drawable.green_button_background, null)
- private val transparentRedBackground =
- resources.getDrawable(R.drawable.transparent_red_button_background, null)
+ private val leftRedBackground =
+ resources.getDrawable(R.drawable.transparent_red_left_half_button_background, null)
+
+ private var showReconnectButton = false
+ set(value) {
+ if (field != value) {
+ field = value
+ updateReconnectButton()
+ }
+ }
+
+ private var reconnectButtonSpace = 0
+ set(value) {
+ if (field != value) {
+ field = value
+ updateReconnectButton()
+ }
+ }
var tunnelState: TunnelState = TunnelState.Disconnected()
set(value) {
@@ -35,10 +54,23 @@ class ConnectActionButton(val parentView: View) {
var onConnect: (() -> Unit)? = null
var onCancel: (() -> Unit)? = null
+ var onReconnect: (() -> Unit)? = null
var onDisconnect: (() -> Unit)? = null
init {
- button.setOnClickListener { action() }
+ mainButton.setOnClickListener { action() }
+ reconnectButton.setOnClickListener { onReconnect?.invoke() }
+
+ reconnectButton.addOnLayoutChangeListener { _, left, _, right, _, _, _, _, _ ->
+ val width = right - left
+ val layoutParams = reconnectButton.layoutParams
+ val leftMargin = when (layoutParams) {
+ is MarginLayoutParams -> layoutParams.leftMargin
+ else -> 0
+ }
+
+ reconnectButtonSpace = width + leftMargin
+ }
}
private fun action() {
@@ -52,17 +84,32 @@ class ConnectActionButton(val parentView: View) {
}
private fun disconnected() {
- button.background = greenBackground
- button.setText(R.string.connect)
+ mainButton.background = greenBackground
+ mainButton.setText(R.string.connect)
+ showReconnectButton = false
}
private fun connecting() {
- button.background = transparentRedBackground
- button.setText(R.string.cancel)
+ redButton(R.string.cancel)
}
private fun connected() {
- button.background = transparentRedBackground
- button.setText(R.string.disconnect)
+ redButton(R.string.disconnect)
+ }
+
+ private fun redButton(text: Int) {
+ mainButton.background = leftRedBackground
+ mainButton.setText(text)
+ showReconnectButton = true
+ }
+
+ private fun updateReconnectButton() {
+ if (showReconnectButton) {
+ reconnectButton.visibility = View.VISIBLE
+ mainButton.setPadding(reconnectButtonSpace, 0, 0, 0)
+ } else {
+ reconnectButton.visibility = View.GONE
+ mainButton.setPadding(0, 0, 0, 0)
+ }
}
}
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 92ebdc102a..6c8bfc442d 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/ConnectFragment.kt
@@ -59,6 +59,7 @@ class ConnectFragment : ServiceDependentFragment(OnNoService.GoToLaunchScreen) {
actionButton.apply {
onConnect = { connectionProxy.connect() }
onCancel = { connectionProxy.disconnect() }
+ onReconnect = { connectionProxy.reconnect() }
onDisconnect = { connectionProxy.disconnect() }
}
diff --git a/android/src/main/res/drawable/icon_reload.xml b/android/src/main/res/drawable/icon_reload.xml
new file mode 100644
index 0000000000..457d15cb45
--- /dev/null
+++ b/android/src/main/res/drawable/icon_reload.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="22dp"
+ android:height="22dp"
+ android:viewportWidth="512.0"
+ android:viewportHeight="512.0"
+ >
+ <path android:fillColor="#FFFFFFFF"
+ android:pathData="M256.455 8c66.269.119 126.437 26.233 170.859 68.685l35.715-35.715C478.149 25.851 504 36.559 504 57.941V192c0 13.255-10.745 24-24 24H345.941c-21.382 0-32.09-25.851-16.971-40.971l41.75-41.75c-30.864-28.899-70.801-44.907-113.23-45.273-92.398-.798-170.283 73.977-169.484 169.442C88.764 348.009 162.184 424 256 424c41.127 0 79.997-14.678 110.629-41.556 4.743-4.161 11.906-3.908 16.368.553l39.662 39.662c4.872 4.872 4.631 12.815-.482 17.433C378.202 479.813 319.926 504 256 504 119.034 504 8.001 392.967 8 256.002 7.999 119.193 119.646 7.755 256.455 8z"
+ />
+</vector>
diff --git a/android/src/main/res/drawable/transparent_red_left_half_button_background.xml b/android/src/main/res/drawable/transparent_red_left_half_button_background.xml
new file mode 100644
index 0000000000..f3102dbeab
--- /dev/null
+++ b/android/src/main/res/drawable/transparent_red_left_half_button_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="false">
+ <shape android:shape="rectangle">
+ <corners
+ android:topLeftRadius="4dp"
+ android:bottomLeftRadius="4dp"
+ />
+ <solid android:color="@color/red60"/>
+ </shape>
+ </item>
+
+ <item android:state_pressed="true">
+ <shape android:shape="rectangle">
+ <corners
+ android:topLeftRadius="4dp"
+ android:bottomLeftRadius="4dp"
+ />
+ <solid android:color="@color/red80"/>
+ </shape>
+ </item>
+</selector>
diff --git a/android/src/main/res/drawable/transparent_red_right_half_button_background.xml b/android/src/main/res/drawable/transparent_red_right_half_button_background.xml
new file mode 100644
index 0000000000..64968d6f34
--- /dev/null
+++ b/android/src/main/res/drawable/transparent_red_right_half_button_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="false">
+ <shape android:shape="rectangle">
+ <corners
+ android:topRightRadius="4dp"
+ android:bottomRightRadius="4dp"
+ />
+ <solid android:color="@color/red60"/>
+ </shape>
+ </item>
+
+ <item android:state_pressed="true">
+ <shape android:shape="rectangle">
+ <corners
+ android:topRightRadius="4dp"
+ android:bottomRightRadius="4dp"
+ />
+ <solid android:color="@color/red80"/>
+ </shape>
+ </item>
+</selector>
diff --git a/android/src/main/res/layout/connect.xml b/android/src/main/res/layout/connect.xml
index 133a945259..44a73b01f6 100644
--- a/android/src/main/res/layout/connect.xml
+++ b/android/src/main/res/layout/connect.xml
@@ -237,9 +237,26 @@
android:paddingRight="8dp"
style="@style/White20Button"
/>
- <Button android:id="@+id/action_button"
- android:text="@string/connect"
- style="@style/GreenButton"
- />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ >
+ <Button android:id="@+id/action_button"
+ android:layout_weight="1"
+ android:text="@string/connect"
+ style="@style/GreenButton"
+ />
+ <ImageButton android:id="@+id/reconnect_button"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="0"
+ android:layout_marginLeft="1dp"
+ android:paddingHorizontal="10dp"
+ android:background="@drawable/transparent_red_right_half_button_background"
+ android:visibility="gone"
+ android:src="@drawable/icon_reload"
+ />
+ </LinearLayout>
</LinearLayout>
</LinearLayout>