diff --git a/src/WorkFlowCheck.MAUI/App.xaml.cs b/src/WorkFlowCheck.MAUI/App.xaml.cs index f32e821..dd2bd17 100644 --- a/src/WorkFlowCheck.MAUI/App.xaml.cs +++ b/src/WorkFlowCheck.MAUI/App.xaml.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection; using System.Threading; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.MAUI.DataLayer; +using WorkFlowCheck.MAUI.Helper; using WorkFlowCheck.MAUI.Services; using WorkFlowCheck.MAUI.Services.Interfaces; @@ -70,7 +71,7 @@ namespace WorkFlowCheck.MAUI { var userDTO = _userService.GetCurrentUser(); - if (userDTO != null && userDTO.Id > 0) + if (userDTO != null && userDTO.Id > 0 && SystemHelper.Syncronised) { if (userDTO.RoleDTO?.Count > 0) { @@ -81,7 +82,13 @@ namespace WorkFlowCheck.MAUI var deviceMessageDTOList = await _syncService.DeviceMessageReadUnreaded(_userService.DeviceId.ToUpper()); if (deviceMessageDTOList != null && deviceMessageDTOList.Count > 0) { - await ShowSnackbar(deviceMessageDTOList[0].Message); + await ShowSnackbar(deviceMessageDTOList[0].Message, async () => await GoToCheckListPage()); + break; + } + deviceMessageDTOList = await _syncService.DeviceMessageReadUnreadedRole(roleDTO.Id); + if (deviceMessageDTOList != null && deviceMessageDTOList.Count > 0) + { + await ShowSnackbar(deviceMessageDTOList[0].Message, async () => await GoToCheckListPage()); break; } } @@ -96,8 +103,32 @@ namespace WorkFlowCheck.MAUI await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } } - private async Task ShowSnackbar(string message) + private async Task GoToCheckListPage() { + await Shell.Current.GoToAsync("//CheckListPage"); + } + private async Task ShowSnackbar(string message, Func action) + { +#if ANDROID + try + { + var context = Android.App.Application.Context; + var player = Android.Media.MediaPlayer.Create(context, Resource.Raw.siren_alert); + player.Start(); + + // Ha lejátszás után el akarod engedni az erÅ‘forrást: + player.Completion += (s, e) => + { + player.Release(); + player.Dispose(); + }; + } + catch (Exception ex) + { + Console.WriteLine("Hanglejátszás hiba: " + ex.Message); + } +#endif + var visualOptions = new SnackbarOptions { ActionButtonTextColor = Colors.Yellow, @@ -105,17 +136,18 @@ namespace WorkFlowCheck.MAUI Font = Microsoft.Maui.Font.SystemFontOfSize(16), BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Red"), TextColor = Colors.Yellow - }; + var snackbar = Snackbar.Make(message, - duration: TimeSpan.FromSeconds(10), - action: () => Console.WriteLine("Snackbar dismissed"), - actionButtonText: "OK", - visualOptions: visualOptions - ); + duration: TimeSpan.FromSeconds(10), + action: async () => await action(), + actionButtonText: "OK", + visualOptions: visualOptions + ); await snackbar.Show(); } + private async Task> CheckSecurity() { var isLogged = await SecureStorage.Default.GetAsync("WFCUser"); diff --git a/src/WorkFlowCheck.MAUI/Helper/SystemHelper.cs b/src/WorkFlowCheck.MAUI/Helper/SystemHelper.cs index 9c29e3d..957e5a2 100644 --- a/src/WorkFlowCheck.MAUI/Helper/SystemHelper.cs +++ b/src/WorkFlowCheck.MAUI/Helper/SystemHelper.cs @@ -14,6 +14,7 @@ namespace WorkFlowCheck.MAUI.Helper public static class SystemHelper { public static string DatabaseName = ""; + public static bool Syncronised = false; #if DEBUG public static string ApiBaseUrl = $"https://dev.wfcapi.nuvolar.hu/"; public static string ApiKey = $"RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU="; diff --git a/src/WorkFlowCheck.MAUI/Pages/System/SyncPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/System/SyncPage.xaml.cs index 510fd1b..6d1c863 100644 --- a/src/WorkFlowCheck.MAUI/Pages/System/SyncPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/System/SyncPage.xaml.cs @@ -1,5 +1,6 @@ using Android.DeviceLock; using WorkFlowCheck.Common.DTO; +using WorkFlowCheck.MAUI.Helper; using WorkFlowCheck.MAUI.Services.Interfaces; namespace WorkFlowCheck.MAUI.Pages.System; @@ -49,7 +50,7 @@ public partial class SyncPage : ContentPage }); }); }); - + SystemHelper.Syncronised = true; progressLabel.Text = "Szinkronizálás befejezve!"; await Shell.Current.GoToAsync("//MainPage"); } diff --git a/src/WorkFlowCheck.MAUI/Platforms/Android/Resources/Raw/siren_alert.mp3 b/src/WorkFlowCheck.MAUI/Platforms/Android/Resources/Raw/siren_alert.mp3 new file mode 100644 index 0000000..7e96c27 Binary files /dev/null and b/src/WorkFlowCheck.MAUI/Platforms/Android/Resources/Raw/siren_alert.mp3 differ diff --git a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs index 24055ca..6c60610 100644 --- a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs @@ -22,6 +22,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces Task> SyncCheckListHeader_Up(int Id, Action reportProgress); Task> DeviceMessageReadUnreaded(string deviceIdBase64); + Task> DeviceMessageReadUnreadedRole(int roleId); Task> SyncUsers_Up(Action reportProgress); Task SyncUsers_Down(Action reportProgress); diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs index e600853..4469f2f 100644 --- a/src/WorkFlowCheck.MAUI/Services/SyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs @@ -405,6 +405,27 @@ namespace WorkFlowCheck.MAUI.Services } return retVal; } + public async Task> DeviceMessageReadUnreadedRole(int roleId) + { + string endpoint = $"{_httpClient.BaseAddress}api/Sync/DeviceMessageReadUnreadedRole/{roleId}"; + var retVal = new List(); + try + { + var response = await _httpClient.GetFromJsonAsync>>(endpoint); + if (response != null) + { + if (response.IsSuccess) + { + return response.Data; + } + } + } + catch (Exception ex) + { + + } + return retVal; + } public async Task> SyncUsers_Up(Action reportProgress) {