diff options
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoCache.kt | 11 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/AppVersionInfoFetcher.kt | 23 |
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() + } } } } |
