diff --git a/src/MayShow.Shared/Helpers/Constants.cs b/src/MayShow.Shared/Helpers/Constants.cs index 6f4c715..b5a23af 100644 --- a/src/MayShow.Shared/Helpers/Constants.cs +++ b/src/MayShow.Shared/Helpers/Constants.cs @@ -11,6 +11,9 @@ class Constants public static string[] AllowedFileExtensionPatterns = [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ]; public static string[] AllowedFileExtensionsNoStar = [ "png", "jpg", "jpeg", "gif", "bmp", "webp", "pdf", "heic", ]; + public static string[] FilePickerMimeTypes = [ "image/*", "application/pdf", "image/heic" ]; + public static string[] FilePickerAppleTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ]; + public static string ReportSavedDataFileName = "report_data.json"; public static List GetDateDisplayFormats() diff --git a/src/MayShow.Shared/Helpers/Utilities.cs b/src/MayShow.Shared/Helpers/Utilities.cs index efad8a9..117cecf 100644 --- a/src/MayShow.Shared/Helpers/Utilities.cs +++ b/src/MayShow.Shared/Helpers/Utilities.cs @@ -9,6 +9,7 @@ using System.Text.Json.Serialization; using System.Text.Json.Serialization.Metadata; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Avalonia.Platform.Storage; using MayShow.Models; namespace MayShow.Helpers; @@ -140,4 +141,24 @@ class Utilities var json = await reader.ReadToEndAsync(); await File.WriteAllTextAsync(path, json); } + + public static FilePickerFileType[] GetReportFilePickerFileTypes() + { + return [ + new FilePickerFileType("All Types") + { + Patterns = Constants.AllowedFileExtensionPatterns, + AppleUniformTypeIdentifiers = Constants.FilePickerAppleTypeIdentifiers, + MimeTypes = Constants.FilePickerMimeTypes, + }, + FilePickerFileTypes.ImageAll, + new FilePickerFileType("HEIC Images") + { + Patterns = [ "*.heic" ], + AppleUniformTypeIdentifiers = [ "public.heic" ], + MimeTypes = [ "image/heic" ] + }, + FilePickerFileTypes.Pdf, + ]; + } } \ No newline at end of file diff --git a/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs b/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs index 574aae8..3b15ebc 100644 --- a/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs +++ b/src/MayShow.Shared/ViewModels/CreatePDFReportViewModel.cs @@ -296,22 +296,7 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger { Title = "Choose image or PDF files...", AllowMultiple = true, - FileTypeFilter = [ - new FilePickerFileType("All Types") - { - Patterns = Constants.AllowedFileExtensionPatterns, - AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ], - MimeTypes = [ "image/*", "application/pdf", "image/heic" ] - }, - FilePickerFileTypes.ImageAll, - new FilePickerFileType("HEIC Images") - { - Patterns = [ "*.heic" ], - AppleUniformTypeIdentifiers = [ "public.heic" ], - MimeTypes = [ "image/heic" ] - }, - FilePickerFileTypes.Pdf, - ], + FileTypeFilter = Utilities.GetReportFilePickerFileTypes(), }); if (files.Count > 0) { @@ -401,22 +386,7 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger { Title = "Choose image or PDF file...", AllowMultiple = false, - FileTypeFilter = [ - new FilePickerFileType("All Types") - { - Patterns = Constants.AllowedFileExtensionPatterns, - AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ], - MimeTypes = [ "image/*", "application/pdf", "image/heic" ] - }, - FilePickerFileTypes.ImageAll, - new FilePickerFileType("HEIC Images") - { - Patterns = [ "*.heic" ], - AppleUniformTypeIdentifiers = [ "public.heic" ], - MimeTypes = [ "image/heic" ] - }, - FilePickerFileTypes.Pdf, - ], + FileTypeFilter = Utilities.GetReportFilePickerFileTypes(), }); if (files.Count > 0) {