Skip to content

Commit

Permalink
fix: add OnServerListUpdatedListener in LocationViewModel
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajhilje committed Aug 6, 2023
1 parent 468ceb1 commit c289d06
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ServersRepository @Inject constructor(
LOGGER.info(response.toString())
response.markServerTypes()
setServerList(response.openVpnServerList, response.wireGuardServerList)
updateLocations()
settings.setIpList(Mapper.stringFromIps(response.config.api.ips))
settings.setIPv6List(Mapper.stringFromIps(response.config.api.ipv6s))
settings.wireGuardPorts = response.config.ports.wireguard.filter { it.portNumber > 0 }
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/net/ivpn/core/v2/viewmodel/LocationViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import net.ivpn.core.common.dagger.ApplicationScope
import net.ivpn.core.common.distance.DistanceProvider
import net.ivpn.core.common.prefs.OnServerListUpdatedListener
import net.ivpn.core.common.prefs.ServersRepository
import net.ivpn.core.common.prefs.Settings
import net.ivpn.core.rest.HttpClientFactory
import net.ivpn.core.rest.IVPNApi
import net.ivpn.core.rest.RequestListener
import net.ivpn.core.rest.data.model.Server
import net.ivpn.core.rest.data.model.ServerLocation
import net.ivpn.core.rest.data.proofs.LocationResponse
import net.ivpn.core.rest.requests.common.Request
Expand Down Expand Up @@ -102,6 +104,7 @@ class LocationViewModel @Inject constructor(
vpnBehaviorController.addVpnStateListener(getVpnStateListener())
checkLocation()
protocolController.addOnProtocolChangedListener(getOnProtocolChangeListener())
serversRepository.addOnServersListUpdatedListener(getOnServerListUpdatedListener())
uiIPStateListener = object : OnIPStateChangedListener {
override fun onIPStateChanged(uiState: IPState) {
if (uiState == ipState.get()) return
Expand Down Expand Up @@ -372,6 +375,16 @@ class LocationViewModel @Inject constructor(
return OnProtocolChangedListener { locations.set(serversRepository.locations) }
}

private fun getOnServerListUpdatedListener(): OnServerListUpdatedListener {
return object : OnServerListUpdatedListener {
override fun onSuccess(servers: List<Server>, isForced: Boolean) {
locations.set(serversRepository.locations)
}
override fun onError(throwable: Throwable) {}
override fun onError() {}
}
}

private fun getVpnStateListener(): VpnStateListener {
return object : VpnStateListenerImpl() {
override fun onConnectionStateChanged(state: ConnectionState) {
Expand Down

0 comments on commit c289d06

Please sign in to comment.