summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-09 19:31:32 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-22 12:29:44 +0000
commit8712e5b0a2b7738f2f9bbcb0edf6aaf1d47abec7 (patch)
tree07b66ac42bba6e9c62f0fe6dcdf7b1731a235f85 /android/src
parent2cc9011c032283261709d1657ef85734a6eae667 (diff)
downloadmullvadvpn-8712e5b0a2b7738f2f9bbcb0edf6aaf1d47abec7.tar.xz
mullvadvpn-8712e5b0a2b7738f2f9bbcb0edf6aaf1d47abec7.zip
Only show account time reminders when running out
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt27
1 files changed, 17 insertions, 10 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
index 0a40afc763..d405c104e5 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt
@@ -14,6 +14,7 @@ import org.joda.time.Duration
class AccountExpiryNotification(val context: Context) {
companion object {
val NOTIFICATION_ID: Int = 2
+ val REMAINING_TIME_FOR_REMINDERS = Duration.standardDays(2)
}
private val resources = context.resources
@@ -30,25 +31,31 @@ class AccountExpiryNotification(val context: Context) {
var accountExpiry by observable<DateTime?>(null) { _, oldValue, newValue ->
if (oldValue != newValue) {
- if (newValue != null) {
- channel.notificationManager.notify(NOTIFICATION_ID, build(newValue))
- } else {
- channel.notificationManager.cancel(NOTIFICATION_ID)
- }
+ update(newValue)
}
}
- private fun build(expiry: DateTime): Notification {
+ private fun update(accountExpiry: DateTime?) {
+ val remainingTime = accountExpiry?.let { expiry -> Duration(DateTime.now(), expiry) }
+
+ if (remainingTime != null && remainingTime.isShorterThan(REMAINING_TIME_FOR_REMINDERS)) {
+ val notification = build(accountExpiry, remainingTime)
+
+ channel.notificationManager.notify(NOTIFICATION_ID, notification)
+ } else {
+ channel.notificationManager.cancel(NOTIFICATION_ID)
+ }
+ }
+
+ private fun build(expiry: DateTime, remainingTime: Duration): Notification {
val intent = Intent(Intent.ACTION_VIEW, buyMoreTimeUrl)
val flags = PendingIntent.FLAG_UPDATE_CURRENT
val pendingIntent = PendingIntent.getActivity(context, 1, intent, flags)
- return channel.buildNotification(pendingIntent, format(expiry))
+ return channel.buildNotification(pendingIntent, format(expiry, remainingTime))
}
- private fun format(expiry: DateTime): String {
- val remainingTime = Duration(DateTime.now(), expiry)
-
+ private fun format(expiry: DateTime, remainingTime: Duration): String {
if (remainingTime.isShorterThan(Duration.ZERO)) {
return resources.getString(R.string.account_credit_has_expired)
} else {