From f38a3d6aada131b74451d172fe39d5c5b574bff1 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Mon, 15 Jul 2024 21:14:30 +0100 Subject: [PATCH] Improved json support --- .../AttachmentEntryCollectionConfiguration.cs | 2 +- Wallet/AttachmentEntryCollectionViewModel.cs | 6 +-- Wallet/CloseWalletHandler.cs | 13 ++---- Wallet/Comment.cs | 8 ++++ Wallet/CommentEntryCollectionConfiguration.cs | 2 +- Wallet/CommentEntryCollectionViewModel.cs | 15 ++++--- .../CommentEntryCollectionViewModelHandler.cs | 2 +- Wallet/CreateCommentEntryViewModel.cs | 4 +- Wallet/CurrencyEntryConfiguration.cs | 5 +-- Wallet/DateEntryConfiguration.cs | 5 +-- Wallet/DateEntryViewModel.cs | 6 +-- Wallet/DateEntryViewModelHandler.cs | 6 +-- .../DropdownEntryCollectionConfiguration.cs | 4 +- Wallet/DropdownEntryCollectionViewModel.cs | 6 +-- Wallet/Hyperlink.cs | 2 +- Wallet/HyperlinkEntryConfiguration.cs | 5 +-- Wallet/HyperlinkEntryViewModel.cs | 2 +- Wallet/IItemEntryConfiguration.cs | 35 +++++++++++++-- Wallet/ImageEntryConfiguration.cs | 5 +-- Wallet/ItemConfiguration.cs | 45 +++++++++---------- Wallet/ItemEntryCollectionViewModel.cs | 12 +++-- Wallet/ItemEntryConfiguration.cs | 12 ++--- Wallet/ItemEntryViewModel.cs | 43 +++++++++--------- Wallet/ItemHeaderViewModel.cs | 2 - Wallet/ItemSectionConfiguration.cs | 2 +- Wallet/MaskedTextEntryConfiguration.cs | 2 +- Wallet/MaskedTextEntryViewModel.cs | 2 +- Wallet/NumberEntryConfiguration.cs | 2 +- Wallet/PasswordEntryConfiguration.cs | 5 +-- Wallet/PasswordEntryViewModel.cs | 2 +- Wallet/PinEntryConfiguration.cs | 2 +- Wallet/PinEntryViewModel.cs | 2 +- Wallet/TextEntryConfiguration.cs | 5 +-- Wallet/TextEntryViewModel.cs | 2 +- 34 files changed, 143 insertions(+), 130 deletions(-) create mode 100644 Wallet/Comment.cs diff --git a/Wallet/AttachmentEntryCollectionConfiguration.cs b/Wallet/AttachmentEntryCollectionConfiguration.cs index e7890d2..eb266a1 100644 --- a/Wallet/AttachmentEntryCollectionConfiguration.cs +++ b/Wallet/AttachmentEntryCollectionConfiguration.cs @@ -1,4 +1,4 @@ namespace Wallet; public record AttachmentEntryCollectionConfiguration : - ItemEntryConfiguration; + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/AttachmentEntryCollectionViewModel.cs b/Wallet/AttachmentEntryCollectionViewModel.cs index e93754a..29d8326 100644 --- a/Wallet/AttachmentEntryCollectionViewModel.cs +++ b/Wallet/AttachmentEntryCollectionViewModel.cs @@ -9,9 +9,9 @@ public partial class AttachmentEntryCollectionViewModel(IServiceProvider provide ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration> configuration, string key, - ICollection> value, + ICollection value, bool isConcealed, bool isRevealed, - double width) : ItemEntryCollectionViewModel>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); + double width) : ItemEntryCollectionViewModel>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); diff --git a/Wallet/CloseWalletHandler.cs b/Wallet/CloseWalletHandler.cs index ecd89d1..a3855c6 100644 --- a/Wallet/CloseWalletHandler.cs +++ b/Wallet/CloseWalletHandler.cs @@ -1,19 +1,14 @@ -using Microsoft.EntityFrameworkCore; -using Toolkit.Foundation; -using Wallet.Data; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; +using Toolkit.Foundation; namespace Wallet; -public class CloseWalletHandler(IDecoratorService walletConnectionDecorator, - IDbContextFactory dbContextFactory) : +public class CloseWalletHandler(IDecoratorService walletConnectionDecorator) : IHandler, bool> { - public async Task Handle(CloseEventArgs args, + public Task Handle(CloseEventArgs args, CancellationToken cancellationToken) { walletConnectionDecorator.Set(null); - - return true; + return Task.FromResult(true); } } diff --git a/Wallet/Comment.cs b/Wallet/Comment.cs new file mode 100644 index 0000000..6330f80 --- /dev/null +++ b/Wallet/Comment.cs @@ -0,0 +1,8 @@ +namespace Wallet; + +public record Comment +{ + public DateTimeOffset DateTime { get; set; } + + public string? Text { get; set; } +} diff --git a/Wallet/CommentEntryCollectionConfiguration.cs b/Wallet/CommentEntryCollectionConfiguration.cs index c0a4214..4c009e0 100644 --- a/Wallet/CommentEntryCollectionConfiguration.cs +++ b/Wallet/CommentEntryCollectionConfiguration.cs @@ -1,4 +1,4 @@ namespace Wallet; public record CommentEntryCollectionConfiguration : - ItemEntryConfiguration; \ No newline at end of file + ItemEntryConfiguration>; \ No newline at end of file diff --git a/Wallet/CommentEntryCollectionViewModel.cs b/Wallet/CommentEntryCollectionViewModel.cs index a50abfd..d35ece9 100644 --- a/Wallet/CommentEntryCollectionViewModel.cs +++ b/Wallet/CommentEntryCollectionViewModel.cs @@ -10,21 +10,22 @@ public partial class CommentEntryCollectionViewModel(IServiceProvider provider, IDisposer disposer, IContentTemplate template, ItemState state, - ItemEntryConfiguration configuration, + ItemEntryConfiguration> configuration, string key, - ICollection> value, + ICollection value, bool isConcealed, bool isRevealed, - double width) : ItemEntryCollectionViewModel>>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width), - INotificationHandler>> + double width) : ItemEntryCollectionViewModel>(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width), + INotificationHandler> { public IContentTemplate Template { get; set; } = template; - public Task Handle(CreateEventArgs> args) + public Task Handle(CreateEventArgs args) { - if (args.Sender is Comment comment) + if (args.Sender is Comment comment) { - Insert(0, DateTimeOffset.Now, comment.Value); + Insert(0, comment.DateTime, comment.Text); + Value.Add(comment); } return Task.CompletedTask; diff --git a/Wallet/CommentEntryCollectionViewModelHandler.cs b/Wallet/CommentEntryCollectionViewModelHandler.cs index e02b3fd..713e00f 100644 --- a/Wallet/CommentEntryCollectionViewModelHandler.cs +++ b/Wallet/CommentEntryCollectionViewModelHandler.cs @@ -11,7 +11,7 @@ public class CommentEntryCollectionViewModelHandler(IServiceFactory serviceFacto if (args.Sender is CommentEntryCollectionConfiguration configuration) { string? label = configuration.Label; - string? value = $"{configuration.Value}" ?? ""; + List value = new List(); double? width = configuration.Width; if (serviceFactory.Create(args => args.Initialize(), diff --git a/Wallet/CreateCommentEntryViewModel.cs b/Wallet/CreateCommentEntryViewModel.cs index 425f4e5..a7cb6c4 100644 --- a/Wallet/CreateCommentEntryViewModel.cs +++ b/Wallet/CreateCommentEntryViewModel.cs @@ -3,8 +3,6 @@ using Toolkit.Foundation; namespace Wallet; -public record Comment(TValue Value); - public partial class CreateCommentEntryViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, @@ -16,7 +14,7 @@ public partial class CreateCommentEntryViewModel(IServiceProvider provider, [RelayCommand] private void Invoke() { - Publisher.Publish(Create.As(new Comment(Value))); + Publisher.Publish(Create.As(new Comment { Text = Value, DateTime = DateTimeOffset.Now })); Value = null; } } \ No newline at end of file diff --git a/Wallet/CurrencyEntryConfiguration.cs b/Wallet/CurrencyEntryConfiguration.cs index f360fc6..667389c 100644 --- a/Wallet/CurrencyEntryConfiguration.cs +++ b/Wallet/CurrencyEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record CurrencyEntryConfiguration : - ItemEntryConfiguration -{ - -} \ No newline at end of file + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/DateEntryConfiguration.cs b/Wallet/DateEntryConfiguration.cs index bb134cd..a6335f5 100644 --- a/Wallet/DateEntryConfiguration.cs +++ b/Wallet/DateEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record DateEntryConfiguration : - ItemEntryConfiguration -{ - -} \ No newline at end of file + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/DateEntryViewModel.cs b/Wallet/DateEntryViewModel.cs index fdeaa3c..e2e6b17 100644 --- a/Wallet/DateEntryViewModel.cs +++ b/Wallet/DateEntryViewModel.cs @@ -9,9 +9,9 @@ public partial class DateEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, - DateTimeOffset value, + DateTimeOffset? value, bool isConcealed, bool isRevealed, - double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); + double width) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value, isConcealed, isRevealed, width); diff --git a/Wallet/DateEntryViewModelHandler.cs b/Wallet/DateEntryViewModelHandler.cs index f73aed4..6eeb4b8 100644 --- a/Wallet/DateEntryViewModelHandler.cs +++ b/Wallet/DateEntryViewModelHandler.cs @@ -12,11 +12,7 @@ public class DateEntryViewModelHandler(IServiceFactory serviceFactory) : { string? label = configuration.Label; - if (!DateTimeOffset.TryParse($"{configuration.Value}", out DateTimeOffset value)) - { - value = DateTimeOffset.Now; - } - + DateTimeOffset? value = configuration.Value is not null ? configuration.Value : DateTimeOffset.Now; double? width = configuration.Width; if (serviceFactory.Create(args => args.Initialize(), diff --git a/Wallet/DropdownEntryCollectionConfiguration.cs b/Wallet/DropdownEntryCollectionConfiguration.cs index ecc544e..137ff17 100644 --- a/Wallet/DropdownEntryCollectionConfiguration.cs +++ b/Wallet/DropdownEntryCollectionConfiguration.cs @@ -3,8 +3,8 @@ namespace Wallet; public record DropdownEntryCollectionConfiguration : - ItemEntryConfiguration + ItemEntryConfiguration { - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public IList Values { get; set; } = new List(); } diff --git a/Wallet/DropdownEntryCollectionViewModel.cs b/Wallet/DropdownEntryCollectionViewModel.cs index a0e801b..f95763d 100644 --- a/Wallet/DropdownEntryCollectionViewModel.cs +++ b/Wallet/DropdownEntryCollectionViewModel.cs @@ -12,8 +12,8 @@ public partial class DropdownEntryCollectionViewModel : ISubscriber subscriber, IDisposer disposer, IEnumerable items, - ItemState state, - ItemEntryConfiguration configuration, + ItemState state, + DropdownEntryCollectionConfiguration configuration, string key, object value, bool isConcealed, @@ -32,7 +32,7 @@ public partial class DropdownEntryCollectionViewModel : IDisposer disposer, IEnumerable items, ItemState state, - ItemEntryConfiguration configuration, + DropdownEntryCollectionConfiguration configuration, string key, object value, bool isConcealed, diff --git a/Wallet/Hyperlink.cs b/Wallet/Hyperlink.cs index 07141bb..35e0b5c 100644 --- a/Wallet/Hyperlink.cs +++ b/Wallet/Hyperlink.cs @@ -1,3 +1,3 @@ namespace Wallet; -public record Hyperlink(string Value); +public record Hyperlink(string? Value); diff --git a/Wallet/HyperlinkEntryConfiguration.cs b/Wallet/HyperlinkEntryConfiguration.cs index 0a231b5..4383e91 100644 --- a/Wallet/HyperlinkEntryConfiguration.cs +++ b/Wallet/HyperlinkEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record HyperlinkEntryConfiguration : - ItemEntryConfiguration -{ - -} + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/HyperlinkEntryViewModel.cs b/Wallet/HyperlinkEntryViewModel.cs index 59cb385..e420d93 100644 --- a/Wallet/HyperlinkEntryViewModel.cs +++ b/Wallet/HyperlinkEntryViewModel.cs @@ -10,7 +10,7 @@ public partial class HyperlinkEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, string value, double width, diff --git a/Wallet/IItemEntryConfiguration.cs b/Wallet/IItemEntryConfiguration.cs index 4270f3e..1cd3a74 100644 --- a/Wallet/IItemEntryConfiguration.cs +++ b/Wallet/IItemEntryConfiguration.cs @@ -1,8 +1,37 @@ -namespace Wallet; +using System.Text.Json.Serialization; -public interface IItemEntryConfiguration +namespace Wallet; + +[JsonDerivedType(typeof(DropdownEntryCollectionConfiguration), typeDiscriminator: "Dropdown")] +[JsonDerivedType(typeof(MaskedTextEntryConfiguration), typeDiscriminator: "MaskedText")] +[JsonDerivedType(typeof(NumberEntryConfiguration), typeDiscriminator: "Number")] +[JsonDerivedType(typeof(PasswordEntryConfiguration), typeDiscriminator: "Password")] +[JsonDerivedType(typeof(TextEntryConfiguration), typeDiscriminator: "Text")] +[JsonDerivedType(typeof(ImageEntryConfiguration), typeDiscriminator: "Images")] +[JsonDerivedType(typeof(AttachmentEntryCollectionConfiguration), typeDiscriminator: "Attachments")] +[JsonDerivedType(typeof(CommentEntryCollectionConfiguration), typeDiscriminator: "Comments")] +[JsonDerivedType(typeof(CurrencyEntryConfiguration), typeDiscriminator: "Currency")] +[JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")] +[JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")] +[JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")] +public interface IItemEntryConfiguration : + IItemEntryConfiguration { string? Label { get; set; } - object? Value { get; set; } + TValue? Value { get; set; } } + +[JsonDerivedType(typeof(DropdownEntryCollectionConfiguration), typeDiscriminator: "Dropdown")] +[JsonDerivedType(typeof(MaskedTextEntryConfiguration), typeDiscriminator: "MaskedText")] +[JsonDerivedType(typeof(NumberEntryConfiguration), typeDiscriminator: "Number")] +[JsonDerivedType(typeof(PasswordEntryConfiguration), typeDiscriminator: "Password")] +[JsonDerivedType(typeof(TextEntryConfiguration), typeDiscriminator: "Text")] +[JsonDerivedType(typeof(ImageEntryConfiguration), typeDiscriminator: "Images")] +[JsonDerivedType(typeof(AttachmentEntryCollectionConfiguration), typeDiscriminator: "Attachments")] +[JsonDerivedType(typeof(CommentEntryCollectionConfiguration), typeDiscriminator: "Comments")] +[JsonDerivedType(typeof(CurrencyEntryConfiguration), typeDiscriminator: "Currency")] +[JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")] +[JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")] +[JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")] +public interface IItemEntryConfiguration; diff --git a/Wallet/ImageEntryConfiguration.cs b/Wallet/ImageEntryConfiguration.cs index 23f7c29..abf7335 100644 --- a/Wallet/ImageEntryConfiguration.cs +++ b/Wallet/ImageEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record ImageEntryConfiguration : - ItemEntryConfiguration -{ - -} + ItemEntryConfiguration; diff --git a/Wallet/ItemConfiguration.cs b/Wallet/ItemConfiguration.cs index af6f21b..2c71916 100644 --- a/Wallet/ItemConfiguration.cs +++ b/Wallet/ItemConfiguration.cs @@ -10,7 +10,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -76,7 +76,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new NumberEntryConfiguration { @@ -155,7 +155,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new CommentEntryCollectionConfiguration { @@ -172,7 +172,7 @@ public record ItemConfiguration { new () { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -193,7 +193,7 @@ public record ItemConfiguration { new ItemSectionConfiguration { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -238,7 +238,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -295,7 +295,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -332,7 +332,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new PasswordEntryConfiguration { @@ -357,7 +357,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -406,7 +406,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -447,7 +447,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -488,7 +488,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -533,7 +533,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -586,7 +586,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -635,7 +635,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -684,7 +684,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -753,7 +753,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -792,7 +792,7 @@ public record ItemConfiguration }, new() { - Entries = new List + Entries = new List { new PinEntryConfiguration { @@ -815,7 +815,7 @@ public record ItemConfiguration }, new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -840,7 +840,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -893,7 +893,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -954,7 +954,7 @@ public record ItemConfiguration { new() { - Entries = new List + Entries = new List { new TextEntryConfiguration { @@ -1004,5 +1004,4 @@ public record ItemConfiguration } } }; - } \ No newline at end of file diff --git a/Wallet/ItemEntryCollectionViewModel.cs b/Wallet/ItemEntryCollectionViewModel.cs index e5a40cf..726f1a7 100644 --- a/Wallet/ItemEntryCollectionViewModel.cs +++ b/Wallet/ItemEntryCollectionViewModel.cs @@ -7,13 +7,14 @@ namespace Wallet; public partial class ItemEntryCollectionViewModel : ObservableCollection, IItemEntryViewModel, + IHandler, bool>, INotificationHandler>, INotificationHandler>, INotificationHandler> where TItem : notnull, IDisposable { - private readonly ItemEntryConfiguration configuration; + private readonly IItemEntryConfiguration configuration; [ObservableProperty] private bool isConcealed; @@ -34,7 +35,7 @@ public partial class ItemEntryCollectionViewModel : ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, TValue value, bool isConcealed, @@ -59,7 +60,7 @@ public partial class ItemEntryCollectionViewModel : IDisposer disposer, IEnumerable items, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, TValue value, bool isConcealed, @@ -95,12 +96,15 @@ public partial class ItemEntryCollectionViewModel : return Task.CompletedTask; } - protected override void OnValueChanged() + public async Task Handle(ValidateEventArgs args, + CancellationToken cancellationToken) { if (configuration is not null) { configuration.Value = Value; } + + return await Task.FromResult(true); } [RelayCommand] diff --git a/Wallet/ItemEntryConfiguration.cs b/Wallet/ItemEntryConfiguration.cs index 1169583..77a1e0f 100644 --- a/Wallet/ItemEntryConfiguration.cs +++ b/Wallet/ItemEntryConfiguration.cs @@ -14,15 +14,15 @@ namespace Wallet; [JsonDerivedType(typeof(DateEntryConfiguration), typeDiscriminator: "Date")] [JsonDerivedType(typeof(HyperlinkEntryConfiguration), typeDiscriminator: "Hyperlink")] [JsonDerivedType(typeof(PinEntryConfiguration), typeDiscriminator: "Pin")] -public record ItemEntryConfiguration : - IItemEntryConfiguration +public record ItemEntryConfiguration : + IItemEntryConfiguration { - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public string? Label { get; set; } - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public object? Value { get; set; } + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public TValue? Value { get; set; } - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] public double? Width { get; set; } = 296; } \ No newline at end of file diff --git a/Wallet/ItemEntryViewModel.cs b/Wallet/ItemEntryViewModel.cs index 9de54f7..525e229 100644 --- a/Wallet/ItemEntryViewModel.cs +++ b/Wallet/ItemEntryViewModel.cs @@ -7,11 +7,25 @@ namespace Wallet; public partial class ItemEntryViewModel : Observable, IItemEntryViewModel, + IHandler, bool>, INotificationHandler>, INotificationHandler>, INotificationHandler> - where TValue : notnull { + private readonly IItemEntryConfiguration configuration; + + [ObservableProperty] + private bool isConcealed; + + [ObservableProperty] + private bool isRevealed; + + [ObservableProperty] + private ItemState state; + + [ObservableProperty] + private double width; + public ItemEntryViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, @@ -19,7 +33,7 @@ public partial class ItemEntryViewModel : ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, TValue value, bool isConcealed, @@ -36,20 +50,6 @@ public partial class ItemEntryViewModel : Track(nameof(Value), () => Value, x => Value = x); } - private readonly ItemEntryConfiguration configuration; - - [ObservableProperty] - private bool isConcealed; - - [ObservableProperty] - private bool isRevealed; - - [ObservableProperty] - private ItemState state; - - [ObservableProperty] - private double width; - public Task Handle(UpdateEventArgs args) => Task.FromResult(State = ItemState.Write); @@ -69,20 +69,23 @@ public partial class ItemEntryViewModel : return Task.CompletedTask; } - protected override void OnValueChanged() + public async Task Handle(ValidateEventArgs args, + CancellationToken cancellationToken) { if (configuration is not null) { configuration.Value = Value; } + + return await Task.FromResult(true); } + [RelayCommand] + private void Copy() => Publisher.Publish(Write.As(new Clipboard($"{Value}"))); + [RelayCommand] private void Hide() => IsRevealed = false; [RelayCommand] private void Reveal() => IsRevealed = true; - - [RelayCommand] - private void Copy() => Publisher.Publish(Write.As(new Clipboard($"{Value}"))); } \ No newline at end of file diff --git a/Wallet/ItemHeaderViewModel.cs b/Wallet/ItemHeaderViewModel.cs index 7ca28d4..8c7ad5a 100644 --- a/Wallet/ItemHeaderViewModel.cs +++ b/Wallet/ItemHeaderViewModel.cs @@ -1,8 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using System.Xml.Linq; using Toolkit.Foundation; -using Wallet.Data; namespace Wallet; diff --git a/Wallet/ItemSectionConfiguration.cs b/Wallet/ItemSectionConfiguration.cs index 6d636be..c0b4c84 100644 --- a/Wallet/ItemSectionConfiguration.cs +++ b/Wallet/ItemSectionConfiguration.cs @@ -2,5 +2,5 @@ public record ItemSectionConfiguration { - public IList Entries { get; set; } = new List(); + public IList Entries { get; set; } = new List(); } \ No newline at end of file diff --git a/Wallet/MaskedTextEntryConfiguration.cs b/Wallet/MaskedTextEntryConfiguration.cs index eadfe4f..d66e1b7 100644 --- a/Wallet/MaskedTextEntryConfiguration.cs +++ b/Wallet/MaskedTextEntryConfiguration.cs @@ -3,7 +3,7 @@ namespace Wallet; public record MaskedTextEntryConfiguration : - ItemEntryConfiguration + ItemEntryConfiguration { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public string? Pattern { get; set; } diff --git a/Wallet/MaskedTextEntryViewModel.cs b/Wallet/MaskedTextEntryViewModel.cs index ffe713f..a5805df 100644 --- a/Wallet/MaskedTextEntryViewModel.cs +++ b/Wallet/MaskedTextEntryViewModel.cs @@ -10,7 +10,7 @@ public partial class MaskedTextEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string pattern, string key, string value, diff --git a/Wallet/NumberEntryConfiguration.cs b/Wallet/NumberEntryConfiguration.cs index 97486d8..bf13e3d 100644 --- a/Wallet/NumberEntryConfiguration.cs +++ b/Wallet/NumberEntryConfiguration.cs @@ -1,7 +1,7 @@ namespace Wallet; public record NumberEntryConfiguration : - ItemEntryConfiguration + ItemEntryConfiguration { public int MinLength { get; set; } diff --git a/Wallet/PasswordEntryConfiguration.cs b/Wallet/PasswordEntryConfiguration.cs index 4275dc0..5792aab 100644 --- a/Wallet/PasswordEntryConfiguration.cs +++ b/Wallet/PasswordEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record PasswordEntryConfiguration : - ItemEntryConfiguration -{ - -} \ No newline at end of file + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/PasswordEntryViewModel.cs b/Wallet/PasswordEntryViewModel.cs index f6bfa79..de5451d 100644 --- a/Wallet/PasswordEntryViewModel.cs +++ b/Wallet/PasswordEntryViewModel.cs @@ -9,7 +9,7 @@ public partial class PasswordEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + IItemEntryConfiguration configuration, string key, string value, bool isConcealed, diff --git a/Wallet/PinEntryConfiguration.cs b/Wallet/PinEntryConfiguration.cs index 173f557..2eae0fb 100644 --- a/Wallet/PinEntryConfiguration.cs +++ b/Wallet/PinEntryConfiguration.cs @@ -1,7 +1,7 @@ namespace Wallet; public record PinEntryConfiguration : - ItemEntryConfiguration + ItemEntryConfiguration { public int Minimum { get; set; } diff --git a/Wallet/PinEntryViewModel.cs b/Wallet/PinEntryViewModel.cs index 049771e..3759b24 100644 --- a/Wallet/PinEntryViewModel.cs +++ b/Wallet/PinEntryViewModel.cs @@ -9,7 +9,7 @@ public partial class PinEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + PinEntryConfiguration configuration, string key, string value, double width, diff --git a/Wallet/TextEntryConfiguration.cs b/Wallet/TextEntryConfiguration.cs index 80d7fb6..06c4dcf 100644 --- a/Wallet/TextEntryConfiguration.cs +++ b/Wallet/TextEntryConfiguration.cs @@ -1,7 +1,4 @@ namespace Wallet; public record TextEntryConfiguration : - ItemEntryConfiguration -{ - -} + ItemEntryConfiguration; \ No newline at end of file diff --git a/Wallet/TextEntryViewModel.cs b/Wallet/TextEntryViewModel.cs index 7e3955a..e5d3cbc 100644 --- a/Wallet/TextEntryViewModel.cs +++ b/Wallet/TextEntryViewModel.cs @@ -9,7 +9,7 @@ public partial class TextEntryViewModel(IServiceProvider provider, ISubscriber subscriber, IDisposer disposer, ItemState state, - ItemEntryConfiguration configuration, + TextEntryConfiguration configuration, string key, string value, bool isConcealed,