summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-07 00:25:45 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-16 12:14:04 +0000
commit3d607e3f815719757aed4749c1688f51bb1d712e (patch)
tree49ec076a191fb154861aab0697fa295f86238218 /android/src
parenteede0577955c2986281f2cf361fee5969a320cce (diff)
downloadmullvadvpn-3d607e3f815719757aed4749c1688f51bb1d712e.tar.xz
mullvadvpn-3d607e3f815719757aed4749c1688f51bb1d712e.zip
Refactor to use observable property
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoCache.kt30
1 files changed, 12 insertions, 18 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoCache.kt
index 2ac54297d5..6bac1f20ee 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoCache.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/AppVersionInfoCache.kt
@@ -1,6 +1,7 @@
package net.mullvad.mullvadvpn.ui.serviceconnection
import android.content.Context
+import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.ipc.DispatchingHandler
import net.mullvad.mullvadvpn.ipc.Event
import net.mullvad.mullvadvpn.model.AppVersionInfo
@@ -14,13 +15,9 @@ class AppVersionInfoCache(
val LEGACY_SHARED_PREFERENCES = "app_version_info_cache"
}
- private var appVersionInfo: AppVersionInfo? = null
- set(value) {
- synchronized(this) {
- field = value
- onUpdate?.invoke()
- }
- }
+ private var appVersionInfo by observable<AppVersionInfo?>(null) { _, _, _ ->
+ onUpdate?.invoke()
+ }
val isSupported
get() = appVersionInfo?.supported ?: true
@@ -31,19 +28,16 @@ class AppVersionInfoCache(
val upgradeVersion
get() = appVersionInfo?.suggestedUpgrade
- var onUpdate: (() -> Unit)? = null
- set(value) {
- field = value
- value?.invoke()
- }
+ var onUpdate by observable<(() -> Unit)?>(null) { _, _, callback ->
+ callback?.invoke()
+ }
- var showBetaReleases = false
- private set(value) {
- if (field != value) {
- field = value
- onUpdate?.invoke()
- }
+ var showBetaReleases by observable(false) { _, wasShowing, shouldShow ->
+ if (shouldShow != wasShowing) {
+ onUpdate?.invoke()
}
+ }
+ private set
var version: String? = null
private set