WIP: Add iOS version #10

Draft
Deadpikle wants to merge 67 commits from feature/ios into main
2 changed files with 51 additions and 16 deletions
Showing only changes of commit 981114a222 - Show all commits
+1 -10
View File
@@ -85,15 +85,6 @@ class ReportPDFCreator : ChangeNotifier
// https://forum.pdfsharp.net/viewtopic.php?f=2&t=1025
public async Task<string?> CreatePDF(List<ReportFile> reportFiles, string reportTitle, string outputFolderPath, PDFFontResolver fontResolver, Settings appSettings)
{
// safety checks
var outputDir = appSettings.PDFOutputSaveLocation == Enums.PDFSaveLocation.BaseFolder
? outputFolderPath
: appSettings.OutputPdfDir; // TODO: adjust for new logic
if (!Directory.Exists(outputDir))
{
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
return null;
}
// setup globals and consts...
GlobalFontSettings.FontResolver = fontResolver;
GlobalFontSettings.FallbackFontResolver = new FailsafeFontResolver();
@@ -403,7 +394,7 @@ class ReportPDFCreator : ChangeNotifier
pdfRenderer.DocumentRenderer.PrepareDocument(); // needed if you make edits after first PrepareDocument() is called
pdfRenderer.RenderDocument();
// actually save to disk now
string outputPDFFilePath = Path.Join(outputDir, outputFileName);
string outputPDFFilePath = Path.Join(outputFolderPath, outputFileName);
_logger?.LogInfo("Saving PDF document to disk...");
pdfRenderer.PdfDocument.Save(outputPDFFilePath);
_logger?.LogInfo("Finished saving PDF output to: " + outputPDFFilePath);
@@ -11,6 +11,7 @@ using MayShow.Interfaces;
using MayShow.Models;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Avalonia.Threading;
namespace MayShow.ViewModels;
@@ -453,7 +454,7 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
{
try
{
await Task.Run(() => CreatePDF(outputFolderPath: _pdfReport.BaseFolder));
await Task.Run(() => CreatePDF());
} catch (Exception e)
{
LogInfo("PDF process failed! Reason: " + e.Message);
@@ -510,16 +511,59 @@ class CreatePDFReportViewModel : BaseViewModel, ICanCheckShutdown, ILogger
}
}
private async Task CreatePDF(string outputFolderPath)
private async Task CreatePDF()
{
IsCreatingPDF = true;
var reportCreator = new ReportPDFCreator(this);
var outputPdfFile = await reportCreator.CreatePDF(ReportFiles.ToList(), ReportTitle, outputFolderPath, new PDFFontResolver(_processDir, this), _settings);
var outputDir = "";
switch (_settings.PDFOutputSaveLocation)
{
case Enums.PDFSaveLocation.BaseFolder:
outputDir = _pdfReport.BaseFolder;
break;
case Enums.PDFSaveLocation.AlwaysAsk:
await Dispatcher.UIThread.InvokeAsync(async () =>
{
var topLevel = TopLevelGrabber?.GetTopLevel();
if (topLevel != null)
{
var result = await topLevel.StorageProvider.SaveFilePickerWithResultAsync(new FilePickerSaveOptions
{
Title = "Choose PDF save location...",
FileTypeChoices = [FilePickerFileTypes.Pdf],
SuggestedFileType = FilePickerFileTypes.Pdf,
DefaultExtension = "pdf",
ShowOverwritePrompt = true,
});
if (result.File is not null)
{
var path = result.File.Path.AbsolutePath;
Console.WriteLine(path); // <--- this is what I want
}
}
});
IsCreatingPDF = false;
return;
break;
case Enums.PDFSaveLocation.OtherChosenDir:
outputDir = _settings.OutputPdfDir;
break;
}
// safety checks
if (!Directory.Exists(outputDir))
{
await DialogHost.Show(new WarningViewModel("Output directory not found! Please adjust your application Settings before continuing. Output directory: " + outputDir));
}
else
{
var outputPdfFile = await reportCreator.CreatePDF(ReportFiles.ToList(), ReportTitle, outputDir, new PDFFontResolver(_processDir, this), _settings);
if (!string.IsNullOrWhiteSpace(outputPdfFile))
{
await CreateAndSaveReportObjectAfterReportCreation();
OpenFolderForFileInFileViewer(outputPdfFile);
}
}
IsCreatingPDF = false;
}