diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-11-21 20:46:28 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-16 12:36:00 +0000 |
| commit | 0e46ee247195a3db4b09c1f333e5942b2b9c330c (patch) | |
| tree | 64d42b20f39e65dcc1443bb93e2e62f964357ed0 /android/src | |
| parent | e3d9659da7cf22175374a96cff66d3154db3105b (diff) | |
| download | mullvadvpn-0e46ee247195a3db4b09c1f333e5942b2b9c330c.tar.xz mullvadvpn-0e46ee247195a3db4b09c1f333e5942b2b9c330c.zip | |
Refactor error message selection for in-app banner
Diffstat (limited to 'android/src')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/TunnelStateNotification.kt | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/TunnelStateNotification.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/TunnelStateNotification.kt index 52460ed4fb..6db3cf2ffd 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/TunnelStateNotification.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/TunnelStateNotification.kt @@ -53,10 +53,20 @@ class TunnelStateNotification( } private fun show(error: ErrorState?) { - val cause = error?.cause + // if the error state is null, we can assume that we are secure + if (error?.isBlocking ?: true) { + title = blockingTitle + message = error?.cause?.let { cause -> blockingErrorMessage(cause) } + } else { + title = notBlockingTitle + message = notBlockingErrorMessage(error?.cause) + } + + shouldShow = true + } - val messageText = when (cause) { - null -> null + private fun blockingErrorMessage(cause: ErrorStateCause): String { + val messageId = when (cause) { is ErrorStateCause.AuthFailed -> R.string.auth_failed is ErrorStateCause.Ipv6Unavailable -> R.string.ipv6_unavailable is ErrorStateCause.SetFirewallPolicyError -> R.string.set_firewall_policy_error @@ -79,21 +89,16 @@ class TunnelStateNotification( is ErrorStateCause.VpnPermissionDenied -> R.string.vpn_permission_denied_error } - // if the error state is null, we can assume that we are secure - if (error?.isBlocking ?: true) { - title = blockingTitle - message = messageText?.let { id -> context.getString(id) } - } else { - val updatedMessageText = when (cause) { - is ErrorStateCause.VpnPermissionDenied -> messageText - else -> R.string.failed_to_block_internet - } + return context.getString(messageId) + } - title = notBlockingTitle - message = updatedMessageText?.let { id -> context.getString(id) } + private fun notBlockingErrorMessage(cause: ErrorStateCause?): String { + val messageId = when (cause) { + is ErrorStateCause.VpnPermissionDenied -> R.string.vpn_permission_denied_error + else -> R.string.failed_to_block_internet } - shouldShow = true + return context.getString(messageId) } private fun hide() { |
