wip item images
This commit is contained in:
@@ -163,7 +163,6 @@ public partial class App : Application
|
|||||||
services.AddScoped<IDecoratorService<ItemConfiguration>, DecoratorService<ItemConfiguration>>();
|
services.AddScoped<IDecoratorService<ItemConfiguration>, DecoratorService<ItemConfiguration>>();
|
||||||
|
|
||||||
services.AddTemplate<ItemViewModel, ItemView>("Item");
|
services.AddTemplate<ItemViewModel, ItemView>("Item");
|
||||||
services.AddHandler<CreateItemViewModelHandler>("Item");
|
|
||||||
|
|
||||||
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
services.AddTemplate<ItemHeaderViewModel, ItemHeaderView>();
|
||||||
services.AddTemplate<ItemContentViewModel, ItemContentView>();
|
services.AddTemplate<ItemContentViewModel, ItemContentView>();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
Route="Item"
|
Route="Item"
|
||||||
Scope="self">
|
Scope="self">
|
||||||
<Parameter Key="Name" Value="{Binding Name}" />
|
<Parameter Key="Name" Value="{Binding Name}" />
|
||||||
|
<Parameter Key="ImageDescriptor" Value="{Binding ImageDescriptor}" />
|
||||||
<Parameter Key="FromCategory" Value="{x:False}" />
|
<Parameter Key="FromCategory" Value="{x:False}" />
|
||||||
<Parameter Key="Favourite" Value="{Binding Favourite}" />
|
<Parameter Key="Favourite" Value="{Binding Favourite}" />
|
||||||
<Parameter Key="Archived" Value="{Binding Archived}" />
|
<Parameter Key="Archived" Value="{Binding Archived}" />
|
||||||
@@ -29,7 +30,10 @@
|
|||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
ColumnDefinitions="40,*">
|
ColumnDefinitions="40,*">
|
||||||
<Grid Grid.Column="0">
|
<Grid Grid.Column="0">
|
||||||
<PersonPicture Height="40" DisplayName="{Binding Name}" />
|
<PersonPicture
|
||||||
|
Height="40"
|
||||||
|
DisplayName="{Binding Name}"
|
||||||
|
ProfilePicture="{Binding ImageDescriptor.Image}" />
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Margin="0,0,0,-2"
|
Margin="0,0,0,-2"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ public class ConfirmCreateItemHandler(IMediator mediator,
|
|||||||
if (headerConfiguration.Name is { Length: > 0 } name &&
|
if (headerConfiguration.Name is { Length: > 0 } name &&
|
||||||
headerConfiguration.Category is { Length: > 0 } category)
|
headerConfiguration.Category is { Length: > 0 } category)
|
||||||
{
|
{
|
||||||
|
IImageDescriptor? imageDescriptor = headerConfiguration.ImageDescriptor;
|
||||||
Guid id = Guid.NewGuid();
|
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));
|
publisher.Publish(Created.As(item));
|
||||||
|
|
||||||
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
await mediator.Handle<CreateEventArgs<(Guid, string, string,
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
using Toolkit.Foundation;
|
|
||||||
|
|
||||||
namespace Wallet;
|
|
||||||
|
|
||||||
public class CreateItemViewModelHandler(IServiceFactory serviceFactory,
|
|
||||||
IDecoratorService<ItemHeaderConfiguration> itemHeaderConfigurationDecorator) :
|
|
||||||
IHandler<CreateEventArgs<ItemViewModel>, ItemViewModel?>
|
|
||||||
{
|
|
||||||
public Task<ItemViewModel?> Handle(CreateEventArgs<ItemViewModel> args,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
string? name = "";
|
|
||||||
ItemState? state = null;
|
|
||||||
|
|
||||||
if (args.Parameters is { Length: 5 })
|
|
||||||
{
|
|
||||||
(name, bool _, bool _, bool _, state) = args.Parameters.CreateValueTuple<string, bool, bool, bool, ItemState>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.Parameters is { Length: 2 })
|
|
||||||
{
|
|
||||||
(bool _, state) = args.Parameters.CreateValueTuple<bool, ItemState>();
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemHeaderConfiguration configuration = new()
|
|
||||||
{
|
|
||||||
Name = name
|
|
||||||
};
|
|
||||||
|
|
||||||
itemHeaderConfigurationDecorator.Set(configuration);
|
|
||||||
|
|
||||||
if (serviceFactory.Create<ItemViewModel>(args => args.Initialize(), args.Parameters) is ItemViewModel itemViewModel)
|
|
||||||
{
|
|
||||||
itemViewModel.Add<ItemHeaderViewModel>(configuration, state, "", name);
|
|
||||||
itemViewModel.Add<ItemContentViewModel>();
|
|
||||||
|
|
||||||
return Task.FromResult<ItemViewModel?>(itemViewModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(default(ItemViewModel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,26 +6,27 @@ namespace Wallet;
|
|||||||
public class ItemCreatedHandler(IServiceProvider serviceProvider,
|
public class ItemCreatedHandler(IServiceProvider serviceProvider,
|
||||||
ICache<Item<(Guid, string)>> cache,
|
ICache<Item<(Guid, string)>> cache,
|
||||||
IPublisher publisher) :
|
IPublisher publisher) :
|
||||||
INotificationHandler<CreatedEventArgs<Item<(Guid, string)>>>
|
INotificationHandler<CreatedEventArgs<Item<(Guid, string, string, IImageDescriptor?)>>>
|
||||||
{
|
{
|
||||||
public Task Handle(CreatedEventArgs<Item<(Guid, string)>> args)
|
public Task Handle(CreatedEventArgs<Item<(Guid, string, string, IImageDescriptor?)>> 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();
|
IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||||
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
IServiceFactory serviceFactory = serviceScope.ServiceProvider.GetRequiredService<IServiceFactory>();
|
||||||
IDecoratorService<Item<(Guid, string)>> decoratorService = serviceScope.ServiceProvider.GetRequiredService<IDecoratorService<Item<(Guid, string)>>>();
|
IDecoratorService<Item<(Guid, string)>> decoratorService = serviceScope.ServiceProvider.GetRequiredService<IDecoratorService<Item<(Guid, string)>>>();
|
||||||
|
|
||||||
if (serviceFactory.Create<ItemNavigationViewModel>(args => args.Initialize(),
|
if (serviceFactory.Create<ItemNavigationViewModel>(args => args.Initialize(),
|
||||||
id, name, "Description", true)
|
id, name, "Description", category, imageDescriptor, true)
|
||||||
is ItemNavigationViewModel viewModel)
|
is ItemNavigationViewModel viewModel)
|
||||||
{
|
{
|
||||||
cache.Add(item);
|
Item<(Guid, string)> cachedItem = new((id, name));
|
||||||
|
cache.Add(cachedItem);
|
||||||
|
|
||||||
int index = cache.IndexOf(item);
|
int index = cache.IndexOf(cachedItem);
|
||||||
decoratorService.Set(item);
|
decoratorService.Set(cachedItem);
|
||||||
|
|
||||||
publisher.Publish(Insert.As(index, viewModel),
|
publisher.Publish(Insert.As(index, viewModel),
|
||||||
nameof(ItemCollectionViewModel));
|
nameof(ItemCollectionViewModel));
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
namespace Wallet;
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
public class ItemHeaderConfiguration
|
namespace Wallet;
|
||||||
|
|
||||||
|
public record ItemHeaderConfiguration
|
||||||
{
|
{
|
||||||
public string? Name { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
public string? Category { get; set; }
|
public string? Category { get; set; }
|
||||||
|
|
||||||
|
public IImageDescriptor? ImageDescriptor { get; set; }
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ using Toolkit.Foundation;
|
|||||||
namespace Wallet;
|
namespace Wallet;
|
||||||
|
|
||||||
public partial class ItemHeaderViewModel :
|
public partial class ItemHeaderViewModel :
|
||||||
Observable<string, string>,
|
Observable<string>,
|
||||||
INotificationHandler<UpdateEventArgs<Item>>,
|
INotificationHandler<UpdateEventArgs<Item>>,
|
||||||
INotificationHandler<ConfirmEventArgs<Item>>,
|
INotificationHandler<ConfirmEventArgs<Item>>,
|
||||||
INotificationHandler<CancelEventArgs<Item>>,
|
INotificationHandler<CancelEventArgs<Item>>,
|
||||||
@@ -19,6 +19,7 @@ public partial class ItemHeaderViewModel :
|
|||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private IImageDescriptor? imageDescriptor;
|
private IImageDescriptor? imageDescriptor;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private ItemState state;
|
private ItemState state;
|
||||||
|
|
||||||
@@ -30,13 +31,14 @@ public partial class ItemHeaderViewModel :
|
|||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
ItemHeaderConfiguration configuration,
|
ItemHeaderConfiguration configuration,
|
||||||
ItemState state,
|
ItemState state,
|
||||||
string key,
|
string value,
|
||||||
string value) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value)
|
IImageDescriptor? imageDescriptor = null) : base(provider, factory, mediator, publisher, subscriber, disposer, value)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
|
|
||||||
State = state;
|
State = state;
|
||||||
Value = value;
|
Value = value;
|
||||||
|
ImageDescriptor = imageDescriptor;
|
||||||
|
|
||||||
Track(nameof(Value), () => Value, newValue => Value = newValue);
|
Track(nameof(Value), () => Value, newValue => Value = newValue);
|
||||||
}
|
}
|
||||||
@@ -85,4 +87,12 @@ public partial class ItemHeaderViewModel :
|
|||||||
configuration.Name = Value;
|
configuration.Name = Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnImageDescriptorChanging(IImageDescriptor? value)
|
||||||
|
{
|
||||||
|
if (configuration is not null)
|
||||||
|
{
|
||||||
|
configuration.ImageDescriptor = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
string name = "",
|
string name = "",
|
||||||
string description = "",
|
string description = "",
|
||||||
string category = "",
|
string category = "",
|
||||||
|
IImageDescriptor? imageDescriptor = default,
|
||||||
bool isSelected = false,
|
bool isSelected = false,
|
||||||
bool favourite = false,
|
bool favourite = false,
|
||||||
bool archived = false) :
|
bool archived = false) :
|
||||||
@@ -44,6 +45,9 @@ public partial class ItemNavigationViewModel(IServiceProvider provider,
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private Guid id = id;
|
private Guid id = id;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private IImageDescriptor? imageDescriptor = imageDescriptor;
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private bool isSelected = isSelected;
|
private bool isSelected = isSelected;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ public partial class ItemViewModel :
|
|||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
IContentTemplate template,
|
IContentTemplate template,
|
||||||
NamedComponent named,
|
NamedComponent named,
|
||||||
|
IDecoratorService<ItemHeaderConfiguration> itemHeaderConfigurationDecorator,
|
||||||
string name = "",
|
string name = "",
|
||||||
|
ImageDescriptor? imageDescriptor = null,
|
||||||
bool fromCategory = false,
|
bool fromCategory = false,
|
||||||
bool favourite = false,
|
bool favourite = false,
|
||||||
bool archived = false,
|
bool archived = false,
|
||||||
@@ -48,6 +50,16 @@ public partial class ItemViewModel :
|
|||||||
Favourite = favourite;
|
Favourite = favourite;
|
||||||
Archived = archived;
|
Archived = archived;
|
||||||
Name = name;
|
Name = name;
|
||||||
|
|
||||||
|
ItemHeaderConfiguration configuration = new()
|
||||||
|
{
|
||||||
|
Name = name
|
||||||
|
};
|
||||||
|
|
||||||
|
itemHeaderConfigurationDecorator.Set(configuration);
|
||||||
|
|
||||||
|
Add<ItemHeaderViewModel>(configuration, state, name, imageDescriptor);
|
||||||
|
Add<ItemContentViewModel>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContentTemplate Template { get; set; }
|
public IContentTemplate Template { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user