summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 11:28:37 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 11:28:37 -0300
commit4bb7784e0bdac6ca641d8ab16e29e82aaec6fc21 (patch)
tree65c5a4d2a139fc7b4d37ccbb5cc961716ede3aea
parent5c1cc92f024380712f62b4d69fc3468b3e73a00e (diff)
parent8a7f10fe8c8001c60a4630f12970ee442d749e77 (diff)
downloadmullvadvpn-4bb7784e0bdac6ca641d8ab16e29e82aaec6fc21.tar.xz
mullvadvpn-4bb7784e0bdac6ca641d8ab16e29e82aaec6fc21.zip
Merge branch 'improve-wireguard-error-notifications'
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt2
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt39
-rw-r--r--android/src/main/res/layout/connect.xml88
-rw-r--r--android/src/main/res/values/strings.xml3
4 files changed, 93 insertions, 39 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
index a5f14cfa92..62a9765cce 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ConnectFragment.kt
@@ -59,7 +59,7 @@ class ConnectFragment : Fragment() {
}
headerBar = HeaderBar(view, context!!)
- notificationBanner = NotificationBanner(view)
+ notificationBanner = NotificationBanner(view, context!!)
status = ConnectionStatus(view, context!!)
locationInfo = LocationInfo(view, locationInfoCache)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt
index 6a56d7c3e3..7060011158 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt
@@ -1,5 +1,8 @@
package net.mullvad.mullvadvpn
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
import android.widget.TextView
import android.view.View
@@ -8,11 +11,15 @@ import net.mullvad.mullvadvpn.model.BlockReason
import net.mullvad.mullvadvpn.model.KeygenEvent
import net.mullvad.mullvadvpn.model.TunnelState
-class NotificationBanner(val parentView: View) {
+class NotificationBanner(val parentView: View, val context: Context) {
+ private val accountUrl = Uri.parse(context.getString(R.string.account_url))
+
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 val icon: View = parentView.findViewById(R.id.notification_icon)
+ private var externalLink: Uri? = null
private var visible = false
var keyState: KeygenEvent? = null
@@ -27,7 +34,12 @@ class NotificationBanner(val parentView: View) {
update()
}
+ init {
+ banner.setOnClickListener { onClick() }
+ }
+
private fun update() {
+ externalLink = null
updateBasedOnKeyState() || updateBasedOnTunnelState()
}
@@ -35,8 +47,13 @@ class NotificationBanner(val parentView: View) {
when (keyState) {
null -> return false
is KeygenEvent.NewKey -> return false
- is KeygenEvent.TooManyKeys -> show(R.string.too_many_keys, null)
- is KeygenEvent.GenerationFailure -> show(R.string.failed_to_generate_key, null)
+ is KeygenEvent.TooManyKeys -> {
+ externalLink = accountUrl
+ show(R.string.wireguard_error, R.string.too_many_keys)
+ }
+ is KeygenEvent.GenerationFailure -> {
+ show(R.string.wireguard_error, R.string.failed_to_generate_key)
+ }
}
return true
@@ -94,6 +111,14 @@ class NotificationBanner(val parentView: View) {
message.setText(messageText)
message.visibility = View.VISIBLE
}
+
+ if (externalLink == null) {
+ banner.setClickable(false)
+ icon.visibility = View.GONE
+ } else {
+ banner.setClickable(true)
+ icon.visibility = View.VISIBLE
+ }
}
private fun hide() {
@@ -104,4 +129,12 @@ class NotificationBanner(val parentView: View) {
}
}
}
+
+ private fun onClick() {
+ val externalLink = this.externalLink
+
+ if (externalLink != null) {
+ context.startActivity(Intent(Intent.ACTION_VIEW, externalLink))
+ }
+ }
}
diff --git a/android/src/main/res/layout/connect.xml b/android/src/main/res/layout/connect.xml
index c876ed15e1..4468e838e8 100644
--- a/android/src/main/res/layout/connect.xml
+++ b/android/src/main/res/layout/connect.xml
@@ -49,52 +49,70 @@
/>
</LinearLayout>
- <RelativeLayout android:id="@+id/notification_banner"
+ <FrameLayout 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:visibility="invisible"
+ android:clickable="false"
>
- <RelativeLayout android:id="@+id/notification_status_container"
- android:layout_width="wrap_content"
+ <RelativeLayout
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_alignBottom="@id/notification_title"
+ android:paddingVertical="8dp"
+ android:paddingLeft="20dp"
+ android:paddingRight="10dp"
+ android:background="?android:attr/selectableItemBackground"
>
- <ImageView android:id="@+id/notification_status"
+ <RelativeLayout android:id="@+id/notification_status_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- 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="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:layout_toLeftOf="@id/notification_icon"
+ 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"
+ />
+ <TextView android:id="@+id/notification_message"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignWithParentIfMissing="true"
+ android:layout_toLeftOf="@id/notification_icon"
+ android:layout_alignLeft="@id/notification_title"
+ android:layout_below="@id/notification_title"
+ android:textSize="13sp"
+ android:textColor="@color/white60"
+ android:text=""
+ android:visibility="gone"
+ />
+ <ImageView android:id="@+id/notification_icon"
+ android:layout_width="12dp"
+ android:layout_height="12dp"
+ android:layout_alignParentRight="true"
+ android:layout_centerVertical="true"
+ android:alpha="0.6"
+ android:src="@drawable/icon_extlink"
+ android:visibility="gone"
/>
</RelativeLayout>
- <TextView android:id="@+id/notification_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- 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"
- />
- <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>
+ </FrameLayout>
<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 20e8a5635d..fbacb36a81 100644
--- a/android/src/main/res/values/strings.xml
+++ b/android/src/main/res/values/strings.xml
@@ -71,6 +71,7 @@
<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="wireguard_error">WireGuard 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>
@@ -79,4 +80,6 @@
While connected, your real location is masked with a private and secure location in the
selected region
</string>
+
+ <string name="account_url">https://mullvad.net/en/account</string>
</resources>