From 544c9e8237b5f27262800976c511698105a70254 Mon Sep 17 00:00:00 2001 From: MarcoE Date: Tue, 17 Feb 2026 10:23:46 +0100 Subject: [PATCH] Gestiti allegati da galleria e fotocamera e aggiunto sentry --- ...roidx_lifecycle_lifecycle_common_java8.xml | 9 ++ ...brains_kotlin_kotlin_stdlib_jdk7_2_0_0.xml | 9 ++ ...brains_kotlin_kotlin_stdlib_jdk8_2_0_0.xml | 9 ++ SteUp.Maui/Core/Services/AttachedService.cs | 101 ++++++++++++++++++ .../Core/System/GenericSystemService.cs | 9 +- SteUp.Maui/MauiProgram.cs | 8 ++ SteUp.Maui/SteUp.Maui.csproj | 1 + SteUp.Shared/Components/Pages/Login.razor | 2 +- .../SingleElements/AppVersion.razor | 18 +--- .../Modal/ModalAddAttached.razor | 94 +++++++--------- SteUp.Shared/Core/Dto/AttachedDto.cs | 23 ++++ .../Core/Interface/System/IAttachedService.cs | 12 +++ SteUp.Shared/SteUp.Shared.csproj | 1 + 13 files changed, 220 insertions(+), 76 deletions(-) create mode 100644 .idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml create mode 100644 .idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk7_2_0_0.xml create mode 100644 .idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk8_2_0_0.xml create mode 100644 SteUp.Maui/Core/Services/AttachedService.cs create mode 100644 SteUp.Shared/Core/Dto/AttachedDto.cs create mode 100644 SteUp.Shared/Core/Interface/System/IAttachedService.cs diff --git a/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml b/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml new file mode 100644 index 0000000..3c1da74 --- /dev/null +++ b/.idea/.idea.SteUp/.idea/libraries/androidx_lifecycle_lifecycle_common_java8.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk7_2_0_0.xml b/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk7_2_0_0.xml new file mode 100644 index 0000000..017e258 --- /dev/null +++ b/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk7_2_0_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk8_2_0_0.xml b/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk8_2_0_0.xml new file mode 100644 index 0000000..416eab3 --- /dev/null +++ b/.idea/.idea.SteUp/.idea/libraries/org_jetbrains_kotlin_kotlin_stdlib_jdk8_2_0_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/SteUp.Maui/Core/Services/AttachedService.cs b/SteUp.Maui/Core/Services/AttachedService.cs new file mode 100644 index 0000000..d2da0e0 --- /dev/null +++ b/SteUp.Maui/Core/Services/AttachedService.cs @@ -0,0 +1,101 @@ +using SteUp.Shared.Core.Dto; +using SteUp.Shared.Core.Interface.System; + +namespace SteUp.Maui.Core.Services; + +public class AttachedService : IAttachedService +{ + public async Task SelectImageFromCamera() + { + var cameraPerm = await Permissions.RequestAsync(); + var storagePerm = await Permissions.RequestAsync(); + + if (cameraPerm != PermissionStatus.Granted || storagePerm != PermissionStatus.Granted) + return null; + + FileResult? result; + + try + { + result = await MediaPicker.Default.CapturePhotoAsync(); + } + catch (Exception ex) + { + Console.WriteLine($"Errore cattura foto: {ex.Message}"); + SentrySdk.CaptureException(ex); + return null; + } + + return result is null ? null : await ConvertToDto(result, AttachedDto.TypeAttached.Image); + } + + public async Task SelectImageFromGallery() + { + var storagePerm = await Permissions.RequestAsync(); + if (storagePerm != PermissionStatus.Granted) + return null; + + FileResult? result; + + try + { + result = await MediaPicker.Default.PickPhotoAsync(); + } + catch (Exception ex) + { + Console.WriteLine($"Errore selezione galleria: {ex.Message}"); + SentrySdk.CaptureException(ex); + return null; + } + + return result is null ? null : await ConvertToDto(result, AttachedDto.TypeAttached.Image); + } + + private static async Task ConvertToDto(FileResult file, AttachedDto.TypeAttached type) + { + var stream = await file.OpenReadAsync(); + using var ms = new MemoryStream(); + await stream.CopyToAsync(ms); + + return new AttachedDto + { + Name = file.FileName, + Path = file.FullPath, + MimeType = file.ContentType, + DimensionBytes = ms.Length, + FileBytes = ms.ToArray(), + Type = type + }; + } + + public async Task SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default) + { + ArgumentNullException.ThrowIfNull(file); + + if (file.CanSeek) + file.Position = 0; + + fileName = Path.GetFileName(fileName); + + var dir = FileSystem.CacheDirectory; + var filePath = Path.Combine(dir, fileName); + + await using var fileStream = File.Create(filePath); + await file.CopyToAsync(fileStream, ct); + + return filePath; + } + + public Task OpenFile(string fileName, string filePath) + { +#if IOS + throw new NotImplementedException(); +#else + return Launcher.OpenAsync(new OpenFileRequest + { + Title = "Apri file", + File = new ReadOnlyFile(filePath) + }); +#endif + } +} \ No newline at end of file diff --git a/SteUp.Maui/Core/System/GenericSystemService.cs b/SteUp.Maui/Core/System/GenericSystemService.cs index 700b873..334c15f 100644 --- a/SteUp.Maui/Core/System/GenericSystemService.cs +++ b/SteUp.Maui/Core/System/GenericSystemService.cs @@ -4,5 +4,12 @@ namespace SteUp.Maui.Core.System; public class GenericSystemService : IGenericSystemService { - public string GetCurrentAppVersion() => AppInfo.VersionString; + public string GetCurrentAppVersion() + { +#if DEBUG + return $"v{AppInfo.VersionString} [DEBUG]"; +#else + return $"v{AppInfo.VersionString}"; +#endif + } } \ No newline at end of file diff --git a/SteUp.Maui/MauiProgram.cs b/SteUp.Maui/MauiProgram.cs index 9285153..278f159 100644 --- a/SteUp.Maui/MauiProgram.cs +++ b/SteUp.Maui/MauiProgram.cs @@ -23,6 +23,14 @@ namespace SteUp.Maui .UseMauiApp() .UseIntegry(appToken: AppToken, useLoginAzienda: true) .UseMauiCommunityToolkit() + .UseSentry(options => + { + options.Dsn = "https://c1ff03e3d1d2dd973a1ce73c58f92a8d@o4508499810254848.ingest.de.sentry.io/4510900455866448"; +#if DEBUG + options.Debug = true; +#endif + options.TracesSampleRate = 1.0; + }) .ConfigureFonts(fonts => { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); }); builder.Services.AddMauiBlazorWebView(); diff --git a/SteUp.Maui/SteUp.Maui.csproj b/SteUp.Maui/SteUp.Maui.csproj index 6068b48..8c4d168 100644 --- a/SteUp.Maui/SteUp.Maui.csproj +++ b/SteUp.Maui/SteUp.Maui.csproj @@ -120,6 +120,7 @@ + diff --git a/SteUp.Shared/Components/Pages/Login.razor b/SteUp.Shared/Components/Pages/Login.razor index 9350fa2..dd309d1 100644 --- a/SteUp.Shared/Components/Pages/Login.razor +++ b/SteUp.Shared/Components/Pages/Login.razor @@ -36,7 +36,7 @@ else diff --git a/SteUp.Shared/Components/SingleElements/AppVersion.razor b/SteUp.Shared/Components/SingleElements/AppVersion.razor index b2f1d72..89e879f 100644 --- a/SteUp.Shared/Components/SingleElements/AppVersion.razor +++ b/SteUp.Shared/Components/SingleElements/AppVersion.razor @@ -2,21 +2,5 @@ @inject IGenericSystemService GenericSystemService
- @Version + @GenericSystemService.GetCurrentAppVersion()
- -@code -{ - private string Version { get; set; } = ""; - - protected override void OnInitialized() - { -#if DEBUG - Version = $"v{GenericSystemService.GetCurrentAppVersion()} [DEBUG]"; -#else - Version = $"v{GenericSystemService.GetCurrentAppVersion()}"; -#endif - - StateHasChanged(); - } -} diff --git a/SteUp.Shared/Components/SingleElements/Modal/ModalAddAttached.razor b/SteUp.Shared/Components/SingleElements/Modal/ModalAddAttached.razor index f828f49..2f25bd2 100644 --- a/SteUp.Shared/Components/SingleElements/Modal/ModalAddAttached.razor +++ b/SteUp.Shared/Components/SingleElements/Modal/ModalAddAttached.razor @@ -1,5 +1,7 @@ @using SteUp.Shared.Components.Layout -@using SteUp.Shared.Components.Layout.Overlay +@using SteUp.Shared.Core.Dto +@using SteUp.Shared.Core.Interface.System +@inject IAttachedService AttachedService @@ -34,18 +36,11 @@ - - @code { - [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } - + [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } = null!; [Parameter] public bool CanAddPosition { get; set; } - - //Overlay for save - private bool VisibleOverlay { get; set; } - private bool SuccessAnimation { get; set; } - - // private AttachedDTO? Attached { get; set; } + + private AttachedDto? Attached { get; set; } private bool _requireNewName; @@ -60,8 +55,6 @@ } } - private bool SelectTypePicture { get; set; } - private string TitleModal { get; set; } = "Aggiungi allegati"; private string? _newName; @@ -76,66 +69,53 @@ } } - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { - SelectTypePicture = true; RequireNewName = false; Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter; } private async Task OnCamera() { - // Attached = await AttachedService.SelectImageFromCamera(); - // - // if (Attached != null) - // { - // RequireNewName = true; - // StateHasChanged(); - // } + Attached = await AttachedService.SelectImageFromCamera(); + + if (Attached != null) + { + RequireNewName = true; + StateHasChanged(); + } } private async Task OnGallery() { - // Attached = await AttachedService.SelectImageFromGallery(); - // - // if (Attached != null) - // { - // RequireNewName = true; - // StateHasChanged(); - // } + Attached = await AttachedService.SelectImageFromGallery(); + + if (Attached != null) + { + RequireNewName = true; + StateHasChanged(); + } } private void OnNewName() { - // if (Attached != null) - // { - // switch (Attached.Type) - // { - // case AttachedDTO.TypeAttached.Position: - // { - // CanAddPosition = false; - // - // Attached.Description = NewName!; - // Attached.Name = NewName!; - // - // break; - // } - // case AttachedDTO.TypeAttached.Image: - // { - // var extension = Path.GetExtension(Attached.Name); - // Attached.Name = NewName! + extension; - // - // break; - // } - // case AttachedDTO.TypeAttached.Document: - // break; - // default: - // throw new ArgumentOutOfRangeException(); - // } - // } + if (Attached != null) + { + switch (Attached.Type) + { + case AttachedDto.TypeAttached.Image: + { + var extension = Path.GetExtension(Attached.Name); + Attached.Name = NewName! + extension; + + break; + } + default: + throw new ArgumentOutOfRangeException(); + } + } - // MudDialog.Close(Attached); - MudDialog.Close(); + MudDialog.Close(Attached); } } \ No newline at end of file diff --git a/SteUp.Shared/Core/Dto/AttachedDto.cs b/SteUp.Shared/Core/Dto/AttachedDto.cs new file mode 100644 index 0000000..8c7e34a --- /dev/null +++ b/SteUp.Shared/Core/Dto/AttachedDto.cs @@ -0,0 +1,23 @@ +namespace SteUp.Shared.Core.Dto; + +public class AttachedDto +{ + public string? Name { get; set; } + public string? Description { get; set; } + + public string? MimeType { get; set; } + public long? DimensionBytes { get; set; } + public string? Path { get; set; } + + public byte[]? FileBytes { get; set; } + + public Stream? FileContent => + FileBytes is null ? null : new MemoryStream(FileBytes); + + public TypeAttached Type { get; set; } + + public enum TypeAttached + { + Image + } +} \ No newline at end of file diff --git a/SteUp.Shared/Core/Interface/System/IAttachedService.cs b/SteUp.Shared/Core/Interface/System/IAttachedService.cs new file mode 100644 index 0000000..3a00cfb --- /dev/null +++ b/SteUp.Shared/Core/Interface/System/IAttachedService.cs @@ -0,0 +1,12 @@ +using SteUp.Shared.Core.Dto; + +namespace SteUp.Shared.Core.Interface.System; + +public interface IAttachedService +{ + Task SelectImageFromCamera(); + Task SelectImageFromGallery(); + + Task SaveToTempStorage(Stream file, string fileName, CancellationToken ct = default); + Task OpenFile(string fileName, string filePath); +} \ No newline at end of file diff --git a/SteUp.Shared/SteUp.Shared.csproj b/SteUp.Shared/SteUp.Shared.csproj index 06b1778..c6b4b83 100644 --- a/SteUp.Shared/SteUp.Shared.csproj +++ b/SteUp.Shared/SteUp.Shared.csproj @@ -16,6 +16,7 @@ +