Initial support for masking

This commit is contained in:
TheXamlGuy
2024-06-06 23:01:23 +01:00
parent c8474e31c2
commit 05a6cd4540
16 changed files with 41 additions and 29 deletions
+10 -3
View File
@@ -98,18 +98,25 @@ public record ItemConfiguration
new DropdownEntryConfiguration
{
Label = "Type",
Values = ["American Express", "Discover", "Maestro", "Mastercard", "Visa"],
},
new MaskedTextEntryConfiguration
{
Label = "Card number"
Label = "Card number",
Pattern = "0000-0000-0000-0000",
Value = "____-____-____-____",
},
new MaskedTextEntryConfiguration
{
Label = "Expiry date"
Label = "Expiry date",
Pattern = "00/00",
Value = "__/__",
},
new MaskedTextEntryConfiguration
{
Label = "Card verification code"
Label = "Card verification code",
Pattern = "000",
Value = "___",
},
}
}
+2 -1
View File
@@ -8,6 +8,7 @@ public partial class ItemDropdownEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string? key = default,
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
@@ -10,7 +10,7 @@ public class ItemDropdownEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is DropdownEntryConfiguration configuration)
{
if (serviceFactory.Create<ItemDropdownEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
if (serviceFactory.Create<ItemDropdownEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
is ItemDropdownEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -9,6 +9,7 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string? key = default,
object? value = default) :
@@ -19,7 +20,7 @@ public partial class ItemEntryViewModel(IServiceProvider provider,
INotificationHandler<CancelEventArgs<Item>>
{
[ObservableProperty]
private ItemState state = ItemState.Read;
private ItemState state = state;
protected override void OnValueChanged() =>
configuration.Value = Value;
+9 -2
View File
@@ -1,4 +1,5 @@
using Toolkit.Foundation;
using CommunityToolkit.Mvvm.ComponentModel;
using Toolkit.Foundation;
namespace Bitvault;
@@ -8,6 +9,12 @@ public partial class ItemMaskedTextEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string? pattern,
string? key = default,
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value)
{
[ObservableProperty]
private string? pattern = pattern;
}
@@ -10,7 +10,7 @@ public class ItemMaskedTextEntryViewModelHandler(IServiceFactory serviceFactory)
{
if (args.Value is MaskedTextEntryConfiguration configuration)
{
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
if (serviceFactory.Create<ItemMaskedTextEntryViewModel>([.. args.Parameters, configuration, configuration.Pattern, configuration.Label, configuration.Value])
is ItemMaskedTextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -8,6 +8,7 @@ public partial class ItemPasswordEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string? key = default,
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
@@ -10,7 +10,7 @@ public class ItemPasswordEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is PasswordEntryConfiguration configuration)
{
if (serviceFactory.Create<ItemPasswordEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
if (serviceFactory.Create<ItemPasswordEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
is ItemPasswordEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
+2 -1
View File
@@ -8,6 +8,7 @@ public partial class ItemTextEntryViewModel(IServiceProvider provider,
IPublisher publisher,
ISubscription subscriber,
IDisposer disposer,
ItemState state,
ItemEntryConfiguration configuration,
string? key = default,
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, configuration, key, value);
object? value = default) : ItemEntryViewModel(provider, factory, mediator, publisher, subscriber, disposer, state, configuration, key, value);
+1 -1
View File
@@ -10,7 +10,7 @@ public class ItemTextEntryViewModelHandler(IServiceFactory serviceFactory) :
{
if (args.Value is TextEntryConfiguration configuration)
{
if (serviceFactory.Create<ItemTextEntryViewModel>(configuration, configuration.Label, configuration.Value ?? "")
if (serviceFactory.Create<ItemTextEntryViewModel>([.. args.Parameters, configuration, configuration.Label, configuration.Value ?? ""])
is ItemTextEntryViewModel viewModel)
{
return Task.FromResult<IItemEntryViewModel?>(viewModel);
@@ -31,7 +31,7 @@ public class SynchronizeItemContentFromCategoryViewModelHandler(IItemConfigurati
Type messageType = typeof(CreateEventArgs<>).MakeGenericType(entryConfiguration.GetType());
ConstructorInfo? constructor = messageType.GetConstructor([entryConfiguration.GetType(), typeof(object[])]);
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { sectionViewModel } }) is object message)
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { ItemState.New } }) is object message)
{
if (await mediator.Handle<object, IItemEntryViewModel?>(message,
entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)
@@ -34,7 +34,7 @@ public class SynchronizeItemContentViewModelHandler(IDecoratorService<Item<(Guid
Type messageType = typeof(CreateEventArgs<>).MakeGenericType(entryConfiguration.GetType());
ConstructorInfo? constructor = messageType.GetConstructor([entryConfiguration.GetType(), typeof(object[])]);
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { sectionViewModel } }) is object message)
if (constructor?.Invoke(new object[] { entryConfiguration, new object[] { ItemState.Read } }) is object message)
{
if (await mediator.Handle<object, IItemEntryViewModel?>(message,
entryConfiguration.GetType().Name) is IItemEntryViewModel entryViewModel)