WIP Image imports and file access
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Toolkit.Foundation;
|
||||
@@ -27,6 +28,12 @@ public partial class CreateWalletViewModel :
|
||||
[ObservableProperty]
|
||||
private bool isConfirmed;
|
||||
|
||||
[RelayCommand]
|
||||
public async Task Import()
|
||||
{
|
||||
await Mediator.Handle<RequestEventArgs<ProfileImage>, IImageDescriptor>(Request.As<ProfileImage>());
|
||||
}
|
||||
|
||||
public CreateWalletViewModel(IValidation validation,
|
||||
IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
|
||||
@@ -5,13 +5,13 @@ using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class RequestItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
public class ItemHandler(IDbContextFactory<WalletContext> dbContextFactory) :
|
||||
IHandler<RequestEventArgs<Item<Guid>>, (Guid, string, string?, string, ItemConfiguration?)>
|
||||
{
|
||||
public async Task<(Guid, string, string?, string, ItemConfiguration?)> Handle(RequestEventArgs<Item<Guid>> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (args.Value is Item<Guid> item)
|
||||
if (args.Sender is Item<Guid> item)
|
||||
{
|
||||
Guid id = item.Value;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Wallet;
|
||||
|
||||
public record ProfileImage;
|
||||
@@ -0,0 +1,22 @@
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Wallet;
|
||||
|
||||
public class ProfileImageHandler(IFileProvider fileProvider,
|
||||
IImageProvider imageProvider) :
|
||||
IHandler<RequestEventArgs<ProfileImage>, IImageDescriptor?>
|
||||
{
|
||||
public async Task<IImageDescriptor?> Handle(RequestEventArgs<ProfileImage> args,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (await fileProvider.SelectFiles(new FileFilter("Image files", ["jpg", "jpeg", "png"])) is { Count: 1 } files)
|
||||
{
|
||||
if (files.FirstOrDefault() is string file)
|
||||
{
|
||||
return await imageProvider.Get(file, 100, 100, true);
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user