diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2020-12-04 21:58:40 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2021-03-25 18:19:59 +0000 |
| commit | 3b48618bd6ed593e0a2e0777e4a05039b00a6f9a (patch) | |
| tree | 31ca07d73750f793c4612afe05bf07261863af08 | |
| parent | d43abc650372dca8e85370ecb53db4afef203456 (diff) | |
| download | mullvadvpn-3b48618bd6ed593e0a2e0777e4a05039b00a6f9a.tar.xz mullvadvpn-3b48618bd6ed593e0a2e0777e4a05039b00a6f9a.zip | |
Update `LocationInfoCache` to listen for locations
2 files changed, 20 insertions, 7 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/LocationInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/LocationInfoCache.kt index 42d4906202..eb3a8c736a 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/LocationInfoCache.kt @@ -1,11 +1,24 @@ package net.mullvad.mullvadvpn.ui.serviceconnection -class LocationInfoCache( - val serviceCache: net.mullvad.mullvadvpn.service.endpoint.LocationInfoCache -) { - var onNewLocation - get() = serviceCache.onNewLocation - set(value) { serviceCache.onNewLocation = value } +import kotlin.properties.Delegates.observable +import net.mullvad.mullvadvpn.ipc.DispatchingHandler +import net.mullvad.mullvadvpn.ipc.Event +import net.mullvad.mullvadvpn.model.GeoIpLocation + +class LocationInfoCache(val eventDispatcher: DispatchingHandler<Event>) { + private var location: GeoIpLocation? by observable(null) { _, _, newLocation -> + onNewLocation?.invoke(newLocation) + } + + var onNewLocation by observable<((GeoIpLocation?) -> Unit)?>(null) { _, _, callback -> + callback?.invoke(location) + } + + init { + eventDispatcher.registerHandler(Event.NewLocation::class) { event -> + location = event.location + } + } fun onDestroy() { onNewLocation = null diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt index aa055c47b2..da0e09b703 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/ServiceConnection.kt @@ -26,7 +26,7 @@ class ServiceConnection(private val service: ServiceInstance, val mainActivity: val connectionProxy = service.connectionProxy val customDns = service.customDns val keyStatusListener = service.keyStatusListener - val locationInfoCache = LocationInfoCache(service.locationInfoCache) + val locationInfoCache = LocationInfoCache(dispatcher) val settingsListener = SettingsListener(dispatcher) val splitTunneling = service.splitTunneling |
