Created
July 14, 2020 16:52
-
-
Save felipebaltazar/7da51d44d9c69e4bc88323c170e2af37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainPageViewModel : ViewModelBase | |
{ | |
private readonly IDisposable _gpsDisposer; | |
... | |
public MainPageViewModel(INavigationService navigationService, IGpsManager gpsManager) | |
: base(navigationService) | |
{ | |
... | |
// Vamos inscrever a viewmodel para ser | |
// notificada quando houver uma nova leitura | |
_gpsDisposer = gpsManager.WhenReading() | |
.Subscribe(OnNext, OnError); | |
} | |
public void OnError(Exception error) | |
{ | |
CurrentLocation = error.Message; | |
} | |
public void OnNext(IGpsReading reading) | |
{ | |
CurrentLocation = $"Latitude: {reading.Position.Latitude} | Longitude: {reading.Position.Longitude}"; | |
} | |
... | |
public override void Destroy() | |
{ | |
base.Destroy(); | |
// Lembrando sempre de desinscrever o observador | |
_gpsDisposer?.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment