summaryrefslogtreecommitdiffhomepage
path: root/android/src/main/kotlin
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 10:22:26 -0300
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 10:22:26 -0300
commit5c1cc92f024380712f62b4d69fc3468b3e73a00e (patch)
tree8cc4d6cccbcdf2f78f0dfcc095e0c5f3415c3604 /android/src/main/kotlin
parentbb151cecadf612fd6028288f25568d312b9fbeb3 (diff)
parentdbce7615b87aee57514e384c7969a64808e01126 (diff)
downloadmullvadvpn-5c1cc92f024380712f62b4d69fc3468b3e73a00e.tar.xz
mullvadvpn-5c1cc92f024380712f62b4d69fc3468b3e73a00e.zip
Merge branch 'block-reason-messages'
Diffstat (limited to 'android/src/main/kotlin')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/NotificationBanner.kt41
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/model/BlockReason.kt12
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/model/TunnelState.kt2
3 files changed, 46 insertions, 9 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()
}