diff --git a/Wallet.Avalonia/App.axaml.cs b/Wallet.Avalonia/App.axaml.cs index 9067b93..3c1f658 100644 --- a/Wallet.Avalonia/App.axaml.cs +++ b/Wallet.Avalonia/App.axaml.cs @@ -163,7 +163,6 @@ public partial class App : Application services.AddScoped, DecoratorService>(); services.AddTemplate("Item"); - services.AddHandler("Item"); services.AddTemplate(); services.AddTemplate(); diff --git a/Wallet.Avalonia/ItemNavigationView.axaml b/Wallet.Avalonia/ItemNavigationView.axaml index 04c5005..765e9c1 100644 --- a/Wallet.Avalonia/ItemNavigationView.axaml +++ b/Wallet.Avalonia/ItemNavigationView.axaml @@ -15,6 +15,7 @@ Route="Item" Scope="self"> + @@ -29,7 +30,10 @@ Background="Transparent" ColumnDefinitions="40,*"> - + 0 } name && headerConfiguration.Category is { Length: > 0 } category) { + IImageDescriptor? imageDescriptor = headerConfiguration.ImageDescriptor; Guid id = Guid.NewGuid(); - Item<(Guid, string)> item = new((id, name)); + Item<(Guid, string, string, IImageDescriptor?)> item = new((id, name, category, imageDescriptor)); publisher.Publish(Created.As(item)); await mediator.Handle itemHeaderConfigurationDecorator) : - IHandler, ItemViewModel?> -{ - public Task Handle(CreateEventArgs args, - CancellationToken cancellationToken) - { - string? name = ""; - ItemState? state = null; - - if (args.Parameters is { Length: 5 }) - { - (name, bool _, bool _, bool _, state) = args.Parameters.CreateValueTuple(); - } - - if (args.Parameters is { Length: 2 }) - { - (bool _, state) = args.Parameters.CreateValueTuple(); - } - - ItemHeaderConfiguration configuration = new() - { - Name = name - }; - - itemHeaderConfigurationDecorator.Set(configuration); - - if (serviceFactory.Create(args => args.Initialize(), args.Parameters) is ItemViewModel itemViewModel) - { - itemViewModel.Add(configuration, state, "", name); - itemViewModel.Add(); - - return Task.FromResult(itemViewModel); - } - - return Task.FromResult(default(ItemViewModel)); - } -} diff --git a/Wallet/ItemCreatedHandler.cs b/Wallet/ItemCreatedHandler.cs index aaeb8e5..c0977cd 100644 --- a/Wallet/ItemCreatedHandler.cs +++ b/Wallet/ItemCreatedHandler.cs @@ -6,26 +6,27 @@ namespace Wallet; public class ItemCreatedHandler(IServiceProvider serviceProvider, ICache> cache, IPublisher publisher) : - INotificationHandler>> + INotificationHandler>> { - public Task Handle(CreatedEventArgs> args) + public Task Handle(CreatedEventArgs> args) { - if (args.Sender is Item<(Guid, string)> item) + if (args.Sender is Item<(Guid, string, string, IImageDescriptor?)> item) { - (Guid id, string name) = item.Value; + (Guid id, string name, string category, IImageDescriptor? imageDescriptor) = item.Value; IServiceScope serviceScope = serviceProvider.CreateScope(); IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService(); IDecoratorService> decoratorService = serviceScope.ServiceProvider.GetRequiredService>>(); if (serviceFactory.Create(args => args.Initialize(), - id, name, "Description", true) + id, name, "Description", category, imageDescriptor, true) is ItemNavigationViewModel viewModel) { - cache.Add(item); + Item<(Guid, string)> cachedItem = new((id, name)); + cache.Add(cachedItem); - int index = cache.IndexOf(item); - decoratorService.Set(item); + int index = cache.IndexOf(cachedItem); + decoratorService.Set(cachedItem); publisher.Publish(Insert.As(index, viewModel), nameof(ItemCollectionViewModel)); diff --git a/Wallet/ItemHeaderConfiguration.cs b/Wallet/ItemHeaderConfiguration.cs index 65e8e00..75f8d4d 100644 --- a/Wallet/ItemHeaderConfiguration.cs +++ b/Wallet/ItemHeaderConfiguration.cs @@ -1,8 +1,12 @@ -namespace Wallet; +using Toolkit.Foundation; -public class ItemHeaderConfiguration +namespace Wallet; + +public record ItemHeaderConfiguration { public string? Name { get; set; } public string? Category { get; set; } + + public IImageDescriptor? ImageDescriptor { get; set; } } \ No newline at end of file diff --git a/Wallet/ItemHeaderViewModel.cs b/Wallet/ItemHeaderViewModel.cs index ffcea05..fea146e 100644 --- a/Wallet/ItemHeaderViewModel.cs +++ b/Wallet/ItemHeaderViewModel.cs @@ -5,7 +5,7 @@ using Toolkit.Foundation; namespace Wallet; public partial class ItemHeaderViewModel : - Observable, + Observable, INotificationHandler>, INotificationHandler>, INotificationHandler>, @@ -19,6 +19,7 @@ public partial class ItemHeaderViewModel : [ObservableProperty] private IImageDescriptor? imageDescriptor; + [ObservableProperty] private ItemState state; @@ -30,13 +31,14 @@ public partial class ItemHeaderViewModel : IDisposer disposer, ItemHeaderConfiguration configuration, ItemState state, - string key, - string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value) + string value, + IImageDescriptor? imageDescriptor = null) : base(provider, factory, mediator, publisher, subscriber, disposer, value) { this.configuration = configuration; State = state; Value = value; + ImageDescriptor = imageDescriptor; Track(nameof(Value), () => Value, newValue => Value = newValue); } @@ -85,4 +87,12 @@ public partial class ItemHeaderViewModel : configuration.Name = Value; } } + + partial void OnImageDescriptorChanging(IImageDescriptor? value) + { + if (configuration is not null) + { + configuration.ImageDescriptor = value; + } + } } \ No newline at end of file diff --git a/Wallet/ItemNavigationViewModel.cs b/Wallet/ItemNavigationViewModel.cs index 3b5dc7c..4b25e3e 100644 --- a/Wallet/ItemNavigationViewModel.cs +++ b/Wallet/ItemNavigationViewModel.cs @@ -15,6 +15,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, string name = "", string description = "", string category = "", + IImageDescriptor? imageDescriptor = default, bool isSelected = false, bool favourite = false, bool archived = false) : @@ -44,6 +45,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider, [ObservableProperty] private Guid id = id; + [ObservableProperty] + private IImageDescriptor? imageDescriptor = imageDescriptor; + [ObservableProperty] private bool isSelected = isSelected; diff --git a/Wallet/ItemViewModel.cs b/Wallet/ItemViewModel.cs index 428106b..ffc1181 100644 --- a/Wallet/ItemViewModel.cs +++ b/Wallet/ItemViewModel.cs @@ -35,7 +35,9 @@ public partial class ItemViewModel : IDisposer disposer, IContentTemplate template, NamedComponent named, + IDecoratorService itemHeaderConfigurationDecorator, string name = "", + ImageDescriptor? imageDescriptor = null, bool fromCategory = false, bool favourite = false, bool archived = false, @@ -48,6 +50,16 @@ public partial class ItemViewModel : Favourite = favourite; Archived = archived; Name = name; + + ItemHeaderConfiguration configuration = new() + { + Name = name + }; + + itemHeaderConfigurationDecorator.Set(configuration); + + Add(configuration, state, name, imageDescriptor); + Add(); } public IContentTemplate Template { get; set; }