WIP Image imports and file access
This commit is contained in:
@@ -105,8 +105,9 @@ public partial class App : Application
|
||||
}
|
||||
});
|
||||
|
||||
services.AddHandler<ProfileImageHandler>();
|
||||
services.AddHandler<QueryWalletHandler>();
|
||||
services.AddHandler<RequestItemHandler>();
|
||||
services.AddHandler<ItemHandler>();
|
||||
services.AddHandler<CreateItemHandler>();
|
||||
services.AddHandler<DeleteItemHandler>();
|
||||
services.AddHandler<UpdateItemHander>();
|
||||
@@ -212,7 +213,9 @@ public partial class App : Application
|
||||
})!);
|
||||
|
||||
services.AddTransient<IWalletFactory, WalletFactory>();
|
||||
|
||||
services.AddHandler<CreateWalletHandler>();
|
||||
services.AddHandler<ProfileImageHandler>();
|
||||
|
||||
services.AddSingleton<IWalletHostCollection, WalletHostCollection>();
|
||||
services.AddInitializer<WalletInitializer>();
|
||||
|
||||
@@ -83,8 +83,8 @@
|
||||
</DropDownButton.Styles>
|
||||
<DropDownButton.Flyout>
|
||||
<MenuFlyout>
|
||||
<MenuItem Header="Import picture" />
|
||||
<MenuItem Header="Remove picture" />
|
||||
<MenuItem Command="{Binding ImportCommand}" Header="Import image" />
|
||||
<MenuItem Header="Remove image" />
|
||||
</MenuFlyout>
|
||||
</DropDownButton.Flyout>
|
||||
<TextBlock
|
||||
|
||||
@@ -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