|
@@ -93,6 +93,8 @@ namespace PRS.Mobile
|
|
|
MobileLogging.Log("MainPage.Appearing");
|
|
|
if (_selectionpage == null)
|
|
|
{
|
|
|
+ _notificationsToken = new CancellationTokenSource();
|
|
|
+
|
|
|
BackButtonEnabled = App.IsSharedDevice;
|
|
|
|
|
|
EnableModules();
|
|
@@ -108,12 +110,6 @@ namespace PRS.Mobile
|
|
|
|
|
|
CheckTimeSheet();
|
|
|
}
|
|
|
-
|
|
|
- App.Data.Notifications.Refresh(false, () => Device.BeginInvokeOnMainThread(() =>
|
|
|
- {
|
|
|
- var count = App.Data.Notifications.Items.Count(x => x.Closed.IsEmpty());
|
|
|
- Notifications.Indicator = count > 0 ? count.ToString() : "";
|
|
|
- }));
|
|
|
|
|
|
_selectionpage = null;
|
|
|
|
|
@@ -132,7 +128,7 @@ namespace PRS.Mobile
|
|
|
//App.Data.GPSLocationUpdated -= OnGPSLocationUpdated;
|
|
|
//App.Data.BluetoothScanFinished -= OnBluetothScanFinished;
|
|
|
|
|
|
- _canceltasks.Cancel();
|
|
|
+ _notificationsToken.Cancel();
|
|
|
}
|
|
|
|
|
|
private void OnBluetothScanFinished(BluetoothEventArgs args)
|
|
@@ -177,7 +173,7 @@ namespace PRS.Mobile
|
|
|
RefreshScreen();
|
|
|
}
|
|
|
|
|
|
- private CancellationTokenSource _canceltasks = new CancellationTokenSource();
|
|
|
+ private CancellationTokenSource _notificationsToken = new CancellationTokenSource();
|
|
|
private int _notificationcount = 0;
|
|
|
|
|
|
private void StartMonitoringNotifications()
|
|
@@ -185,22 +181,21 @@ namespace PRS.Mobile
|
|
|
//notifications are allowed to upload once every 30 seconds
|
|
|
// This will eventually be replaced with websocket pushes
|
|
|
// but we're not ready for that yet :-(
|
|
|
- var token = _canceltasks.Token;
|
|
|
+ var token = _notificationsToken.Token;
|
|
|
Task.Run(
|
|
|
() =>
|
|
|
{
|
|
|
- while (!_canceltasks.Token.IsCancellationRequested)
|
|
|
+ while (!_notificationsToken.Token.IsCancellationRequested)
|
|
|
{
|
|
|
App.Data.Notifications.Refresh(true);
|
|
|
- if (App.Data.Notifications.Items.Count != _notificationcount)
|
|
|
+ _notificationcount = App.Data.Notifications.Items.Where(x=>x.Closed.IsEmpty()).ToList().Count;
|
|
|
+ Dispatcher.BeginInvokeOnMainThread(() =>
|
|
|
{
|
|
|
- Dispatcher.BeginInvokeOnMainThread(() =>
|
|
|
- {
|
|
|
- _notificationcount = App.Data.Notifications.Items.Count;
|
|
|
- Notifications.Indicator = _notificationcount.ToString();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
+ Notifications.Indicator = _notificationcount > 0
|
|
|
+ ? _notificationcount.ToString()
|
|
|
+ : "";
|
|
|
+ });
|
|
|
+
|
|
|
Task.Delay(TimeSpan.FromSeconds(30), token)
|
|
|
.Wait(token);
|
|
|
}
|
|
@@ -211,7 +206,7 @@ namespace PRS.Mobile
|
|
|
|
|
|
private void StartPromptingForUpdates()
|
|
|
{
|
|
|
- var token = _canceltasks.Token;
|
|
|
+ var token = _notificationsToken.Token;
|
|
|
Task.Run(
|
|
|
() =>
|
|
|
{
|
|
@@ -309,7 +304,7 @@ namespace PRS.Mobile
|
|
|
_currenttimesheet = table.Rows.FirstOrDefault()?.ToObject<TimeSheet>();
|
|
|
}
|
|
|
|
|
|
- var token = _canceltasks.Token;
|
|
|
+ var token = _notificationsToken.Token;
|
|
|
Task.Run(
|
|
|
() =>
|
|
|
{
|