Refactor mime types, apple type identifiers, file picker type filter
This commit is contained in:
@@ -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<DateDisplayFormat> GetDateDisplayFormats()
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user