-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
App.cs
82 lines (63 loc) · 2.28 KB
/
App.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using AsyncAwaitBestPractices;
using GitTrends.Shared;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
namespace GitTrends
{
public class App : Xamarin.Forms.Application
{
static readonly WeakEventManager _resumedEventManager = new();
readonly IAnalyticsService _analyticsService;
readonly NotificationService _notificationService;
readonly AppInitializationService _appInitializationService;
public App(LanguageService languageService,
SplashScreenPage splashScreenPage,
IAnalyticsService analyticsService,
NotificationService notificationService,
AppInitializationService appInitializationService)
{
_analyticsService = analyticsService;
_notificationService = notificationService;
_appInitializationService = appInitializationService;
analyticsService.Track("App Initialized", new Dictionary<string, string>
{
{ nameof(LanguageService.PreferredLanguage), languageService.PreferredLanguage ?? "default" },
{ nameof(CultureInfo.CurrentUICulture), CultureInfo.CurrentUICulture.TwoLetterISOLanguageName }
});
MainPage = splashScreenPage;
On<iOS>().SetHandleControlUpdatesOnMainThread(true);
}
public static event EventHandler Resumed
{
add => _resumedEventManager.AddEventHandler(value);
remove => _resumedEventManager.RemoveEventHandler(value);
}
protected override async void OnStart()
{
base.OnStart();
_analyticsService.Track("App Started");
await ClearBageNotifications();
var appInitializationCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(15));
await _appInitializationService.InitializeApp(appInitializationCancellationTokenSource.Token);
}
protected override async void OnResume()
{
base.OnResume();
OnResumed();
_analyticsService.Track("App Resumed");
await ClearBageNotifications();
}
protected override void OnSleep()
{
base.OnSleep();
_analyticsService.Track("App Backgrounded");
}
ValueTask ClearBageNotifications() => _notificationService.SetAppBadgeCount(0);
void OnResumed() => _resumedEventManager.RaiseEvent(this, EventArgs.Empty, nameof(Resumed));
}
}