WIP Image imports and file access

This commit is contained in:
TheXamlGuy
2024-06-28 21:03:56 +01:00
parent f75084e874
commit 3d39487cd7
6 changed files with 40 additions and 5 deletions
+4 -1
View File
@@ -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>();
+2 -2
View File
@@ -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
+7
View File
@@ -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;
+3
View File
@@ -0,0 +1,3 @@
namespace Wallet;
public record ProfileImage;
+22
View File
@@ -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;
}
}