diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-07-31 10:22:26 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-07-31 10:22:26 -0300 |
| commit | 5c1cc92f024380712f62b4d69fc3468b3e73a00e (patch) | |
| tree | 8cc4d6cccbcdf2f78f0dfcc095e0c5f3415c3604 /android | |
| parent | bb151cecadf612fd6028288f25568d312b9fbeb3 (diff) | |
| parent | dbce7615b87aee57514e384c7969a64808e01126 (diff) | |
| download | mullvadvpn-5c1cc92f024380712f62b4d69fc3468b3e73a00e.tar.xz mullvadvpn-5c1cc92f024380712f62b4d69fc3468b3e73a00e.zip | |
Merge branch 'block-reason-messages'
Diffstat (limited to 'android')
5 files changed, 86 insertions, 20 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt index f6e50fd94e..6a56d7c3e3 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt @@ -4,12 +4,14 @@ import android.widget.TextView import android.view.View import net.mullvad.mullvadvpn.model.ActionAfterDisconnect +import net.mullvad.mullvadvpn.model.BlockReason import net.mullvad.mullvadvpn.model.KeygenEvent import net.mullvad.mullvadvpn.model.TunnelState class NotificationBanner(val parentView: View) { private val banner: View = parentView.findViewById(R.id.notification_banner) private val title: TextView = parentView.findViewById(R.id.notification_title) + private val message: TextView = parentView.findViewById(R.id.notification_message) private var visible = false @@ -33,8 +35,8 @@ class NotificationBanner(val parentView: View) { when (keyState) { null -> return false is KeygenEvent.NewKey -> return false - is KeygenEvent.TooManyKeys -> show(R.string.too_many_keys) - is KeygenEvent.GenerationFailure -> show(R.string.failed_to_generate_key) + is KeygenEvent.TooManyKeys -> show(R.string.too_many_keys, null) + is KeygenEvent.GenerationFailure -> show(R.string.failed_to_generate_key, null) } return true @@ -47,20 +49,36 @@ class NotificationBanner(val parentView: View) { is TunnelState.Disconnecting -> { when (state.actionAfterDisconnect) { is ActionAfterDisconnect.Nothing -> hide() - is ActionAfterDisconnect.Block -> show(R.string.blocking_internet) - is ActionAfterDisconnect.Reconnect -> show(R.string.blocking_internet) + is ActionAfterDisconnect.Block -> showBlocking(null) + is ActionAfterDisconnect.Reconnect -> showBlocking(null) } } is TunnelState.Disconnected -> hide() - is TunnelState.Connecting -> show(R.string.blocking_internet) + is TunnelState.Connecting -> showBlocking(null) is TunnelState.Connected -> hide() - is TunnelState.Blocked -> show(R.string.blocking_internet) + is TunnelState.Blocked -> showBlocking(state.reason) } return true } - private fun show(message: Int) { + private fun showBlocking(reason: BlockReason?) { + val messageText = when (reason) { + null -> null + is BlockReason.AuthFailed -> R.string.auth_failed + is BlockReason.Ipv6Unavailable -> R.string.ipv6_unavailable + is BlockReason.SetFirewallPolicyError -> R.string.set_firewall_policy_error + is BlockReason.SetDnsError -> R.string.set_dns_error + is BlockReason.StartTunnelError -> R.string.start_tunnel_error + is BlockReason.NoMatchingRelay -> R.string.no_matching_relay + is BlockReason.IsOffline -> R.string.is_offline + is BlockReason.TapAdapterProblem -> R.string.tap_adapter_problem + } + + show(R.string.blocking_internet, messageText) + } + + private fun show(titleText: Int, messageText: Int?) { if (!visible) { visible = true banner.visibility = View.VISIBLE @@ -68,7 +86,14 @@ class NotificationBanner(val parentView: View) { banner.animate().translationY(0.0F).setDuration(350).start() } - title.setText(message) + title.setText(titleText) + + if (messageText == null) { + message.visibility = View.GONE + } else { + message.setText(messageText) + message.visibility = View.VISIBLE + } } private fun hide() { diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/BlockReason.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/BlockReason.kt new file mode 100644 index 0000000000..769a97b6fa --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/BlockReason.kt @@ -0,0 +1,12 @@ +package net.mullvad.mullvadvpn.model + +sealed class BlockReason { + class AuthFailed(val reason: String?) : BlockReason() + class Ipv6Unavailable : BlockReason() + class SetFirewallPolicyError : BlockReason() + class SetDnsError : BlockReason() + class StartTunnelError : BlockReason() + class NoMatchingRelay : BlockReason() + class IsOffline : BlockReason() + class TapAdapterProblem : BlockReason() +} diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/TunnelState.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/TunnelState.kt index b08e75e3e8..054a07ed4d 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/model/TunnelState.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/model/TunnelState.kt @@ -5,5 +5,5 @@ sealed class TunnelState() { class Connecting(val location: GeoIpLocation?) : TunnelState() class Connected(val location: GeoIpLocation?) : TunnelState() class Disconnecting(val actionAfterDisconnect: ActionAfterDisconnect) : TunnelState() - class Blocked() : TunnelState() + class Blocked(val reason: BlockReason) : TunnelState() } diff --git a/android/src/main/res/layout/connect.xml b/android/src/main/res/layout/connect.xml index 5b05e4c2f3..c876ed15e1 100644 --- a/android/src/main/res/layout/connect.xml +++ b/android/src/main/res/layout/connect.xml @@ -49,33 +49,52 @@ /> </LinearLayout> - <LinearLayout android:id="@+id/notification_banner" + <RelativeLayout android:id="@+id/notification_banner" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingVertical="8dp" + android:paddingLeft="20dp" + android:paddingRight="10dp" android:background="@color/darkBlue" - android:orientation="horizontal" - android:gravity="center" android:visibility="invisible" > - <ImageView + <RelativeLayout android:id="@+id/notification_status_container" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="0" - android:layout_marginLeft="19dp" - android:src="@drawable/icon_notification_error" - /> + android:layout_alignParentTop="true" + android:layout_alignParentLeft="true" + android:layout_alignBottom="@id/notification_title" + > + <ImageView android:id="@+id/notification_status" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerInParent="true" + android:src="@drawable/icon_notification_error" + /> + </RelativeLayout> <TextView android:id="@+id/notification_title" - android:layout_width="0dp" + android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" + android:layout_alignParentTop="true" + android:layout_toRightOf="@id/notification_status_container" android:layout_marginLeft="7dp" android:textSize="13sp" android:textStyle="bold" android:text="@string/blocking_internet" android:textAllCaps="true" /> - </LinearLayout> + <TextView android:id="@+id/notification_message" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_alignLeft="@id/notification_title" + android:layout_below="@id/notification_title" + android:textSize="13sp" + android:textColor="@color/white60" + android:text="" + android:visibility="gone" + /> + </RelativeLayout> <Space android:layout_width="match_parent" diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index 0ca628f401..20e8a5635d 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -61,6 +61,16 @@ <string name="switch_location">Switch location</string> <string name="blocking_internet">Blocking internet</string> + <string name="auth_failed">Account authentication failed.</string> + <string name="ipv6_unavailable">Could not configure IPv6</string> + <string name="set_firewall_policy_error"> + Failed to apply firewall rules. The device might currently be unsecured + </string> + <string name="set_dns_error">Failed to set system DNS server</string> + <string name="start_tunnel_error">Failed to start tunnel connection</string> + <string name="no_matching_relay">No relay server matches the current settings</string> + <string name="is_offline">This device is offline, no tunnels can be established</string> + <string name="tap_adapter_problem">TAP adapter error</string> <string name="too_many_keys">Too many WireGuard keys registered to account</string> <string name="failed_to_generate_key">Failed to generate WireGuard key</string> |
