From da92dc45b6d50f178f8888aec54e8f25bbf41f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Szab=C3=B3?= Date: Fri, 16 May 2025 07:27:02 +0200 Subject: [PATCH] =?UTF-8?q?Firebase=20FCM=20kliens=20m=C5=B1k=C3=B6dik?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pages/Security/LoginPage.xaml.cs | 20 +++++++++++++++---- .../Platforms/Android/MainActivity.cs | 13 +++++++++++- .../Services/Interfaces/ISyncService.cs | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs index 83f7bd5..2c762e3 100644 --- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs @@ -15,7 +15,7 @@ public partial class LoginPage : BasePage public LoginPage() { InitializeComponent(); - InitFirebase(); + SetContent(LoginContent); _userService = MauiProgram.ServiceProvider.GetRequiredService(); _syncService = MauiProgram.ServiceProvider.GetRequiredService(); @@ -35,10 +35,22 @@ public partial class LoginPage : BasePage if (response != null && response.IsSuccess) { _userService.SetCurrentUser(response.Data); - SystemHelper.SystemUserDTO = response.Data; + SystemHelper.SystemUserDTO = response.Data; + var needFCM = false; + foreach (var role in response.Data.RoleDTO) + { + if (role.CanEnableBlocked) + { + needFCM = true; + break; + } + } + if (needFCM) + { + await InitFirebase(); + } - var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data); await SecureStorage.Default.SetAsync("WFCUser", "wFCUser"); await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken); @@ -169,7 +181,7 @@ public partial class LoginPage : BasePage } - private async void InitFirebase() + private async Task InitFirebase() { try { diff --git a/src/WorkFlowCheck.MAUI/Platforms/Android/MainActivity.cs b/src/WorkFlowCheck.MAUI/Platforms/Android/MainActivity.cs index 001b30b..64eef11 100644 --- a/src/WorkFlowCheck.MAUI/Platforms/Android/MainActivity.cs +++ b/src/WorkFlowCheck.MAUI/Platforms/Android/MainActivity.cs @@ -1,6 +1,7 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Android.Media; using Android.Nfc; using Android.OS; using Firebase; @@ -103,11 +104,21 @@ namespace WorkFlowCheck.MAUI } private void CreateNotificationChannel() { + var soundUri = Android.Net.Uri.Parse($"android.resource://{Android.App.Application.Context.PackageName}/raw/siren_alert"); + var audioAttributes = new AudioAttributes.Builder() + .SetUsage(AudioUsageKind.Notification) + .SetContentType(AudioContentType.Sonification) + .Build(); var channelId = $"{PackageName}.general"; var notificationManager = (NotificationManager)GetSystemService(NotificationService); - var channel = new NotificationChannel(channelId, "General", NotificationImportance.Default); + var channel = new NotificationChannel(channelId, "General", NotificationImportance.High); + + channel.SetSound(soundUri, audioAttributes); + notificationManager.CreateNotificationChannel(channel); FirebaseCloudMessagingImplementation.ChannelId = channelId; + + } } } diff --git a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs index c62d1c0..c0feda4 100644 --- a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs @@ -27,6 +27,6 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces Task> SyncUsers_Up(Action reportProgress); Task SyncUsers_Down(Action reportProgress); - Task UploadFCMToken(string token); + Task> UploadFCMToken(string token); } }