From 833a1e456f6972479ca14cfdddd5ceca4a3c1170 Mon Sep 17 00:00:00 2001 From: MarcoE Date: Mon, 25 Aug 2025 10:00:41 +0200 Subject: [PATCH 1/4] Iniziata implementazione notifiche firebase --- .../IntegryApi/Dto/RegisterDeviceDTO.cs | 10 +++++ .../IntegryApi/Dto/WtbUserDeviceTokenDTO.cs | 22 +++++++++++ .../IntegryNotificationRestClient.cs | 38 +++++++++++++++++++ .../Network}/NetworkService.cs | 2 +- .../FirebaseNotificationService.cs | 16 ++++++++ .../Push/PushNotificationDelegate.cs | 31 +++++++++++++++ salesbook.Maui/GoogleService-Info.plist | 30 +++++++++++++++ salesbook.Maui/MauiProgram.cs | 11 ++++++ .../Platforms/Android/AndroidManifest.xml | 11 +++++- .../Platforms/Android/MainActivity.cs | 6 +++ salesbook.Maui/Platforms/iOS/Info.plist | 4 ++ salesbook.Maui/google-services.json | 29 ++++++++++++++ salesbook.Maui/salesbook.Maui.csproj | 12 ++++++ salesbook.Shared/Components/Pages/Home.razor | 10 +++++ .../Interface/IFirebaseNotificationService.cs | 6 +++ .../IIntegryNotificationRestClient.cs | 8 ++++ 16 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 salesbook.Maui/Core/RestClient/IntegryApi/Dto/RegisterDeviceDTO.cs create mode 100644 salesbook.Maui/Core/RestClient/IntegryApi/Dto/WtbUserDeviceTokenDTO.cs create mode 100644 salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs rename salesbook.Maui/Core/{Services => System/Network}/NetworkService.cs (82%) create mode 100644 salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs create mode 100644 salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs create mode 100644 salesbook.Maui/GoogleService-Info.plist create mode 100644 salesbook.Maui/google-services.json create mode 100644 salesbook.Shared/Core/Interface/IFirebaseNotificationService.cs create mode 100644 salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/Dto/RegisterDeviceDTO.cs b/salesbook.Maui/Core/RestClient/IntegryApi/Dto/RegisterDeviceDTO.cs new file mode 100644 index 0000000..fc7c01d --- /dev/null +++ b/salesbook.Maui/Core/RestClient/IntegryApi/Dto/RegisterDeviceDTO.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto; + +public class RegisterDeviceDTO +{ + [JsonPropertyName("userDeviceToken")] + public WtbUserDeviceTokenDTO UserDeviceToken { get; set; } + +} \ No newline at end of file diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/Dto/WtbUserDeviceTokenDTO.cs b/salesbook.Maui/Core/RestClient/IntegryApi/Dto/WtbUserDeviceTokenDTO.cs new file mode 100644 index 0000000..136bd4e --- /dev/null +++ b/salesbook.Maui/Core/RestClient/IntegryApi/Dto/WtbUserDeviceTokenDTO.cs @@ -0,0 +1,22 @@ +using System.Text.Json.Serialization; + +namespace salesbook.Maui.Core.RestClient.IntegryApi.Dto; + +public class WtbUserDeviceTokenDTO +{ + [JsonPropertyName("type")] + public string Type => "wtb_user_device_tokens"; + + [JsonPropertyName("deviceToken")] + public string DeviceToken { get; set; } + + [JsonPropertyName("userName")] + public string Username { get; set; } + + [JsonPropertyName("appName")] + public int AppName => 7; //salesbook + + [JsonPropertyName("platform")] + public string Platform { get; set; } + +} \ No newline at end of file diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs new file mode 100644 index 0000000..d18ff4c --- /dev/null +++ b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs @@ -0,0 +1,38 @@ +using IntegryApiClient.Core.Domain.Abstraction.Contracts.Account; +using IntegryApiClient.Core.Domain.RestClient.Contacts; +using Microsoft.Extensions.Logging; +using salesbook.Maui.Core.RestClient.IntegryApi.Dto; +using salesbook.Shared.Core.Interface; + +namespace salesbook.Maui.Core.RestClient.IntegryApi; + +public class IntegryNotificationRestClient( + ILogger logger, + IUserSession userSession, + IIntegryApiRestClient integryApiRestClient +) : IIntegryNotificationRestClient +{ + public async Task Register(string fcmToken, ILogger? logger1 = null) + { + logger1 ??= logger; + + var userDeviceToken = new RegisterDeviceDTO() + { + UserDeviceToken = new WtbUserDeviceTokenDTO() + { + DeviceToken = fcmToken, + Platform = OperatingSystem.IsAndroid() ? "Android" : "iOS", + Username = userSession.User.Username + } + }; + try + { + await integryApiRestClient.AuthorizedPost($"device_tokens/insert", userDeviceToken, + logger: logger1); + } + catch (Exception ex) + { + SentrySdk.CaptureException(ex); + } + } +} \ No newline at end of file diff --git a/salesbook.Maui/Core/Services/NetworkService.cs b/salesbook.Maui/Core/System/Network/NetworkService.cs similarity index 82% rename from salesbook.Maui/Core/Services/NetworkService.cs rename to salesbook.Maui/Core/System/Network/NetworkService.cs index 31a45b0..7fb8b96 100644 --- a/salesbook.Maui/Core/Services/NetworkService.cs +++ b/salesbook.Maui/Core/System/Network/NetworkService.cs @@ -1,6 +1,6 @@ using salesbook.Shared.Core.Interface; -namespace salesbook.Maui.Core.Services; +namespace salesbook.Maui.Core.System.Network; public class NetworkService : INetworkService { diff --git a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs new file mode 100644 index 0000000..e0b7c28 --- /dev/null +++ b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs @@ -0,0 +1,16 @@ +using salesbook.Shared.Core.Interface; +using Shiny; +using Shiny.Push; + +namespace salesbook.Maui.Core.System.Notification; + +public class FirebaseNotificationService(IPushManager pushManager, IIntegryNotificationRestClient integryNotificationRestClient) : IFirebaseNotificationService +{ + public async Task InitFirebase() + { + var (accessState, token) = await pushManager.RequestAccess(); + + if (accessState == AccessState.Denied || token is null) return; + await integryNotificationRestClient.Register(token); + } +} \ No newline at end of file diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs new file mode 100644 index 0000000..14cf03d --- /dev/null +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -0,0 +1,31 @@ +using Shiny.Push; + +namespace salesbook.Maui.Core.System.Notification.Push; + +public class PushNotificationDelegate : IPushDelegate +{ + public Task OnEntry(PushNotification notification) + { + // fires when the user taps on a push notification + return Task.CompletedTask; + } + + public Task OnReceived(PushNotification notification) + { + // fires when a push notification is received (silient or notification) + //notification.Data["content-available"] = "1"; + return Task.CompletedTask; + } + + public Task OnNewToken(string token) + { + // fires when a push notification change is set by the operating system or provider + return Task.CompletedTask; + } + + public Task OnUnRegistered(string token) + { + // fires when a push notification change is set by the operating system or provider + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/salesbook.Maui/GoogleService-Info.plist b/salesbook.Maui/GoogleService-Info.plist new file mode 100644 index 0000000..4ed039f --- /dev/null +++ b/salesbook.Maui/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyC_QtQpsVortjzgl-B7__IQZ-85lOct55E + GCM_SENDER_ID + 830771692001 + PLIST_VERSION + 1 + BUNDLE_ID + it.integry.salesbook + PROJECT_ID + salesbook-smetar + STORAGE_BUCKET + salesbook-smetar.firebasestorage.app + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:830771692001:ios:59d8b1d8570ac81f3752a0 + + \ No newline at end of file diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index 2b3aa2a..c4d0361 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -6,7 +6,11 @@ using Microsoft.AspNetCore.Components.Authorization; using Microsoft.Extensions.Logging; using MudBlazor.Services; using MudExtensions.Services; +using salesbook.Maui.Core.RestClient.IntegryApi; using salesbook.Maui.Core.Services; +using salesbook.Maui.Core.System.Network; +using salesbook.Maui.Core.System.Notification; +using salesbook.Maui.Core.System.Notification.Push; using salesbook.Shared; using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Helpers; @@ -16,6 +20,7 @@ using salesbook.Shared.Core.Messages.Activity.New; using salesbook.Shared.Core.Messages.Back; using salesbook.Shared.Core.Messages.Contact; using salesbook.Shared.Core.Services; +using Shiny; namespace salesbook.Maui { @@ -64,6 +69,12 @@ namespace salesbook.Maui builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); + + //Notification + builder.Services.AddNotifications(); + builder.Services.AddPush(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); diff --git a/salesbook.Maui/Platforms/Android/AndroidManifest.xml b/salesbook.Maui/Platforms/Android/AndroidManifest.xml index ddb278b..a8b23a0 100644 --- a/salesbook.Maui/Platforms/Android/AndroidManifest.xml +++ b/salesbook.Maui/Platforms/Android/AndroidManifest.xml @@ -1,6 +1,15 @@  - + + + + + + + + + + diff --git a/salesbook.Maui/Platforms/Android/MainActivity.cs b/salesbook.Maui/Platforms/Android/MainActivity.cs index 1c93fe9..75ed53c 100644 --- a/salesbook.Maui/Platforms/Android/MainActivity.cs +++ b/salesbook.Maui/Platforms/Android/MainActivity.cs @@ -7,6 +7,12 @@ namespace salesbook.Maui MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] + [IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction], + Categories = new[] + { + "android.intent.category.DEFAULT" + } + )] public class MainActivity : MauiAppCompatActivity { } diff --git a/salesbook.Maui/Platforms/iOS/Info.plist b/salesbook.Maui/Platforms/iOS/Info.plist index a094b3e..0c883a2 100644 --- a/salesbook.Maui/Platforms/iOS/Info.plist +++ b/salesbook.Maui/Platforms/iOS/Info.plist @@ -45,5 +45,9 @@ NSPhotoLibraryAddUsageDescription Permette all'app di salvare file o immagini nella tua libreria fotografica se necessario. + UIBackgroundModes + + remote-notification + diff --git a/salesbook.Maui/google-services.json b/salesbook.Maui/google-services.json new file mode 100644 index 0000000..ef98865 --- /dev/null +++ b/salesbook.Maui/google-services.json @@ -0,0 +1,29 @@ +{ + "project_info": { + "project_number": "830771692001", + "project_id": "salesbook-smetar", + "storage_bucket": "salesbook-smetar.firebasestorage.app" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:830771692001:android:06bc5a9706bc9bef3752a0", + "android_client_info": { + "package_name": "it.integry.salesbook" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyB43ai_Ph0phO_OkBC1wAOazKZUV9KsLaM" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/salesbook.Maui/salesbook.Maui.csproj b/salesbook.Maui/salesbook.Maui.csproj index 4c87907..3120900 100644 --- a/salesbook.Maui/salesbook.Maui.csproj +++ b/salesbook.Maui/salesbook.Maui.csproj @@ -93,6 +93,16 @@ --> + + + PreserveNewest + + + + + + + @@ -128,6 +138,8 @@ + + diff --git a/salesbook.Shared/Components/Pages/Home.razor b/salesbook.Shared/Components/Pages/Home.razor index 6e62825..190c941 100644 --- a/salesbook.Shared/Components/Pages/Home.razor +++ b/salesbook.Shared/Components/Pages/Home.razor @@ -4,6 +4,7 @@ @using salesbook.Shared.Components.Layout.Spinner @inject IFormFactor FormFactor @inject INetworkService NetworkService +@inject IFirebaseNotificationService FirebaseNotificationService @@ -11,6 +12,15 @@ { protected override async Task OnInitializedAsync() { + try + { + await FirebaseNotificationService.InitFirebase(); + } + catch (Exception e) + { + Console.WriteLine($"Firebase init: {e.Message}"); + } + var lastSyncDate = LocalStorage.Get("last-sync"); if (!FormFactor.IsWeb() && NetworkService.IsNetworkAvailable() && lastSyncDate.Equals(DateTime.MinValue)) diff --git a/salesbook.Shared/Core/Interface/IFirebaseNotificationService.cs b/salesbook.Shared/Core/Interface/IFirebaseNotificationService.cs new file mode 100644 index 0000000..47c6707 --- /dev/null +++ b/salesbook.Shared/Core/Interface/IFirebaseNotificationService.cs @@ -0,0 +1,6 @@ +namespace salesbook.Shared.Core.Interface; + +public interface IFirebaseNotificationService +{ + Task InitFirebase(); +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs b/salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs new file mode 100644 index 0000000..7eef3df --- /dev/null +++ b/salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs @@ -0,0 +1,8 @@ +using Microsoft.Extensions.Logging; + +namespace salesbook.Shared.Core.Interface; + +public interface IIntegryNotificationRestClient +{ + Task Register(string fcmToken, ILogger? logger1 = null); +} \ No newline at end of file From dfb86e3cd7895bf5844619fb752a347ee1409c0f Mon Sep 17 00:00:00 2001 From: MarcoE Date: Tue, 9 Sep 2025 11:43:07 +0200 Subject: [PATCH 2/4] Implementate notifiche --- .../IntegryNotificationRestClient.cs | 2 +- .../Core/Services/ManageDataService.cs | 2 + salesbook.Maui/Core/Services/SyncDbService.cs | 1 + .../Core/System/Network/NetworkService.cs | 1 + .../FirebaseNotificationService.cs | 25 +++- .../Notification/ShinyNotificationManager.cs | 9 ++ salesbook.Maui/MauiProgram.cs | 10 +- .../Platforms/Android/AndroidManifest.xml | 8 +- .../Platforms/Android/AndroidModule.cs | 13 +++ .../Core/BatteryOptimizationManagerService.cs | 28 +++++ .../Platforms/Android/MainActivity.cs | 33 +++++- .../Platforms/Android/MainApplication.cs | 22 ++-- salesbook.Maui/Platforms/iOS/AppDelegate.cs | 16 ++- .../Core/BatteryOptimizationManagerService.cs | 12 ++ .../Platforms/iOS/PrivacyInfo.xcprivacy | 110 ++++++++++++++++++ salesbook.Maui/Platforms/iOS/iOSModule.cs | 13 +++ salesbook.Maui/salesbook.Maui.csproj | 13 ++- .../Components/Layout/MainLayout.razor | 4 +- .../Components/Pages/Commessa.razor | 1 + salesbook.Shared/Components/Pages/Home.razor | 13 +++ salesbook.Shared/Components/Pages/Login.razor | 1 + .../Components/Pages/PersonalInfo.razor | 1 + salesbook.Shared/Components/Pages/User.razor | 1 + .../BottomSheet/SearchAddress.razor | 1 + .../SingleElements/Card/AttachCard.razor | 1 + .../SingleElements/Modal/ActivityForm.razor | 2 + .../SingleElements/Modal/ContactForm.razor | 2 + .../SingleElements/Modal/PersRifForm.razor | 2 + .../{ => IntegryApi}/IIntegryApiService.cs | 2 +- .../IIntegryNotificationRestClient.cs | 2 +- .../IBatteryOptimizationManagerService.cs | 8 ++ .../{ => System/Network}/INetworkService.cs | 2 +- .../Notification/IShinyNotificationManager.cs | 6 + .../Core/Services/IntegryApiService.cs | 1 + salesbook.Web/Core/Services/NetworkService.cs | 1 + salesbook.Web/Program.cs | 2 + 36 files changed, 338 insertions(+), 33 deletions(-) create mode 100644 salesbook.Maui/Core/System/Notification/ShinyNotificationManager.cs create mode 100644 salesbook.Maui/Platforms/Android/AndroidModule.cs create mode 100644 salesbook.Maui/Platforms/Android/Core/BatteryOptimizationManagerService.cs create mode 100644 salesbook.Maui/Platforms/iOS/Core/BatteryOptimizationManagerService.cs create mode 100644 salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy create mode 100644 salesbook.Maui/Platforms/iOS/iOSModule.cs rename salesbook.Shared/Core/Interface/{ => IntegryApi}/IIntegryApiService.cs (97%) rename salesbook.Shared/Core/Interface/{ => IntegryApi}/IIntegryNotificationRestClient.cs (73%) create mode 100644 salesbook.Shared/Core/Interface/System/Battery/IBatteryOptimizationManagerService.cs rename salesbook.Shared/Core/Interface/{ => System/Network}/INetworkService.cs (67%) create mode 100644 salesbook.Shared/Core/Interface/System/Notification/IShinyNotificationManager.cs diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs index d18ff4c..021fc6c 100644 --- a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs +++ b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs @@ -2,7 +2,7 @@ using IntegryApiClient.Core.Domain.RestClient.Contacts; using Microsoft.Extensions.Logging; using salesbook.Maui.Core.RestClient.IntegryApi.Dto; -using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.IntegryApi; namespace salesbook.Maui.Core.RestClient.IntegryApi; diff --git a/salesbook.Maui/Core/Services/ManageDataService.cs b/salesbook.Maui/Core/Services/ManageDataService.cs index 9b6dc26..9031c83 100644 --- a/salesbook.Maui/Core/Services/ManageDataService.cs +++ b/salesbook.Maui/Core/Services/ManageDataService.cs @@ -7,6 +7,8 @@ using salesbook.Shared.Core.Helpers.Enum; using salesbook.Shared.Core.Interface; using Sentry.Protocol; using System.Linq.Expressions; +using salesbook.Shared.Core.Interface.IntegryApi; +using salesbook.Shared.Core.Interface.System.Network; namespace salesbook.Maui.Core.Services; diff --git a/salesbook.Maui/Core/Services/SyncDbService.cs b/salesbook.Maui/Core/Services/SyncDbService.cs index d5c55bb..795f99a 100644 --- a/salesbook.Maui/Core/Services/SyncDbService.cs +++ b/salesbook.Maui/Core/Services/SyncDbService.cs @@ -1,5 +1,6 @@ using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.IntegryApi; namespace salesbook.Maui.Core.Services; diff --git a/salesbook.Maui/Core/System/Network/NetworkService.cs b/salesbook.Maui/Core/System/Network/NetworkService.cs index 124578a..af1da33 100644 --- a/salesbook.Maui/Core/System/Network/NetworkService.cs +++ b/salesbook.Maui/Core/System/Network/NetworkService.cs @@ -1,4 +1,5 @@ using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.System.Network; namespace salesbook.Maui.Core.System.Network; diff --git a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs index e0b7c28..2f766eb 100644 --- a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs +++ b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs @@ -1,16 +1,37 @@ using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.IntegryApi; using Shiny; +using Shiny.Notifications; using Shiny.Push; namespace salesbook.Maui.Core.System.Notification; -public class FirebaseNotificationService(IPushManager pushManager, IIntegryNotificationRestClient integryNotificationRestClient) : IFirebaseNotificationService +public class FirebaseNotificationService( + IPushManager pushManager, + IIntegryNotificationRestClient integryNotificationRestClient, + INotificationManager notificationManager +) : IFirebaseNotificationService { public async Task InitFirebase() { - var (accessState, token) = await pushManager.RequestAccess(); + CreateNotificationChannel(); + var (accessState, token) = await pushManager.RequestAccess(); + if (accessState == AccessState.Denied || token is null) return; await integryNotificationRestClient.Register(token); } + + private void CreateNotificationChannel() + { + var channel = new Channel + { + Identifier = "salesbook_push", + Description = "Notifiche push di SalesBook", + Importance = ChannelImportance.High, + Actions = [] + }; + + notificationManager.AddChannel(channel); + } } \ No newline at end of file diff --git a/salesbook.Maui/Core/System/Notification/ShinyNotificationManager.cs b/salesbook.Maui/Core/System/Notification/ShinyNotificationManager.cs new file mode 100644 index 0000000..ab1ce6b --- /dev/null +++ b/salesbook.Maui/Core/System/Notification/ShinyNotificationManager.cs @@ -0,0 +1,9 @@ +using salesbook.Shared.Core.Interface.System.Notification; +using Shiny.Notifications; + +namespace salesbook.Maui.Core.System.Notification; + +public class ShinyNotificationManager(INotificationManager notificationManager) : IShinyNotificationManager +{ + public Task RequestAccess() => notificationManager.RequestAccess(); +} \ No newline at end of file diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index d565c99..1743cbf 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -1,4 +1,3 @@ -using AutoMapper; using CommunityToolkit.Maui; using CommunityToolkit.Mvvm.Messaging; using IntegryApiClient.MAUI; @@ -16,6 +15,9 @@ using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Dto.PageState; using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.IntegryApi; +using salesbook.Shared.Core.Interface.System.Network; +using salesbook.Shared.Core.Interface.System.Notification; using salesbook.Shared.Core.Messages.Activity.Copy; using salesbook.Shared.Core.Messages.Activity.New; using salesbook.Shared.Core.Messages.Back; @@ -29,7 +31,7 @@ namespace salesbook.Maui { private const string AppToken = "f0484398-1f8b-42f5-ab79-5282c164e1d8"; - public static MauiApp CreateMauiApp() + public static MauiAppBuilder CreateMauiAppBuilder() { InteractiveRenderSettings.ConfigureBlazorHybridRenderModes(); @@ -38,6 +40,7 @@ namespace salesbook.Maui .UseMauiApp() .UseIntegry(appToken: AppToken, useLoginAzienda: true) .UseMauiCommunityToolkit() + .UseShiny() .UseSentry(options => { options.Dsn = "https://453b6b38f94fd67e40e0d5306d6caff8@o4508499810254848.ingest.de.sentry.io/4509605099667536"; @@ -82,6 +85,7 @@ namespace salesbook.Maui builder.Services.AddPush(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); @@ -93,7 +97,7 @@ namespace salesbook.Maui builder.Services.AddSingleton(); builder.Services.AddSingleton(); - return builder.Build(); + return builder; } } } \ No newline at end of file diff --git a/salesbook.Maui/Platforms/Android/AndroidManifest.xml b/salesbook.Maui/Platforms/Android/AndroidManifest.xml index a8b23a0..e38ccd8 100644 --- a/salesbook.Maui/Platforms/Android/AndroidManifest.xml +++ b/salesbook.Maui/Platforms/Android/AndroidManifest.xml @@ -1,5 +1,5 @@  - + @@ -15,4 +15,10 @@ + + + + + + \ No newline at end of file diff --git a/salesbook.Maui/Platforms/Android/AndroidModule.cs b/salesbook.Maui/Platforms/Android/AndroidModule.cs new file mode 100644 index 0000000..19ab9b1 --- /dev/null +++ b/salesbook.Maui/Platforms/Android/AndroidModule.cs @@ -0,0 +1,13 @@ +using salesbook.Maui.Core; +using salesbook.Shared.Core.Interface.System.Battery; + +namespace salesbook.Maui; + +public static class AndroidModule +{ + public static MauiAppBuilder RegisterAndroidAppServices(this MauiAppBuilder mauiAppBuilder) + { + mauiAppBuilder.Services.AddSingleton(); + return mauiAppBuilder; + } +} \ No newline at end of file diff --git a/salesbook.Maui/Platforms/Android/Core/BatteryOptimizationManagerService.cs b/salesbook.Maui/Platforms/Android/Core/BatteryOptimizationManagerService.cs new file mode 100644 index 0000000..4e1f3ff --- /dev/null +++ b/salesbook.Maui/Platforms/Android/Core/BatteryOptimizationManagerService.cs @@ -0,0 +1,28 @@ +using Android.App; +using Android.Content; +using Android.OS; +using Android.Provider; +using salesbook.Shared.Core.Interface.System.Battery; +using Application = Android.App.Application; + +namespace salesbook.Maui.Core; + +public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService +{ + public bool IsBatteryOptimizationEnabled() + { + var packageName = AppInfo.PackageName; + + var pm = (PowerManager)Application.Context.GetSystemService(Context.PowerService)!; + return !pm.IsIgnoringBatteryOptimizations(packageName); + } + + public void OpenBatteryOptimizationSettings(Action onCompleted) + { + var packageName = AppInfo.PackageName; + + var intent = new Intent(Settings.ActionRequestIgnoreBatteryOptimizations); + intent.SetData(Android.Net.Uri.Parse("package:" + packageName)); + ((MainActivity)Platform.CurrentActivity!).StartActivityForResult(intent, (result, _) => { onCompleted(result == Result.Ok); }); + } +} \ No newline at end of file diff --git a/salesbook.Maui/Platforms/Android/MainActivity.cs b/salesbook.Maui/Platforms/Android/MainActivity.cs index 75ed53c..dbc05ea 100644 --- a/salesbook.Maui/Platforms/Android/MainActivity.cs +++ b/salesbook.Maui/Platforms/Android/MainActivity.cs @@ -1,19 +1,42 @@ using Android.App; +using Android.Content; using Android.Content.PM; namespace salesbook.Maui { - [Activity(Theme = "@style/Maui.SplashTheme", + [Activity( + Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] - [IntentFilter([Shiny.ShinyPushIntents.NotificationClickAction], - Categories = new[] - { + + [IntentFilter( + [ + Shiny.ShinyPushIntents.NotificationClickAction + ], + Categories = + [ "android.intent.category.DEFAULT" - } + ] )] public class MainActivity : MauiAppCompatActivity { + private readonly IDictionary> _onActivityResultSubscriber = + new Dictionary>(); + + public void StartActivityForResult(Intent intent, Action onResultAction) + { + var requestCode = new Random(DateTime.Now.Millisecond).Next(); + _onActivityResultSubscriber.Add(requestCode, onResultAction); + StartActivityForResult(intent, requestCode); + } + + protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) + { + if (_onActivityResultSubscriber.TryGetValue(requestCode, out var value)) + value(resultCode, data); + + base.OnActivityResult(requestCode, resultCode, data); + } } } \ No newline at end of file diff --git a/salesbook.Maui/Platforms/Android/MainApplication.cs b/salesbook.Maui/Platforms/Android/MainApplication.cs index 2820e44..ff3db19 100644 --- a/salesbook.Maui/Platforms/Android/MainApplication.cs +++ b/salesbook.Maui/Platforms/Android/MainApplication.cs @@ -1,16 +1,16 @@ using Android.App; using Android.Runtime; -namespace salesbook.Maui -{ - [Application(HardwareAccelerated = true)] - public class MainApplication : MauiApplication - { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } +namespace salesbook.Maui; - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); +[Application(HardwareAccelerated = true)] +public class MainApplication : MauiApplication +{ + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { } -} + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder() + .RegisterAndroidAppServices().Build(); +} \ No newline at end of file diff --git a/salesbook.Maui/Platforms/iOS/AppDelegate.cs b/salesbook.Maui/Platforms/iOS/AppDelegate.cs index 57062da..0728e77 100644 --- a/salesbook.Maui/Platforms/iOS/AppDelegate.cs +++ b/salesbook.Maui/Platforms/iOS/AppDelegate.cs @@ -1,10 +1,24 @@ using Foundation; +using UIKit; namespace salesbook.Maui { [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate { - protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiAppBuilder() + .RegisterIosAppServices().Build(); + + [Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")] + public void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) + => global::Shiny.Hosting.Host.Lifecycle.OnRegisteredForRemoteNotifications(deviceToken); + + [Export("application:didFailToRegisterForRemoteNotificationsWithError:")] + public void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error) + => global::Shiny.Hosting.Host.Lifecycle.OnFailedToRegisterForRemoteNotifications(error); + + [Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")] + public void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler) + => global::Shiny.Hosting.Host.Lifecycle.OnDidReceiveRemoteNotification(userInfo, completionHandler); } } diff --git a/salesbook.Maui/Platforms/iOS/Core/BatteryOptimizationManagerService.cs b/salesbook.Maui/Platforms/iOS/Core/BatteryOptimizationManagerService.cs new file mode 100644 index 0000000..3f9400d --- /dev/null +++ b/salesbook.Maui/Platforms/iOS/Core/BatteryOptimizationManagerService.cs @@ -0,0 +1,12 @@ +using salesbook.Shared.Core.Interface.System.Battery; + +namespace salesbook.Maui.Core; + +public class BatteryOptimizationManagerService : IBatteryOptimizationManagerService +{ + public bool IsBatteryOptimizationEnabled() => true; + + public void OpenBatteryOptimizationSettings(Action onCompleted) + { + } +} \ No newline at end of file diff --git a/salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy b/salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy new file mode 100644 index 0000000..fcd26e7 --- /dev/null +++ b/salesbook.Maui/Platforms/iOS/PrivacyInfo.xcprivacy @@ -0,0 +1,110 @@ + + + + + + NSPrivacyAccessedAPITypes + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryFileTimestamp + NSPrivacyAccessedAPITypeReasons + + C617.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategorySystemBootTime + NSPrivacyAccessedAPITypeReasons + + 35F9.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryDiskSpace + NSPrivacyAccessedAPITypeReasons + + E174.1 + + + + NSPrivacyAccessedAPIType + NSPrivacyAccessedAPICategoryUserDefaults + NSPrivacyAccessedAPITypeReasons + + CA92.1 + + + + NSPrivacyCollectedDataTypes + + + + NSPrivacyCollectedDataTypeUserID + NSPrivacyCollectedDataTypeLocation + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + NSPrivacyCollectedDataTypeEmailAddress + NSPrivacyCollectedDataTypeLocation + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + NSPrivacyCollectedDataTypePhoneNumber + NSPrivacyCollectedDataTypeLocation + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + + + NSPrivacyCollectedDataType + NSPrivacyCollectedDataTypeOtherDiagnosticData + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + NSPrivacyCollectedDataType + NSPrivacyCollectedDataTypeCrashData + NSPrivacyCollectedDataTypeLinked + + NSPrivacyCollectedDataTypeTracking + + NSPrivacyCollectedDataTypePurposes + + NSPrivacyCollectedDataTypePurposeAppFunctionality + + + + + + + diff --git a/salesbook.Maui/Platforms/iOS/iOSModule.cs b/salesbook.Maui/Platforms/iOS/iOSModule.cs new file mode 100644 index 0000000..071675e --- /dev/null +++ b/salesbook.Maui/Platforms/iOS/iOSModule.cs @@ -0,0 +1,13 @@ +using salesbook.Maui.Core; +using salesbook.Shared.Core.Interface.System.Battery; + +namespace salesbook.Maui; + +public static class iOSModule +{ + public static MauiAppBuilder RegisterIosAppServices(this MauiAppBuilder mauiAppBuilder) + { + mauiAppBuilder.Services.AddSingleton(); + return mauiAppBuilder; + } +} \ No newline at end of file diff --git a/salesbook.Maui/salesbook.Maui.csproj b/salesbook.Maui/salesbook.Maui.csproj index 3120900..fb9eb60 100644 --- a/salesbook.Maui/salesbook.Maui.csproj +++ b/salesbook.Maui/salesbook.Maui.csproj @@ -83,14 +83,16 @@ manual - + - --> + + + @@ -138,6 +140,7 @@ + diff --git a/salesbook.Shared/Components/Layout/MainLayout.razor b/salesbook.Shared/Components/Layout/MainLayout.razor index dc8d62b..514030f 100644 --- a/salesbook.Shared/Components/Layout/MainLayout.razor +++ b/salesbook.Shared/Components/Layout/MainLayout.razor @@ -1,5 +1,7 @@ @using System.Globalization @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.IntegryApi +@using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Messages.Back @inherits LayoutComponentBase @inject IJSRuntime JS @@ -55,7 +57,7 @@ private bool _showWarning; private DateTime _lastApiCheck = DateTime.MinValue; - private const int DelaySeconds = 60; + private const int DelaySeconds = 180; private CancellationTokenSource? _cts; diff --git a/salesbook.Shared/Components/Pages/Commessa.razor b/salesbook.Shared/Components/Pages/Commessa.razor index 24d8b14..829abce 100644 --- a/salesbook.Shared/Components/Pages/Commessa.razor +++ b/salesbook.Shared/Components/Pages/Commessa.razor @@ -11,6 +11,7 @@ @using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.IntegryApi @inject JobSteps JobSteps @inject IManageDataService ManageData @inject IIntegryApiService IntegryApiService diff --git a/salesbook.Shared/Components/Pages/Home.razor b/salesbook.Shared/Components/Pages/Home.razor index c39cdd5..aadb903 100644 --- a/salesbook.Shared/Components/Pages/Home.razor +++ b/salesbook.Shared/Components/Pages/Home.razor @@ -2,10 +2,13 @@ @attribute [Authorize] @using salesbook.Shared.Core.Interface @using salesbook.Shared.Components.Layout.Spinner +@using salesbook.Shared.Core.Interface.System.Network +@using salesbook.Shared.Core.Interface.System.Notification @using salesbook.Shared.Core.Services @inject IFormFactor FormFactor @inject INetworkService NetworkService @inject IFirebaseNotificationService FirebaseNotificationService +@inject IShinyNotificationManager NotificationManager @inject PreloadService PreloadService @@ -14,6 +17,8 @@ { protected override async Task OnInitializedAsync() { + await CheckAndRequestPermissions(); + try { await FirebaseNotificationService.InitFirebase(); @@ -35,6 +40,14 @@ NavigationManager.NavigateTo("/Calendar"); } + private async Task CheckAndRequestPermissions() + { + await NotificationManager.RequestAccess(); + + // if (BatteryOptimizationManagerService.IsBatteryOptimizationEnabled()) + // BatteryOptimizationManagerService.OpenBatteryOptimizationSettings(_ => { }); + } + private Task StartSyncUser() { return Task.Run(() => diff --git a/salesbook.Shared/Components/Pages/Login.razor b/salesbook.Shared/Components/Pages/Login.razor index baafd52..bbf2048 100644 --- a/salesbook.Shared/Components/Pages/Login.razor +++ b/salesbook.Shared/Components/Pages/Login.razor @@ -1,6 +1,7 @@ @page "/login" @using salesbook.Shared.Components.Layout.Spinner @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Services @inject IUserAccountService UserAccountService @inject AppAuthenticationStateProvider AuthenticationStateProvider diff --git a/salesbook.Shared/Components/Pages/PersonalInfo.razor b/salesbook.Shared/Components/Pages/PersonalInfo.razor index 036fcbf..8ac584b 100644 --- a/salesbook.Shared/Components/Pages/PersonalInfo.razor +++ b/salesbook.Shared/Components/Pages/PersonalInfo.razor @@ -3,6 +3,7 @@ @using salesbook.Shared.Components.Layout @using salesbook.Shared.Core.Authorization.Enum @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Services @inject AppAuthenticationStateProvider AuthenticationStateProvider @inject INetworkService NetworkService diff --git a/salesbook.Shared/Components/Pages/User.razor b/salesbook.Shared/Components/Pages/User.razor index 0da73a8..aff2c4d 100644 --- a/salesbook.Shared/Components/Pages/User.razor +++ b/salesbook.Shared/Components/Pages/User.razor @@ -10,6 +10,7 @@ @using salesbook.Shared.Core.Dto.Activity @using salesbook.Shared.Core.Dto.JobProgress @using salesbook.Shared.Core.Dto.PageState +@using salesbook.Shared.Core.Interface.IntegryApi @implements IAsyncDisposable @inject IManageDataService ManageData @inject IMapper Mapper diff --git a/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor index 44a29f7..c6f0b7b 100644 --- a/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor +++ b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor @@ -2,6 +2,7 @@ @using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Interface @using salesbook.Shared.Components.Layout.Overlay +@using salesbook.Shared.Core.Interface.IntegryApi @inject IIntegryApiService IntegryApiService
diff --git a/salesbook.Shared/Components/SingleElements/Card/AttachCard.razor b/salesbook.Shared/Components/SingleElements/Card/AttachCard.razor index 26d27a8..3d0d085 100644 --- a/salesbook.Shared/Components/SingleElements/Card/AttachCard.razor +++ b/salesbook.Shared/Components/SingleElements/Card/AttachCard.razor @@ -1,5 +1,6 @@ @using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.IntegryApi @inject IIntegryApiService IntegryApiService @inject IAttachedService AttachedService diff --git a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor index 352cdc7..7e5a8af 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ActivityForm.razor @@ -9,6 +9,8 @@ @using salesbook.Shared.Core.Dto.Contact @using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Interface +@using salesbook.Shared.Core.Interface.IntegryApi +@using salesbook.Shared.Core.Interface.System.Network @using salesbook.Shared.Core.Messages.Activity.Copy @inject IManageDataService ManageData @inject INetworkService NetworkService diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor index 8b6ffbd..46f9fa9 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor @@ -5,6 +5,8 @@ @using salesbook.Shared.Core.Entity @using salesbook.Shared.Components.SingleElements.BottomSheet @using salesbook.Shared.Core.Dto.Contact +@using salesbook.Shared.Core.Interface.IntegryApi +@using salesbook.Shared.Core.Interface.System.Network @inject IManageDataService ManageData @inject INetworkService NetworkService @inject IIntegryApiService IntegryApiService diff --git a/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor b/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor index 3e107ae..c3813b2 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/PersRifForm.razor @@ -2,6 +2,8 @@ @using salesbook.Shared.Components.Layout @using salesbook.Shared.Core.Interface @using salesbook.Shared.Components.Layout.Overlay +@using salesbook.Shared.Core.Interface.IntegryApi +@using salesbook.Shared.Core.Interface.System.Network @inject IManageDataService ManageData @inject INetworkService NetworkService @inject IIntegryApiService IntegryApiService diff --git a/salesbook.Shared/Core/Interface/IIntegryApiService.cs b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryApiService.cs similarity index 97% rename from salesbook.Shared/Core/Interface/IIntegryApiService.cs rename to salesbook.Shared/Core/Interface/IntegryApi/IIntegryApiService.cs index a8fdc7d..1cd51af 100644 --- a/salesbook.Shared/Core/Interface/IIntegryApiService.cs +++ b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryApiService.cs @@ -4,7 +4,7 @@ using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Dto.JobProgress; using salesbook.Shared.Core.Entity; -namespace salesbook.Shared.Core.Interface; +namespace salesbook.Shared.Core.Interface.IntegryApi; public interface IIntegryApiService { diff --git a/salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs similarity index 73% rename from salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs rename to salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs index 7eef3df..27de9c7 100644 --- a/salesbook.Shared/Core/Interface/IIntegryNotificationRestClient.cs +++ b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace salesbook.Shared.Core.Interface; +namespace salesbook.Shared.Core.Interface.IntegryApi; public interface IIntegryNotificationRestClient { diff --git a/salesbook.Shared/Core/Interface/System/Battery/IBatteryOptimizationManagerService.cs b/salesbook.Shared/Core/Interface/System/Battery/IBatteryOptimizationManagerService.cs new file mode 100644 index 0000000..179f1ac --- /dev/null +++ b/salesbook.Shared/Core/Interface/System/Battery/IBatteryOptimizationManagerService.cs @@ -0,0 +1,8 @@ +namespace salesbook.Shared.Core.Interface.System.Battery; + +public interface IBatteryOptimizationManagerService +{ + bool IsBatteryOptimizationEnabled(); + + void OpenBatteryOptimizationSettings(Action onCompleted); +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Interface/INetworkService.cs b/salesbook.Shared/Core/Interface/System/Network/INetworkService.cs similarity index 67% rename from salesbook.Shared/Core/Interface/INetworkService.cs rename to salesbook.Shared/Core/Interface/System/Network/INetworkService.cs index 1bec94c..43b6acc 100644 --- a/salesbook.Shared/Core/Interface/INetworkService.cs +++ b/salesbook.Shared/Core/Interface/System/Network/INetworkService.cs @@ -1,4 +1,4 @@ -namespace salesbook.Shared.Core.Interface; +namespace salesbook.Shared.Core.Interface.System.Network; public interface INetworkService { diff --git a/salesbook.Shared/Core/Interface/System/Notification/IShinyNotificationManager.cs b/salesbook.Shared/Core/Interface/System/Notification/IShinyNotificationManager.cs new file mode 100644 index 0000000..ec8454b --- /dev/null +++ b/salesbook.Shared/Core/Interface/System/Notification/IShinyNotificationManager.cs @@ -0,0 +1,6 @@ +namespace salesbook.Shared.Core.Interface.System.Notification; + +public interface IShinyNotificationManager +{ + Task RequestAccess(); +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Services/IntegryApiService.cs b/salesbook.Shared/Core/Services/IntegryApiService.cs index c138b68..4a3d943 100644 --- a/salesbook.Shared/Core/Services/IntegryApiService.cs +++ b/salesbook.Shared/Core/Services/IntegryApiService.cs @@ -7,6 +7,7 @@ using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Interface; using System.Net.Http.Headers; using salesbook.Shared.Core.Dto.Contact; +using salesbook.Shared.Core.Interface.IntegryApi; namespace salesbook.Shared.Core.Services; diff --git a/salesbook.Web/Core/Services/NetworkService.cs b/salesbook.Web/Core/Services/NetworkService.cs index 64b4044..16d9938 100644 --- a/salesbook.Web/Core/Services/NetworkService.cs +++ b/salesbook.Web/Core/Services/NetworkService.cs @@ -1,4 +1,5 @@ using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.System.Network; namespace salesbook.Web.Core.Services; diff --git a/salesbook.Web/Program.cs b/salesbook.Web/Program.cs index cbb65dc..fc2b24a 100644 --- a/salesbook.Web/Program.cs +++ b/salesbook.Web/Program.cs @@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Components.WebAssembly.Hosting; using MudBlazor.Services; using salesbook.Shared.Components; using salesbook.Shared.Core.Interface; +using salesbook.Shared.Core.Interface.IntegryApi; +using salesbook.Shared.Core.Interface.System.Network; using salesbook.Shared.Core.Services; using salesbook.Web.Core.Services; From 7319378e758750afafce80dadee893895f22a8ea Mon Sep 17 00:00:00 2001 From: MarcoE Date: Tue, 9 Sep 2025 16:30:51 +0200 Subject: [PATCH 3/4] Creata card notifiche --- .../Push/PushNotificationDelegate.cs | 24 ++++-- salesbook.Maui/MauiProgram.cs | 13 +-- salesbook.Maui/wwwroot/index.html | 1 + .../Components/Layout/NavMenu.razor | 28 ++++-- .../Components/Pages/Notifications.razor | 34 +++++++- .../Components/Pages/Notifications.razor.css | 6 ++ .../Card/NotificationCard.razor | 15 ++++ .../Card/NotificationCard.razor.css | 64 ++++++++++++++ .../Dto/Notification/PushNotificationDTO.cs | 9 ++ .../Core/Dto/PageState/NotificationState.cs | 8 ++ .../NewPushNotificationMessage.cs | 6 ++ .../NewPushNotificationService.cs | 14 +++ salesbook.Shared/wwwroot/js/notifications.js | 85 +++++++++++++++++++ 13 files changed, 289 insertions(+), 18 deletions(-) create mode 100644 salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor create mode 100644 salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css create mode 100644 salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs create mode 100644 salesbook.Shared/Core/Dto/PageState/NotificationState.cs create mode 100644 salesbook.Shared/Core/Messages/Notification/NewPushNotificationMessage.cs create mode 100644 salesbook.Shared/Core/Messages/Notification/NewPushNotificationService.cs create mode 100644 salesbook.Shared/wwwroot/js/notifications.js diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs index 14cf03d..8e69c40 100644 --- a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -1,8 +1,15 @@ -using Shiny.Push; +using CommunityToolkit.Mvvm.Messaging; +using salesbook.Shared.Core.Dto.Notification; +using salesbook.Shared.Core.Interface.IntegryApi; +using salesbook.Shared.Core.Messages.Notification; +using Shiny.Push; namespace salesbook.Maui.Core.System.Notification.Push; -public class PushNotificationDelegate : IPushDelegate +public class PushNotificationDelegate( + IIntegryNotificationRestClient integryNotificationRestClient, + IMessenger messenger +) : IPushDelegate { public Task OnEntry(PushNotification notification) { @@ -12,14 +19,21 @@ public class PushNotificationDelegate : IPushDelegate public Task OnReceived(PushNotification notification) { - // fires when a push notification is received (silient or notification) - //notification.Data["content-available"] = "1"; + if (notification.Notification is null) return Task.CompletedTask; + var pushNotification = new PushNotificationDTO + { + Title = notification.Notification.Title, + Message = notification.Notification.Message + }; + + messenger.Send(new NewPushNotificationMessage(pushNotification)); + return Task.CompletedTask; } public Task OnNewToken(string token) { - // fires when a push notification change is set by the operating system or provider + integryNotificationRestClient.Register(token); return Task.CompletedTask; } diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index 1743cbf..c9c7290 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -22,6 +22,7 @@ using salesbook.Shared.Core.Messages.Activity.Copy; using salesbook.Shared.Core.Messages.Activity.New; using salesbook.Shared.Core.Messages.Back; using salesbook.Shared.Core.Messages.Contact; +using salesbook.Shared.Core.Messages.Notification; using salesbook.Shared.Core.Services; using Shiny; @@ -71,14 +72,16 @@ namespace salesbook.Maui builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); //Message - builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); //Notification builder.Services.AddNotifications(); diff --git a/salesbook.Maui/wwwroot/index.html b/salesbook.Maui/wwwroot/index.html index 74faadd..7f7b15f 100644 --- a/salesbook.Maui/wwwroot/index.html +++ b/salesbook.Maui/wwwroot/index.html @@ -53,6 +53,7 @@ + diff --git a/salesbook.Shared/Components/Layout/NavMenu.razor b/salesbook.Shared/Components/Layout/NavMenu.razor index a4cdf53..6880a7d 100644 --- a/salesbook.Shared/Components/Layout/NavMenu.razor +++ b/salesbook.Shared/Components/Layout/NavMenu.razor @@ -1,13 +1,18 @@ @using CommunityToolkit.Mvvm.Messaging @using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto.Activity +@using salesbook.Shared.Core.Dto.Notification +@using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Messages.Activity.Copy @using salesbook.Shared.Core.Messages.Activity.New @using salesbook.Shared.Core.Messages.Contact +@using salesbook.Shared.Core.Messages.Notification @inject IDialogService Dialog @inject IMessenger Messenger @inject CopyActivityService CopyActivityService +@inject NewPushNotificationService NewPushNotificationService +@inject NotificationState Notification
@@ -63,8 +70,9 @@ protected override Task OnInitializedAsync() { CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto); + NewPushNotificationService.OnNotificationReceived += NewNotificationReceived; - NavigationManager.LocationChanged += (_, args) => + NavigationManager.LocationChanged += (_, args) => { var location = args.Location.Remove(0, NavigationManager.BaseUri.Length); @@ -104,4 +112,10 @@ Messenger.Send(new NewContactMessage((CRMCreateContactResponseDTO)result.Data)); } } + + private void NewNotificationReceived(PushNotificationDTO notification) + { + Notification.UnreadNotifications.Add(notification); + InvokeAsync(StateHasChanged); + } } \ No newline at end of file diff --git a/salesbook.Shared/Components/Pages/Notifications.razor b/salesbook.Shared/Components/Pages/Notifications.razor index 9579556..494a3d4 100644 --- a/salesbook.Shared/Components/Pages/Notifications.razor +++ b/salesbook.Shared/Components/Pages/Notifications.razor @@ -2,13 +2,45 @@ @attribute [Authorize] @using salesbook.Shared.Components.Layout @using salesbook.Shared.Components.SingleElements +@using salesbook.Shared.Core.Dto.Notification +@using salesbook.Shared.Core.Dto.PageState +@using salesbook.Shared.Core.Messages.Notification +@inject NotificationState Notification +@inject NewPushNotificationService NewPushNotificationService +@inject IJSRuntime JS
- + @if (Notification.UnreadNotifications.IsNullOrEmpty()) + { + + } + else + { +
+ @foreach(var notification in Notification.UnreadNotifications) + { + + } +
+ }
@code { + protected override Task OnInitializedAsync() + { + NewPushNotificationService.OnNotificationReceived += NewNotificationReceived; + return Task.CompletedTask; + } + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await JS.InvokeVoidAsync("initNotifications"); + } + + private void NewNotificationReceived(PushNotificationDTO notification) + { + InvokeAsync(StateHasChanged); + } } \ No newline at end of file diff --git a/salesbook.Shared/Components/Pages/Notifications.razor.css b/salesbook.Shared/Components/Pages/Notifications.razor.css index e69de29..6f08dcd 100644 --- a/salesbook.Shared/Components/Pages/Notifications.razor.css +++ b/salesbook.Shared/Components/Pages/Notifications.razor.css @@ -0,0 +1,6 @@ +.list { + display: flex; + flex-direction: column; + align-items: center; + gap: 12px; +} diff --git a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor new file mode 100644 index 0000000..873e9f7 --- /dev/null +++ b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor @@ -0,0 +1,15 @@ +@using salesbook.Shared.Core.Dto.Notification + +
+
+
+
+
@Notification.Title
+
@Notification.Message
+
+
+
+ +@code { + [Parameter] public PushNotificationDTO Notification { get; set; } = new(); +} \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css new file mode 100644 index 0000000..2c63bb0 --- /dev/null +++ b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css @@ -0,0 +1,64 @@ +.row { + position: relative; + overflow: hidden; + border-radius: var(--mud-default-borderradius); + box-shadow: var(--custom-box-shadow); + width: 100%; +} + +.behind { + position: absolute; + inset: 0; + display: flex; + justify-content: flex-end; + align-items: center; + padding-right: 14px; + background: var(--mud-palette-error); + z-index: 0; +} + +.trash-btn { + color: white; + padding: 10px 15px; + cursor: pointer; +} + +.notification-card { + position: relative; + z-index: 1; + display: flex; + align-items: center; + padding: 12px; + background: var(--mud-palette-background); + transition: transform .2s ease; + touch-action: pan-y; + will-change: transform; + transform: translateX(0); +} + +.avatar { + width: 42px; + height: 42px; + border-radius: 12px; + display: grid; + place-items: center; + background: #0b1220; + border: 1px solid #1f2937; + font-weight: bold; + color: #22d3ee; +} + +.title { + font-weight: 700; + margin-bottom: unset !important; +} + +.subtitle { + font-size: 13px; + color: #94a3b8; +} + +.collapsing { + transition: height .22s ease, margin .22s ease, opacity .22s ease; + overflow: hidden; +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs b/salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs new file mode 100644 index 0000000..91de6df --- /dev/null +++ b/salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs @@ -0,0 +1,9 @@ +namespace salesbook.Shared.Core.Dto.Notification; + +public class PushNotificationDTO +{ + public string? Title { get; set; } + public string? Message { get; set; } + + public DateTime Hours => DateTime.Now; +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/PageState/NotificationState.cs b/salesbook.Shared/Core/Dto/PageState/NotificationState.cs new file mode 100644 index 0000000..cfaf940 --- /dev/null +++ b/salesbook.Shared/Core/Dto/PageState/NotificationState.cs @@ -0,0 +1,8 @@ +using salesbook.Shared.Core.Dto.Notification; + +namespace salesbook.Shared.Core.Dto.PageState; + +public class NotificationState +{ + public List UnreadNotifications { get; set; } = []; +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Messages/Notification/NewPushNotificationMessage.cs b/salesbook.Shared/Core/Messages/Notification/NewPushNotificationMessage.cs new file mode 100644 index 0000000..ff48cec --- /dev/null +++ b/salesbook.Shared/Core/Messages/Notification/NewPushNotificationMessage.cs @@ -0,0 +1,6 @@ +using CommunityToolkit.Mvvm.Messaging.Messages; +using salesbook.Shared.Core.Dto.Notification; + +namespace salesbook.Shared.Core.Messages.Notification; + +public class NewPushNotificationMessage(PushNotificationDTO value) : ValueChangedMessage(value); \ No newline at end of file diff --git a/salesbook.Shared/Core/Messages/Notification/NewPushNotificationService.cs b/salesbook.Shared/Core/Messages/Notification/NewPushNotificationService.cs new file mode 100644 index 0000000..e863668 --- /dev/null +++ b/salesbook.Shared/Core/Messages/Notification/NewPushNotificationService.cs @@ -0,0 +1,14 @@ +using CommunityToolkit.Mvvm.Messaging; +using salesbook.Shared.Core.Dto.Notification; + +namespace salesbook.Shared.Core.Messages.Notification; + +public class NewPushNotificationService +{ + public event Action? OnNotificationReceived; + + public NewPushNotificationService(IMessenger messenger) + { + messenger.Register(this, (_, o) => { OnNotificationReceived?.Invoke(o.Value); }); + } +} \ No newline at end of file diff --git a/salesbook.Shared/wwwroot/js/notifications.js b/salesbook.Shared/wwwroot/js/notifications.js new file mode 100644 index 0000000..f38633c --- /dev/null +++ b/salesbook.Shared/wwwroot/js/notifications.js @@ -0,0 +1,85 @@ +const FIRST_THRESHOLD = 80; // rivela pulsante +const SECOND_THRESHOLD = 160; // elimina diretta +const CLOSE_THRESHOLD = 40; // swipe a destra per richiudere +const MAX_SWIPE = 200; + +window.initNotifications = () => { + document.querySelectorAll('.row').forEach(initRow); +}; + +function initRow(row) { + const card = row.querySelector('.notification-card'); + const btn = row.querySelector('.trash-btn'); + let startX = 0, currentX = 0, dragging = false; + let open = false; + + card.addEventListener('pointerdown', (e) => { + if (e.pointerType === 'mouse' && e.button !== 0) return; + dragging = true; + startX = e.clientX; + card.setPointerCapture(e.pointerId); + card.style.transition = 'none'; + }); + + card.addEventListener('pointermove', (e) => { + if (!dragging) return; + const dx = e.clientX - startX; + let translate = dx; + + if (!open) { + // swiping left to open/delete + translate = Math.max(-MAX_SWIPE, Math.min(0, dx)); + } else { + // if already open, allow swipe right to close + translate = Math.min(0, -FIRST_THRESHOLD + dx); + } + currentX = translate; + card.style.transform = `translateX(${translate}px)`; + }); + + function endDrag() { + if (!dragging) return; + dragging = false; + card.style.transition = 'transform .2s ease'; + + if (!open) { + if (currentX < -SECOND_THRESHOLD) { + card.style.transform = `translateX(-${MAX_SWIPE}px)`; + setTimeout(() => removeRow(row), 200); + } else if (currentX < -FIRST_THRESHOLD) { + card.style.transform = `translateX(-${FIRST_THRESHOLD}px)`; + open = true; + } else { + card.style.transform = 'translateX(0)'; + open = false; + } + } else { + // se è già aperto e vado a destra abbastanza → chiudo + if (currentX > -FIRST_THRESHOLD + CLOSE_THRESHOLD) { + card.style.transform = 'translateX(0)'; + open = false; + } else { + card.style.transform = `translateX(-${FIRST_THRESHOLD}px)`; + open = true; + } + } + } + + card.addEventListener('pointerup', endDrag); + card.addEventListener('pointercancel', endDrag); + + btn.addEventListener('click', () => removeRow(row)); +} + +function removeRow(row) { + const h = row.getBoundingClientRect().height; + row.style.height = h + 'px'; + row.classList.add('collapsing'); + requestAnimationFrame(() => { + row.style.opacity = '0'; + row.style.marginTop = '0'; + row.style.marginBottom = '0'; + row.style.height = '0'; + }); + setTimeout(() => row.remove(), 220); +} \ No newline at end of file From 7bfe67a97cdd9338c5ae0ce0347f593d7f8a56bd Mon Sep 17 00:00:00 2001 From: MarcoE Date: Thu, 11 Sep 2025 16:06:19 +0200 Subject: [PATCH 4/4] Gestita pagina notifiche --- ... IntegryRegisterNotificationRestClient.cs} | 6 +- .../Core/Services/ManageDataService.cs | 14 +- .../FirebaseNotificationService.cs | 4 +- .../Push/PushNotificationDelegate.cs | 10 +- salesbook.Maui/MauiProgram.cs | 1 + salesbook.Maui/salesbook.Maui.csproj | 2 +- .../Components/Layout/NavMenu.razor | 7 +- .../Components/Pages/Calendar.razor.css | 6 +- .../Components/Pages/Notifications.razor | 155 ++++++++++++++++-- .../Components/Pages/User.razor.css | 1 + .../Components/Pages/Users.razor.css | 3 +- .../Card/NotificationCard.razor | 85 +++++++++- .../Card/NotificationCard.razor.css | 61 +++++-- .../SingleElements/Modal/ActivityForm.razor | 54 ++++-- .../Core/Dto/Activity/ActivityDTO.cs | 14 +- .../Dto/Notification/PushNotificationDTO.cs | 9 - .../Core/Dto/NotificationDataDTO.cs | 12 ++ .../Core/Dto/PageState/NotificationState.cs | 8 +- .../Core/Dto/ReadNotificationRequestDTO.cs | 15 ++ .../Core/Entity/WtbDeviceNotification.cs | 15 ++ .../Core/Entity/WtbNotification.cs | 37 +++++ .../IIntegryNotificationRestClient.cs | 7 +- .../IIntegryRegisterNotificationRestClient.cs | 8 + .../NewPushNotificationMessage.cs | 4 +- .../NewPushNotificationService.cs | 4 +- .../Services/IntegryNotificationRestClient.cs | 33 ++++ salesbook.Shared/salesbook.Shared.csproj | 2 +- salesbook.Shared/wwwroot/css/app.css | 8 +- salesbook.Shared/wwwroot/js/notifications.js | 129 ++++++++++++--- salesbook.Web/salesbook.Web.csproj | 2 +- 30 files changed, 611 insertions(+), 105 deletions(-) rename salesbook.Maui/Core/RestClient/IntegryApi/{IntegryNotificationRestClient.cs => IntegryRegisterNotificationRestClient.cs} (87%) delete mode 100644 salesbook.Shared/Core/Dto/Notification/PushNotificationDTO.cs create mode 100644 salesbook.Shared/Core/Dto/NotificationDataDTO.cs create mode 100644 salesbook.Shared/Core/Dto/ReadNotificationRequestDTO.cs create mode 100644 salesbook.Shared/Core/Entity/WtbDeviceNotification.cs create mode 100644 salesbook.Shared/Core/Entity/WtbNotification.cs create mode 100644 salesbook.Shared/Core/Interface/IntegryApi/IIntegryRegisterNotificationRestClient.cs create mode 100644 salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs diff --git a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs similarity index 87% rename from salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs rename to salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs index 021fc6c..39fc676 100644 --- a/salesbook.Maui/Core/RestClient/IntegryApi/IntegryNotificationRestClient.cs +++ b/salesbook.Maui/Core/RestClient/IntegryApi/IntegryRegisterNotificationRestClient.cs @@ -6,11 +6,11 @@ using salesbook.Shared.Core.Interface.IntegryApi; namespace salesbook.Maui.Core.RestClient.IntegryApi; -public class IntegryNotificationRestClient( - ILogger logger, +public class IntegryRegisterNotificationRestClient( + ILogger logger, IUserSession userSession, IIntegryApiRestClient integryApiRestClient -) : IIntegryNotificationRestClient +) : IIntegryRegisterNotificationRestClient { public async Task Register(string fcmToken, ILogger? logger1 = null) { diff --git a/salesbook.Maui/Core/Services/ManageDataService.cs b/salesbook.Maui/Core/Services/ManageDataService.cs index 9031c83..b9196a1 100644 --- a/salesbook.Maui/Core/Services/ManageDataService.cs +++ b/salesbook.Maui/Core/Services/ManageDataService.cs @@ -1,14 +1,15 @@ using AutoMapper; +using MudBlazor.Extensions; using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Dto.Activity; using salesbook.Shared.Core.Dto.Contact; using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Helpers.Enum; using salesbook.Shared.Core.Interface; -using Sentry.Protocol; -using System.Linq.Expressions; using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Interface.System.Network; +using Sentry.Protocol; +using System.Linq.Expressions; namespace salesbook.Maui.Core.Services; @@ -211,6 +212,15 @@ public class ManageDataService( { var dto = mapper.Map(activity); + if (activity is { AlarmTime: not null, EstimatedTime: not null }) + { + var minuteBefore = activity.EstimatedTime.Value - activity.AlarmTime.Value; + dto.MinuteBefore = (int)Math.Abs(minuteBefore.TotalMinutes); + + dto.NotificationDate = dto.MinuteBefore == 0 ? + activity.EstimatedTime : activity.AlarmTime; + } + if (activity.CodJcom != null) { dto.Category = ActivityCategoryEnum.Commessa; diff --git a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs index 2f766eb..8d0fd36 100644 --- a/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs +++ b/salesbook.Maui/Core/System/Notification/FirebaseNotificationService.cs @@ -8,7 +8,7 @@ namespace salesbook.Maui.Core.System.Notification; public class FirebaseNotificationService( IPushManager pushManager, - IIntegryNotificationRestClient integryNotificationRestClient, + IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient, INotificationManager notificationManager ) : IFirebaseNotificationService { @@ -19,7 +19,7 @@ public class FirebaseNotificationService( var (accessState, token) = await pushManager.RequestAccess(); if (accessState == AccessState.Denied || token is null) return; - await integryNotificationRestClient.Register(token); + await integryRegisterNotificationRestClient.Register(token); } private void CreateNotificationChannel() diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs index 8e69c40..5f0bdc7 100644 --- a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -1,5 +1,5 @@ using CommunityToolkit.Mvvm.Messaging; -using salesbook.Shared.Core.Dto.Notification; +using salesbook.Shared.Core.Entity; using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Messages.Notification; using Shiny.Push; @@ -7,7 +7,7 @@ using Shiny.Push; namespace salesbook.Maui.Core.System.Notification.Push; public class PushNotificationDelegate( - IIntegryNotificationRestClient integryNotificationRestClient, + IIntegryRegisterNotificationRestClient integryRegisterNotificationRestClient, IMessenger messenger ) : IPushDelegate { @@ -20,10 +20,10 @@ public class PushNotificationDelegate( public Task OnReceived(PushNotification notification) { if (notification.Notification is null) return Task.CompletedTask; - var pushNotification = new PushNotificationDTO + var pushNotification = new WtbNotification { Title = notification.Notification.Title, - Message = notification.Notification.Message + Body = notification.Notification.Message }; messenger.Send(new NewPushNotificationMessage(pushNotification)); @@ -33,7 +33,7 @@ public class PushNotificationDelegate( public Task OnNewToken(string token) { - integryNotificationRestClient.Register(token); + integryRegisterNotificationRestClient.Register(token); return Task.CompletedTask; } diff --git a/salesbook.Maui/MauiProgram.cs b/salesbook.Maui/MauiProgram.cs index c9c7290..4abc81f 100644 --- a/salesbook.Maui/MauiProgram.cs +++ b/salesbook.Maui/MauiProgram.cs @@ -86,6 +86,7 @@ namespace salesbook.Maui //Notification builder.Services.AddNotifications(); builder.Services.AddPush(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/salesbook.Maui/salesbook.Maui.csproj b/salesbook.Maui/salesbook.Maui.csproj index fb9eb60..9b32639 100644 --- a/salesbook.Maui/salesbook.Maui.csproj +++ b/salesbook.Maui/salesbook.Maui.csproj @@ -133,7 +133,7 @@ - + diff --git a/salesbook.Shared/Components/Layout/NavMenu.razor b/salesbook.Shared/Components/Layout/NavMenu.razor index 6880a7d..f5c158d 100644 --- a/salesbook.Shared/Components/Layout/NavMenu.razor +++ b/salesbook.Shared/Components/Layout/NavMenu.razor @@ -1,7 +1,6 @@ @using CommunityToolkit.Mvvm.Messaging @using salesbook.Shared.Core.Dto @using salesbook.Shared.Core.Dto.Activity -@using salesbook.Shared.Core.Dto.Notification @using salesbook.Shared.Core.Dto.PageState @using salesbook.Shared.Core.Entity @using salesbook.Shared.Core.Messages.Activity.Copy @@ -35,7 +34,7 @@