diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-08-01 21:31:50 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-08-02 13:46:52 +0000 |
| commit | 3712d4b6ba67e88575a233a7fc9df8fcca670e7b (patch) | |
| tree | c03790cba7d9e792d15bb89b1f9c0ee2023ccbd5 /android | |
| parent | fc28a749fba82bf2fed844a7ffab33f3619f7233 (diff) | |
| download | mullvadvpn-3712d4b6ba67e88575a233a7fc9df8fcca670e7b.tar.xz mullvadvpn-3712d4b6ba67e88575a233a7fc9df8fcca670e7b.zip | |
Send `GeoIpLocation` instead of location strings
Diffstat (limited to 'android')
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/LocationInfo.kt | 18 | ||||
| -rw-r--r-- | android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt | 15 |
2 files changed, 13 insertions, 20 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/LocationInfo.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/LocationInfo.kt index f1fb1d7860..36e3a35223 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/LocationInfo.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/LocationInfo.kt @@ -4,6 +4,7 @@ import android.view.View import android.widget.TextView import net.mullvad.mullvadvpn.dataproxy.LocationInfoCache +import net.mullvad.mullvadvpn.model.GeoIpLocation class LocationInfo(val parentView: View, val locationInfoCache: LocationInfoCache) { private val countryLabel: TextView = parentView.findViewById(R.id.country) @@ -11,18 +12,19 @@ class LocationInfo(val parentView: View, val locationInfoCache: LocationInfoCach private val hostnameLabel: TextView = parentView.findViewById(R.id.hostname) init { - locationInfoCache.onNewLocation = { country, city, hostname -> - updateViews(country, city, hostname) + locationInfoCache.onNewLocation = { newLocation -> + location = newLocation } } + var location: GeoIpLocation? = null + set(value) { + countryLabel.text = value?.country ?: "" + cityLabel.text = value?.city ?: "" + hostnameLabel.text = value?.hostname ?: "" + } + fun onDestroy() { locationInfoCache.onNewLocation = null } - - fun updateViews(country: String, city: String, hostname: String) { - countryLabel.text = country - cityLabel.text = city - hostnameLabel.text = hostname - } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt index 6fc655c2a8..2f3b6fc84b 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/dataproxy/LocationInfoCache.kt @@ -22,16 +22,16 @@ class LocationInfoCache( private var lastKnownRealLocation: GeoIpLocation? = null private var activeFetch: Job? = null - var onNewLocation: ((String, String, String) -> Unit)? = null + var onNewLocation: ((GeoIpLocation?) -> Unit)? = null set(value) { field = value - notifyNewLocation() + value?.invoke(location) } var location: GeoIpLocation? = null set(value) { field = value - notifyNewLocation() + onNewLocation?.invoke(value) } var state: TunnelState = TunnelState.Disconnected() @@ -59,15 +59,6 @@ class LocationInfoCache( } } - fun notifyNewLocation() { - val location = this.location - val country = location?.country ?: "" - val city = location?.city ?: "" - val hostname = location?.hostname ?: "" - - onNewLocation?.invoke(country, city, hostname) - } - private fun locationFromSelectedRelay(): GeoIpLocation? { val relayItem = relayListListener.selectedRelayItem |
