Fix downloadFile
This commit is contained in:
11
salesbook.Maui/Platforms/Android/Core/FilePreviewService.cs
Normal file
11
salesbook.Maui/Platforms/Android/Core/FilePreviewService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using salesbook.Maui.Core.Interface;
|
||||
|
||||
namespace salesbook.Maui.Core;
|
||||
|
||||
public class FilePreviewService :IFilePreviewService
|
||||
{
|
||||
public Task Preview(string fileName, string filePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
24
salesbook.Maui/Platforms/iOS/Core/FilePreviewService.cs
Normal file
24
salesbook.Maui/Platforms/iOS/Core/FilePreviewService.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using QuickLook;
|
||||
using salesbook.Maui.Core.Interface;
|
||||
using salesbook.Maui.Helpers;
|
||||
using UIKit;
|
||||
|
||||
namespace salesbook.Maui.Core;
|
||||
|
||||
public class FilePreviewService : IFilePreviewService
|
||||
{
|
||||
public Task Preview(string fileName, string filePath)
|
||||
{
|
||||
var currentController = UIApplication.SharedApplication.KeyWindow?.RootViewController;
|
||||
while (currentController?.PresentedViewController != null)
|
||||
currentController = currentController.PresentedViewController;
|
||||
|
||||
var currentView = currentController?.View;
|
||||
var qLPreview = new QLPreviewController();
|
||||
var item = new QlPreviewItemBundle(fileName, filePath);
|
||||
qLPreview.DataSource = new PreviewControllerDs(item);
|
||||
currentController?.PresentViewController(qLPreview, true, null);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
16
salesbook.Maui/Platforms/iOS/Helpers/PreviewControllerDs.cs
Normal file
16
salesbook.Maui/Platforms/iOS/Helpers/PreviewControllerDs.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using QuickLook;
|
||||
|
||||
namespace salesbook.Maui.Helpers;
|
||||
|
||||
public class PreviewControllerDs(QLPreviewItem item) : QLPreviewControllerDataSource
|
||||
{
|
||||
public override nint PreviewItemCount(QLPreviewController controller)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public override IQLPreviewItem GetPreviewItem(QLPreviewController controller, nint index)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
19
salesbook.Maui/Platforms/iOS/Helpers/QlPreviewItemBundle.cs
Normal file
19
salesbook.Maui/Platforms/iOS/Helpers/QlPreviewItemBundle.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Foundation;
|
||||
using QuickLook;
|
||||
|
||||
namespace salesbook.Maui.Helpers;
|
||||
|
||||
public class QlPreviewItemBundle(string fileName, string filePath) : QLPreviewItem
|
||||
{
|
||||
public override string PreviewItemTitle => fileName;
|
||||
public override NSUrl PreviewItemUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
var documents = NSBundle.MainBundle.BundlePath;
|
||||
var lib = Path.Combine(documents, filePath);
|
||||
var url = NSUrl.FromFilename(lib);
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Foundation;
|
||||
using QuickLook;
|
||||
|
||||
namespace salesbook.Maui.Helpers;
|
||||
|
||||
public class QlPreviewItemFileSystem(string fileName, string filePath) : QLPreviewItem
|
||||
{
|
||||
public override string PreviewItemTitle => fileName;
|
||||
|
||||
public override NSUrl PreviewItemUrl => NSUrl.FromString(filePath);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user