diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-06-26 17:05:50 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-07-01 20:22:02 +0000 |
| commit | 5e49b276c9dd82d3e2de7494d4c70e3660fb7c28 (patch) | |
| tree | 362e6ea39853f64656a3b55e6c6963a417f0fbdc /android/src/main | |
| parent | 76c014b878399d375dad036b049cf2575bba5d01 (diff) | |
| download | mullvadvpn-5e49b276c9dd82d3e2de7494d4c70e3660fb7c28.tar.xz mullvadvpn-5e49b276c9dd82d3e2de7494d4c70e3660fb7c28.zip | |
Create version upgrade in-app notification
Diffstat (limited to 'android/src/main')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/VersionInfoNotification.kt | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/VersionInfoNotification.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/VersionInfoNotification.kt new file mode 100644 index 0000000000..8c5fe7568e --- /dev/null +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/notification/VersionInfoNotification.kt @@ -0,0 +1,53 @@ +package net.mullvad.mullvadvpn.ui.notification + +import android.content.Context +import net.mullvad.mullvadvpn.R +import net.mullvad.mullvadvpn.dataproxy.AppVersionInfoCache + +class VersionInfoNotification( + context: Context, + private val versionInfoCache: AppVersionInfoCache +) : NotificationWithUrl(context, R.string.download_url) { + private val unsupportedVersion = context.getString(R.string.unsupported_version) + private val updateAvailable = context.getString(R.string.update_available) + + override fun onResume() { + versionInfoCache.onUpdate = { + jobTracker.newUiJob("updateVersionInfo") { + updateVersionInfo( + versionInfoCache.isOutdated, + versionInfoCache.isSupported, + versionInfoCache.upgradeVersion + ) + } + } + } + + override fun onPause() { + versionInfoCache.onUpdate = null + } + + private fun updateVersionInfo(isOutdated: Boolean, isSupported: Boolean, upgrade: String?) { + if (isOutdated || !isSupported) { + val template: Int + + if (isSupported) { + status = StatusLevel.Warning + title = updateAvailable + template = R.string.update_available_description + } else { + status = StatusLevel.Error + title = unsupportedVersion + template = R.string.unsupported_version_description + } + + message = context.getString(template, upgrade) + + shouldShow = true + } else { + shouldShow = false + } + + update() + } +} |
