Skip to content

Commit fa8f975

Browse files
Cleanup.
1 parent 0d57fb6 commit fa8f975

24 files changed

+287
-284
lines changed

sample/Sample.Android/MainActivity.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Android.Content.PM;
1111
using Android.OS;
1212
using Android.Runtime;
13+
using Notifo.SDK;
1314
using Notifo.SDK.FirebasePlugin;
1415
using Prism;
1516
using Prism.Ioc;
@@ -30,13 +31,13 @@ protected override void OnCreate(Bundle savedInstanceState)
3031
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
3132
LoadApplication(new App(new AndroidInitializer()));
3233

33-
NotifoFirebasePlugin.ProcessIntent(this, Intent);
34+
NotifoIO.Current.ProcessIntent(this, Intent);
3435
}
3536

3637
protected override void OnNewIntent(Intent intent)
3738
{
3839
base.OnNewIntent(intent);
39-
NotifoFirebasePlugin.ProcessIntent(this, intent);
40+
NotifoIO.Current.ProcessIntent(this, intent);
4041
}
4142

4243
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)

sample/Sample.Android/MainApplication.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Android.App;
1010
using Android.OS;
1111
using Android.Runtime;
12+
using Notifo.SDK;
1213
using Notifo.SDK.FirebasePlugin;
1314
using Plugin.FirebasePushNotification;
1415

@@ -31,11 +32,15 @@ public override void OnCreate()
3132
FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";
3233
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
3334
}
35+
36+
var resetToken = false;
3437
#if DEBUG
35-
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), new NotificationHandler(), resetToken: true);
36-
#else
37-
NotifoFirebasePlugin.Initialize(this, new NotifoStartup(), new NotificationHandler(), resetToken: false);
38+
resetToken = true;
3839
#endif
40+
NotifoIO.Current
41+
.SetNotificationHandler(new NotificationHandler())
42+
.UseDefaults()
43+
.UseFirebasePluginEventsProvider(this, resetToken: resetToken);
3944
}
4045
}
4146
}

sample/Sample.iOS/AppDelegate.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using Foundation;
10+
using Notifo.SDK;
1011
using Notifo.SDK.FirebasePlugin;
1112
using Prism;
1213
using Prism.Ioc;
@@ -26,33 +27,39 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary
2627
global::Xamarin.Forms.Forms.Init();
2728
LoadApplication(new App(new iOSInitializer()));
2829

29-
NotifoFirebasePlugin.Initialize(launchOptions, new NotifoStartup(), new NotificationHandler(), true);
30+
NotifoIO.Current
31+
.SetNotificationHandler(new NotificationHandler())
32+
.UseDefaults()
33+
.UseFirebasePluginEventsProvider(launchOptions, true);
34+
3035
UNUserNotificationCenter.Current.Delegate = this;
3136

3237
return base.FinishedLaunching(uiApplication, launchOptions);
3338
}
3439

3540
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
3641
{
37-
NotifoFirebasePlugin.DidRegisterRemoteNotifications(deviceToken);
42+
NotifoIO.Current.DidRegisterRemoteNotifications(deviceToken);
3843
}
3944

4045
public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
4146
{
42-
NotifoFirebasePlugin.RemoteNotificationRegistrationFailed(error);
47+
NotifoIO.Current.RemoteNotificationRegistrationFailed(error);
4348
}
4449

4550
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
4651
public override async void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
4752
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void
4853
{
49-
await NotifoFirebasePlugin.DidReceiveMessageAsync(userInfo);
54+
await NotifoIO.Current.DidReceiveMessageAsync(userInfo);
5055
completionHandler(UIBackgroundFetchResult.NewData);
5156
}
5257

5358
[Export("userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:")]
54-
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler) =>
55-
NotifoFirebasePlugin.DidReceiveNotificationResponse(center, response, completionHandler);
59+
public void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
60+
{
61+
NotifoIO.Current.DidReceiveNotificationResponse(center, response, completionHandler);
62+
}
5663

5764
#pragma warning disable SA1300 // Element should begin with upper-case letter
5865
#pragma warning disable IDE1006 // Naming Styles

sample/Sample/NotifoStartup.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111

1212
namespace Sample
1313
{
14-
public class NotifoStartup : INotifoStartup
14+
public static class NotifoStartup
1515
{
16-
public void ConfigureService(INotifoMobilePush notifo)
16+
public static INotifoMobilePush UseDefaults(this INotifoMobilePush notifo)
1717
{
1818
notifo
1919
.SetSharedName("notifo.Sample")
2020
.SetBaseUrl(Constants.ApiUrl)
2121
.UseFirebasePluginEventsProvider();
2222

2323
notifo.OnNotificationOpened += Current_OnNotificationOpened;
24+
25+
return notifo;
2426
}
2527

26-
private void Current_OnNotificationOpened(object source, NotificationEventArgs e)
28+
private static void Current_OnNotificationOpened(object source, NotificationEventArgs e)
2729
{
2830
Device.BeginInvokeOnMainThread(() =>
2931
{

sample/Sample/Sample.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<ImplicitUsings>enable</ImplicitUsings>
54
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
65
<TargetFramework>netstandard2.1</TargetFramework>
76
</PropertyGroup>

sample/Sample/ViewModels/EventsPageViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8+
using System;
89
using System.Diagnostics;
910
using MvvmHelpers;
1011
using Notifo.SDK;

sample/SampleNotificationServiceExtension/NotificationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override async void DidReceiveNotificationRequest(UNNotificationRequest r
3737
.SetSharedName("notifo.Sample")
3838
.SetNotificationHandler(new NotificationHandler());
3939

40-
await NotifoIO.DidReceiveNotificationRequestAsync(request, BestAttemptContent);
40+
await NotifoIO.Current.DidReceiveNotificationRequestAsync(request, BestAttemptContent);
4141

4242
// Display the notification.
4343
ContentHandler(BestAttemptContent);

sdk/Notifo.SDK.FirebasePlugin/Notifo.SDK.FirebasePlugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<None Include="**\*.netstandard.cs" />
4141
<None Include="**\*.android.cs" />
4242
</ItemGroup>
43-
43+
4444
<ItemGroup>
4545
<PackageReference Include="Notifo.SDK" Version="1.7.3" />
4646
</ItemGroup>

sdk/Notifo.SDK.FirebasePlugin/NotifoFirebasePlugin.android.cs renamed to sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.android.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,50 @@
99
using Android.Content;
1010
using Plugin.FirebasePushNotification;
1111
using Notifo.SDK;
12+
using System;
13+
using System.Threading;
14+
using Notifo.SDK.NotifoMobilePush;
15+
using Notifo.SDK.PushEventProvider;
1216

1317
namespace Notifo.SDK.FirebasePlugin;
1418

1519
/// <summary>
16-
/// Plugin initialization.
20+
/// The <see cref="INotifoMobilePush"/> extension methods.
1721
/// </summary>
18-
public class NotifoFirebasePlugin
22+
public static partial class NotifoMobilePushExtensions
1923
{
24+
private static bool isAndroidHandlerRegistered;
25+
2026
/// <summary>
21-
/// Initializes the firebase plugin.
27+
/// Use the firebase plugin as the push events provider.
2228
/// </summary>
29+
/// <param name="notifo">The <see cref="INotifoMobilePush"/> instance.</param>
2330
/// <param name="context">The current application context.</param>
24-
/// <param name="notifoStartup">The <see cref="INotifoStartup"/> implementation.</param>
25-
/// <param name="notificationHandler">The <see cref="INotificationHandler"/> implementation.</param>
2631
/// <param name="resetToken">Set to <see langword="true"/> while debugging.</param>
2732
/// <param name="autoRegistration">Automatically register for push notifications.</param>
28-
public static void Initialize(Context context, INotifoStartup notifoStartup, INotificationHandler notificationHandler = null, bool resetToken = false, bool autoRegistration = true)
33+
/// <returns>The current instance.</returns>
34+
public static INotifoMobilePush UseFirebasePluginEventsProvider(this INotifoMobilePush notifo, Context context, bool resetToken = false, bool autoRegistration = true)
2935
{
36+
if (isAndroidHandlerRegistered)
37+
{
38+
return notifo;
39+
}
40+
3041
FirebasePushNotificationManager.Initialize(context, new NotifoPushNotificationHandler(), resetToken, createDefaultNotificationChannel: true, autoRegistration);
42+
isAndroidHandlerRegistered = true;
3143

32-
NotifoIO.Current.SetNotificationHandler(notificationHandler);
33-
notifoStartup.ConfigureService(NotifoIO.Current);
44+
return notifo.UseFirebasePluginEventsProvider();
3445
}
3546

3647
/// <summary>
3748
/// Method for processing open notification intent.
3849
/// </summary>
50+
/// <param name="notifo">The <see cref="INotifoMobilePush"/> instance.</param>
3951
/// <param name="activity">The current activity.</param>
4052
/// <param name="intent">The intent for processing.</param>
41-
public static void ProcessIntent(Activity activity, Intent intent)
53+
public static void ProcessIntent(this INotifoMobilePush notifo, Activity activity, Intent intent)
4254
{
55+
notifo.UseFirebasePluginEventsProvider();
4356
FirebasePushNotificationManager.ProcessIntent(activity, intent, enableDelayedResponse: true);
44-
NotifoIO.Current.UseFirebasePluginEventsProvider();
4557
}
4658
}

sdk/Notifo.SDK.FirebasePlugin/NotifoMobilePushExtensions.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,25 @@ namespace Notifo.SDK.FirebasePlugin;
1515
/// <summary>
1616
/// The <see cref="INotifoMobilePush"/> extension methods.
1717
/// </summary>
18-
public static class NotifoMobilePushExtensions
18+
public static partial class NotifoMobilePushExtensions
1919
{
20-
private static readonly Lazy<IPushEventsProvider> CurrentPluginEventsProvider =
21-
new Lazy<IPushEventsProvider>(() => new PluginEventsProvider(), LazyThreadSafetyMode.PublicationOnly);
20+
private static bool isHandlerRegistered;
2221

2322
/// <summary>
2423
/// Use the firebase plugin as the push events provider.
2524
/// </summary>
26-
/// <param name="notifoMobilePush">The <see cref="INotifoMobilePush"/> instance.</param>
25+
/// <param name="notifo">The <see cref="INotifoMobilePush"/> instance.</param>
2726
/// <returns>The current instance.</returns>
28-
public static INotifoMobilePush UseFirebasePluginEventsProvider(this INotifoMobilePush notifoMobilePush)
27+
public static INotifoMobilePush UseFirebasePluginEventsProvider(this INotifoMobilePush notifo)
2928
{
30-
return notifoMobilePush.SetPushEventsProvider(CurrentPluginEventsProvider.Value);
29+
if (isHandlerRegistered)
30+
{
31+
return notifo;
32+
}
33+
34+
notifo.SetPushEventsProvider(new PluginEventsProvider());
35+
isHandlerRegistered = true;
36+
37+
return notifo;
3138
}
3239
}

0 commit comments

Comments
 (0)