From c4eb69949445d9899f7fef49c28079567c150864 Mon Sep 17 00:00:00 2001 From: Vladislav Antonyuk Date: Wed, 26 Jun 2024 14:53:43 +0300 Subject: [PATCH] MauiNotifications --- Auth/AuthServices/AuthServices.csproj | 2 +- Auth/MauiAuth/MauiAuth.csproj | 2 +- Auth/MauiAuthBlazor/MauiAuthBlazor.csproj | 2 +- .../MauiTaskListApp/MauiTaskListApp.csproj | 2 +- DynamicFab/DynamicFab.csproj | 2 +- IPTVPlayer/IPTVPlayer.csproj | 4 +- KanbanBoard/KanbanBoard.csproj | 2 +- MauiAnimation/MauiAnimation.csproj | 2 +- MauiBank/MauiBank.csproj | 2 +- MauiBells/MauiBells.csproj | 2 +- MauiBluetooth/MauiBluetooth.csproj | 4 +- MauiCaptcha/MauiCaptcha.csproj | 2 +- MauiLocalization/MauiLocalization.csproj | 2 +- MauiMaps/MauiMaps.csproj | 4 +- MauiMultiWindow/MauiMultiWindow.csproj | 2 +- MauiNotifications/App.xaml | 14 + MauiNotifications/App.xaml.cs | 20 + MauiNotifications/AppShell.xaml | 15 + MauiNotifications/AppShell.xaml.cs | 9 + .../DeviceInstallationService.cs | 22 + MauiNotifications/MainPage.xaml | 36 ++ MauiNotifications/MainPage.xaml.cs | 23 + MauiNotifications/MauiNotifications.csproj | 45 ++ MauiNotifications/MauiProgram.cs | 24 + .../Platforms/Android/AndroidManifest.xml | 10 + .../Platforms/Android/MainActivity.cs | 9 + .../Platforms/Android/MainApplication.cs | 15 + .../DeviceInstallationService.cs | 41 ++ ...ushNotificationFirebaseMessagingService.cs | 45 ++ .../Android/Resources/values/colors.xml | 6 + .../Platforms/Android/google-services.json | 39 ++ .../Platforms/MacCatalyst/AppDelegate.cs | 9 + .../MacCatalyst/DeviceInstallationService.cs | 16 + .../Platforms/MacCatalyst/Entitlements.plist | 14 + .../Platforms/MacCatalyst/Info.plist | 38 ++ .../Platforms/MacCatalyst/Program.cs | 15 + .../Tizen/DeviceInstallationService.cs | 16 + MauiNotifications/Platforms/Tizen/Main.cs | 17 + .../Platforms/Tizen/tizen-manifest.xml | 15 + MauiNotifications/Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 23 + .../Windows/DeviceInstallationService.cs | 32 ++ .../Platforms/Windows/Package.appxmanifest | 60 +++ .../Platforms/Windows/app.manifest | 15 + .../Platforms/iOS/AppDelegate.cs | 9 + .../iOS/DeviceInstallationService.cs | 16 + MauiNotifications/Platforms/iOS/Info.plist | 32 ++ MauiNotifications/Platforms/iOS/Program.cs | 15 + .../Properties/launchSettings.json | 8 + MauiNotifications/README.md | 7 + MauiNotifications/README.mdpp | 7 + .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Images/dotnet_bot.png | Bin 0 -> 69811 bytes MauiNotifications/Resources/Splash/splash.svg | 8 + .../Resources/Styles/Colors.xaml | 45 ++ .../Resources/Styles/Styles.xaml | 426 ++++++++++++++++++ MauiPaint/MauiPaint.csproj | 2 +- MauiSamples.sln | 44 +- .../MauiShellCustomization.csproj | 2 +- MauiSpeech/MauiSpeech.csproj | 2 +- .../Client.Android.UITests.csproj | 2 +- .../Client.MacCatalyst.UITests.csproj | 2 +- .../Client.Tizen.UITests.csproj | 2 +- .../Client.Windows.UITests.csproj | 2 +- .../Client.iOS.UITests.csproj | 2 +- .../MauiWorkflowBuilder.csproj | 2 +- README.md | 2 + README.mdpp | 2 + TutorialHelp/TutorialHelp.csproj | 2 +- 70 files changed, 1294 insertions(+), 46 deletions(-) create mode 100644 MauiNotifications/App.xaml create mode 100644 MauiNotifications/App.xaml.cs create mode 100644 MauiNotifications/AppShell.xaml create mode 100644 MauiNotifications/AppShell.xaml.cs create mode 100644 MauiNotifications/DeviceInstallationService.cs create mode 100644 MauiNotifications/MainPage.xaml create mode 100644 MauiNotifications/MainPage.xaml.cs create mode 100644 MauiNotifications/MauiNotifications.csproj create mode 100644 MauiNotifications/MauiProgram.cs create mode 100644 MauiNotifications/Platforms/Android/AndroidManifest.xml create mode 100644 MauiNotifications/Platforms/Android/MainActivity.cs create mode 100644 MauiNotifications/Platforms/Android/MainApplication.cs create mode 100644 MauiNotifications/Platforms/Android/Notifications/DeviceInstallationService.cs create mode 100644 MauiNotifications/Platforms/Android/Notifications/PushNotificationFirebaseMessagingService.cs create mode 100644 MauiNotifications/Platforms/Android/Resources/values/colors.xml create mode 100644 MauiNotifications/Platforms/Android/google-services.json create mode 100644 MauiNotifications/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 MauiNotifications/Platforms/MacCatalyst/DeviceInstallationService.cs create mode 100644 MauiNotifications/Platforms/MacCatalyst/Entitlements.plist create mode 100644 MauiNotifications/Platforms/MacCatalyst/Info.plist create mode 100644 MauiNotifications/Platforms/MacCatalyst/Program.cs create mode 100644 MauiNotifications/Platforms/Tizen/DeviceInstallationService.cs create mode 100644 MauiNotifications/Platforms/Tizen/Main.cs create mode 100644 MauiNotifications/Platforms/Tizen/tizen-manifest.xml create mode 100644 MauiNotifications/Platforms/Windows/App.xaml create mode 100644 MauiNotifications/Platforms/Windows/App.xaml.cs create mode 100644 MauiNotifications/Platforms/Windows/DeviceInstallationService.cs create mode 100644 MauiNotifications/Platforms/Windows/Package.appxmanifest create mode 100644 MauiNotifications/Platforms/Windows/app.manifest create mode 100644 MauiNotifications/Platforms/iOS/AppDelegate.cs create mode 100644 MauiNotifications/Platforms/iOS/DeviceInstallationService.cs create mode 100644 MauiNotifications/Platforms/iOS/Info.plist create mode 100644 MauiNotifications/Platforms/iOS/Program.cs create mode 100644 MauiNotifications/Properties/launchSettings.json create mode 100644 MauiNotifications/README.md create mode 100644 MauiNotifications/README.mdpp create mode 100644 MauiNotifications/Resources/AppIcon/appicon.svg create mode 100644 MauiNotifications/Resources/AppIcon/appiconfg.svg create mode 100644 MauiNotifications/Resources/Images/dotnet_bot.png create mode 100644 MauiNotifications/Resources/Splash/splash.svg create mode 100644 MauiNotifications/Resources/Styles/Colors.xaml create mode 100644 MauiNotifications/Resources/Styles/Styles.xaml diff --git a/Auth/AuthServices/AuthServices.csproj b/Auth/AuthServices/AuthServices.csproj index 17dac02d..1c8fb5f6 100644 --- a/Auth/AuthServices/AuthServices.csproj +++ b/Auth/AuthServices/AuthServices.csproj @@ -5,7 +5,7 @@ - + diff --git a/Auth/MauiAuth/MauiAuth.csproj b/Auth/MauiAuth/MauiAuth.csproj index 3ce1bc7b..0618a01b 100644 --- a/Auth/MauiAuth/MauiAuth.csproj +++ b/Auth/MauiAuth/MauiAuth.csproj @@ -25,7 +25,7 @@ - + diff --git a/Auth/MauiAuthBlazor/MauiAuthBlazor.csproj b/Auth/MauiAuthBlazor/MauiAuthBlazor.csproj index d05c969a..db3e97bb 100644 --- a/Auth/MauiAuthBlazor/MauiAuthBlazor.csproj +++ b/Auth/MauiAuthBlazor/MauiAuthBlazor.csproj @@ -26,7 +26,7 @@ - + diff --git a/Database/MauiTaskListApp/MauiTaskListApp.csproj b/Database/MauiTaskListApp/MauiTaskListApp.csproj index b1fbf980..fde3e343 100644 --- a/Database/MauiTaskListApp/MauiTaskListApp.csproj +++ b/Database/MauiTaskListApp/MauiTaskListApp.csproj @@ -30,7 +30,7 @@ - + diff --git a/DynamicFab/DynamicFab.csproj b/DynamicFab/DynamicFab.csproj index 7b5de69d..aaf63c81 100644 --- a/DynamicFab/DynamicFab.csproj +++ b/DynamicFab/DynamicFab.csproj @@ -26,7 +26,7 @@ - + diff --git a/IPTVPlayer/IPTVPlayer.csproj b/IPTVPlayer/IPTVPlayer.csproj index 2bf33724..6f90c74b 100644 --- a/IPTVPlayer/IPTVPlayer.csproj +++ b/IPTVPlayer/IPTVPlayer.csproj @@ -32,8 +32,8 @@ - - + + diff --git a/KanbanBoard/KanbanBoard.csproj b/KanbanBoard/KanbanBoard.csproj index 8b5bf920..6569fcbc 100644 --- a/KanbanBoard/KanbanBoard.csproj +++ b/KanbanBoard/KanbanBoard.csproj @@ -27,7 +27,7 @@ - + all diff --git a/MauiAnimation/MauiAnimation.csproj b/MauiAnimation/MauiAnimation.csproj index e91c78bb..bf4a8e35 100644 --- a/MauiAnimation/MauiAnimation.csproj +++ b/MauiAnimation/MauiAnimation.csproj @@ -27,7 +27,7 @@ - + diff --git a/MauiBank/MauiBank.csproj b/MauiBank/MauiBank.csproj index a08d17f9..965755ea 100644 --- a/MauiBank/MauiBank.csproj +++ b/MauiBank/MauiBank.csproj @@ -32,7 +32,7 @@ - + diff --git a/MauiBells/MauiBells.csproj b/MauiBells/MauiBells.csproj index e4e7a78b..08308189 100644 --- a/MauiBells/MauiBells.csproj +++ b/MauiBells/MauiBells.csproj @@ -31,7 +31,7 @@ - + diff --git a/MauiBluetooth/MauiBluetooth.csproj b/MauiBluetooth/MauiBluetooth.csproj index 0c4fe906..6338dbc1 100644 --- a/MauiBluetooth/MauiBluetooth.csproj +++ b/MauiBluetooth/MauiBluetooth.csproj @@ -26,9 +26,9 @@ - + - + diff --git a/MauiCaptcha/MauiCaptcha.csproj b/MauiCaptcha/MauiCaptcha.csproj index 6c82c667..139c14d7 100644 --- a/MauiCaptcha/MauiCaptcha.csproj +++ b/MauiCaptcha/MauiCaptcha.csproj @@ -32,7 +32,7 @@ - + diff --git a/MauiLocalization/MauiLocalization.csproj b/MauiLocalization/MauiLocalization.csproj index b288e5f3..5111658f 100644 --- a/MauiLocalization/MauiLocalization.csproj +++ b/MauiLocalization/MauiLocalization.csproj @@ -29,7 +29,7 @@ - + diff --git a/MauiMaps/MauiMaps.csproj b/MauiMaps/MauiMaps.csproj index a05b31e6..29b0ccec 100644 --- a/MauiMaps/MauiMaps.csproj +++ b/MauiMaps/MauiMaps.csproj @@ -29,9 +29,9 @@ - + - + diff --git a/MauiMultiWindow/MauiMultiWindow.csproj b/MauiMultiWindow/MauiMultiWindow.csproj index 99871bcb..47d21918 100644 --- a/MauiMultiWindow/MauiMultiWindow.csproj +++ b/MauiMultiWindow/MauiMultiWindow.csproj @@ -25,6 +25,6 @@ - + \ No newline at end of file diff --git a/MauiNotifications/App.xaml b/MauiNotifications/App.xaml new file mode 100644 index 00000000..30f427dc --- /dev/null +++ b/MauiNotifications/App.xaml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/MauiNotifications/App.xaml.cs b/MauiNotifications/App.xaml.cs new file mode 100644 index 00000000..e3fe7a35 --- /dev/null +++ b/MauiNotifications/App.xaml.cs @@ -0,0 +1,20 @@ +namespace MauiNotifications; + +public partial class App +{ + private readonly DeviceInstallationService deviceInstallationService; + + public App(DeviceInstallationService deviceInstallationService) + { + this.deviceInstallationService = deviceInstallationService; + InitializeComponent(); + + MainPage = new AppShell(); + } + + protected override async void OnStart() + { + base.OnStart(); + await deviceInstallationService.RegisterDevice(); + } +} \ No newline at end of file diff --git a/MauiNotifications/AppShell.xaml b/MauiNotifications/AppShell.xaml new file mode 100644 index 00000000..b07f536d --- /dev/null +++ b/MauiNotifications/AppShell.xaml @@ -0,0 +1,15 @@ + + + + + + diff --git a/MauiNotifications/AppShell.xaml.cs b/MauiNotifications/AppShell.xaml.cs new file mode 100644 index 00000000..4481b486 --- /dev/null +++ b/MauiNotifications/AppShell.xaml.cs @@ -0,0 +1,9 @@ +namespace MauiNotifications; + +public partial class AppShell : Shell +{ + public AppShell() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/MauiNotifications/DeviceInstallationService.cs b/MauiNotifications/DeviceInstallationService.cs new file mode 100644 index 00000000..57eef5cd --- /dev/null +++ b/MauiNotifications/DeviceInstallationService.cs @@ -0,0 +1,22 @@ +namespace MauiNotifications; + +using Microsoft.Azure.NotificationHubs; + +public partial class DeviceInstallationService(IConnectivity connectivity, INotificationHubClient notificationHubClient) +{ + public async Task RegisterDevice() + { + if (connectivity.NetworkAccess != NetworkAccess.Internet) + { + return; + } + + var installation = await GetInstallation(); + if (installation == null) + { + return; + } + + await notificationHubClient.CreateOrUpdateInstallationAsync(installation); + } +} \ No newline at end of file diff --git a/MauiNotifications/MainPage.xaml b/MauiNotifications/MainPage.xaml new file mode 100644 index 00000000..a7535c0a --- /dev/null +++ b/MauiNotifications/MainPage.xaml @@ -0,0 +1,36 @@ + + + + + + + +