summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-09 19:54:44 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-22 12:29:44 +0000
commit74408e14fde254530e55c1ee8f335a157f6b6bc4 (patch)
tree347275da04f0e18201a1beb3ed28f42386a397c3 /android
parent8712e5b0a2b7738f2f9bbcb0edf6aaf1d47abec7 (diff)
downloadmullvadvpn-74408e14fde254530e55c1ee8f335a157f6b6bc4.tar.xz
mullvadvpn-74408e14fde254530e55c1ee8f335a157f6b6bc4.zip
Update notification every 12 hours
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/notifications/AccountExpiryNotification.kt12
1 files changed, 12 insertions, 0 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 d405c104e5..34c1360f72 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
@@ -7,7 +7,9 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import kotlin.properties.Delegates.observable
+import kotlinx.coroutines.delay
import net.mullvad.mullvadvpn.R
+import net.mullvad.mullvadvpn.util.JobTracker
import org.joda.time.DateTime
import org.joda.time.Duration
@@ -15,8 +17,10 @@ class AccountExpiryNotification(val context: Context) {
companion object {
val NOTIFICATION_ID: Int = 2
val REMAINING_TIME_FOR_REMINDERS = Duration.standardDays(2)
+ val TIME_BETWEEN_CHECKS: Long = 12 /* h */ * 60 /* min */ * 60 /* s */ * 1000 /* ms */
}
+ private val jobTracker = JobTracker()
private val resources = context.resources
private val buyMoreTimeUrl = Uri.parse(resources.getString(R.string.account_url))
@@ -42,11 +46,19 @@ class AccountExpiryNotification(val context: Context) {
val notification = build(accountExpiry, remainingTime)
channel.notificationManager.notify(NOTIFICATION_ID, notification)
+
+ jobTracker.newUiJob("scheduleUpdate") { scheduleUpdate() }
} else {
channel.notificationManager.cancel(NOTIFICATION_ID)
+ jobTracker.cancelJob("scheduleUpdate")
}
}
+ private suspend fun scheduleUpdate() {
+ delay(TIME_BETWEEN_CHECKS)
+ update(accountExpiry)
+ }
+
private fun build(expiry: DateTime, remainingTime: Duration): Notification {
val intent = Intent(Intent.ACTION_VIEW, buyMoreTimeUrl)
val flags = PendingIntent.FLAG_UPDATE_CURRENT