summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 14:15:39 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-07-31 15:32:33 +0000
commit0864ddbd4e1d7566f50affa261dcc6a7f969db96 (patch)
treee75d08f8964032c7a5afbae722cae5e3eb6e47a8 /android
parent4bb7784e0bdac6ca641d8ab16e29e82aaec6fc21 (diff)
downloadmullvadvpn-0864ddbd4e1d7566f50affa261dcc6a7f969db96.tar.xz
mullvadvpn-0864ddbd4e1d7566f50affa261dcc6a7f969db96.zip
Move constants to new `AppVersionInfoCache` class
Diffstat (limited to 'android')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt11
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt23
2 files changed, 21 insertions, 13 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt
new file mode 100644
index 0000000000..0b99e97bb7
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt
@@ -0,0 +1,11 @@
+package net.mullvad.mullvadvpn.dataproxy
+
+class AppVersionInfoCache {
+ companion object {
+ val KEY_CURRENT_IS_SUPPORTED = "current_is_supported"
+ val KEY_LAST_UPDATED = "last_updated"
+ val KEY_LATEST_STABLE = "latest_stable"
+ val KEY_LATEST = "latest"
+ val SHARED_PREFERENCES = "app_version_info_cache"
+ }
+}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt
index 2b066c934b..26c6e2f885 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt
@@ -15,14 +15,9 @@ import net.mullvad.mullvadvpn.MullvadDaemon
val ONE_DAY_IN_MILLISECONDS = 24L * 60L * 60L * 1000L
val ONE_MINUTE_IN_MILLISECONDS = 60L * 1000L
-val KEY_CURRENT_IS_SUPPORTED = "current_is_supported"
-val KEY_LAST_UPDATED = "last_updated"
-val KEY_LATEST_STABLE = "latest_stable"
-val KEY_LATEST = "latest"
-val SHARED_PREFERENCES = "app_version_info_cache"
-
class AppVersionInfoFetcher(val daemon: Deferred<MullvadDaemon>, val context: Context) {
- private val preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE)
+ private val preferences =
+ context.getSharedPreferences(AppVersionInfoCache.SHARED_PREFERENCES, Context.MODE_PRIVATE)
private val mainLoop = run()
@@ -39,7 +34,7 @@ class AppVersionInfoFetcher(val daemon: Deferred<MullvadDaemon>, val context: Co
private fun calculateDelay(): Long {
val now = Calendar.getInstance().timeInMillis
- val lastUpdated = preferences.getLong(KEY_LAST_UPDATED, 0)
+ val lastUpdated = preferences.getLong(AppVersionInfoCache.KEY_LAST_UPDATED, 0)
val delta = now - lastUpdated
if (delta < 0 || delta >= ONE_DAY_IN_MILLISECONDS) {
@@ -63,11 +58,13 @@ class AppVersionInfoFetcher(val daemon: Deferred<MullvadDaemon>, val context: Co
if (versionInfo != null) {
preferences.edit().apply {
- putLong(KEY_LAST_UPDATED, now)
- putBoolean(KEY_CURRENT_IS_SUPPORTED, versionInfo.currentIsSupported)
- putString(KEY_LATEST_STABLE, versionInfo.latestStable)
- putString(KEY_LATEST, versionInfo.latest)
- commit()
+ with(AppVersionInfoCache) {
+ putLong(KEY_LAST_UPDATED, now)
+ putBoolean(KEY_CURRENT_IS_SUPPORTED, versionInfo.currentIsSupported)
+ putString(KEY_LATEST_STABLE, versionInfo.latestStable)
+ putString(KEY_LATEST, versionInfo.latest)
+ commit()
+ }
}
}
}