|
@@ -9,6 +9,7 @@ public class DefaultGeolocation : INotifyPropertyChanged, IGeolocation
|
|
|
{
|
|
|
|
|
|
private DateTime _nextCheck = DateTime.MaxValue;
|
|
|
+ private TimeSpan _remaining = TimeSpan.Zero;
|
|
|
|
|
|
public bool Scanning
|
|
|
{
|
|
@@ -23,11 +24,21 @@ public class DefaultGeolocation : INotifyPropertyChanged, IGeolocation
|
|
|
set
|
|
|
{
|
|
|
SetField(ref _currentLocation, value);
|
|
|
- LocationChanged?.Invoke(this, EventArgs.Empty);
|
|
|
+ LocationChanged?.Invoke(this, new GeoLocationChangedArgs(value));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public event EventHandler? LocationChanged;
|
|
|
+ private TimeSpan _frequency = TimeSpan.FromSeconds(10);
|
|
|
+
|
|
|
+ public TimeSpan Frequency
|
|
|
+ {
|
|
|
+ get => _frequency;
|
|
|
+ set => SetField(ref _frequency, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public event GeoLocationChangedHandler? LocationChanged;
|
|
|
+
|
|
|
+ public event GeoLocationTimerHandler? TimerChanged;
|
|
|
|
|
|
public Logger? Logger { get; set; }
|
|
|
|
|
@@ -48,20 +59,31 @@ public class DefaultGeolocation : INotifyPropertyChanged, IGeolocation
|
|
|
{
|
|
|
while (!_cancelTokenSource.Token.IsCancellationRequested)
|
|
|
{
|
|
|
- if (_nextCheck < DateTime.Now && !_isCheckingLocation)
|
|
|
+ if (!_isCheckingLocation)
|
|
|
{
|
|
|
- try
|
|
|
+ if (_nextCheck < DateTime.Now)
|
|
|
{
|
|
|
- _isCheckingLocation = true;
|
|
|
- CurrentLocation = await PlatformTools.Geolocation.GetLocationAsync(_cancelTokenSource);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _isCheckingLocation = true;
|
|
|
+ CurrentLocation =
|
|
|
+ await PlatformTools.Geolocation.GetLocationAsync(_cancelTokenSource);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger?.Send(LogType.Error, "", $"GPS Location Error: {ex.Message}");
|
|
|
+ CurrentLocation = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ _isCheckingLocation = false;
|
|
|
+ _nextCheck = DateTime.Now.Add(_frequency);
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ else
|
|
|
{
|
|
|
- Logger?.Send(LogType.Error, "", $"GPS Location Error: {ex.Message}");
|
|
|
- CurrentLocation = null;
|
|
|
+ _remaining = _nextCheck - DateTime.Now;
|
|
|
+ TimerChanged?.Invoke(this, new GeoLocationTimerArgs(_frequency, _remaining));
|
|
|
+ Thread.Sleep(100);
|
|
|
}
|
|
|
- _isCheckingLocation = false;
|
|
|
- _nextCheck = DateTime.Now.AddSeconds(30);
|
|
|
}
|
|
|
}
|
|
|
}
|