This commit is contained in:
TheXamlGuy
2024-07-10 14:36:09 +01:00
parent 5ce415eb3d
commit 3dfe0ce59b
5 changed files with 73 additions and 33 deletions
+20 -4
View File
@@ -11,10 +11,26 @@ public class MainViewModelActivationHandler(IPublisher publisher,
{
bool selected = true;
foreach (IComponentHost Wallet in Wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
is IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null))
foreach (IComponentHost Wallet in Wallets.OrderBy(x =>
{
if (Wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
IConfigurationDescriptor<WalletConfiguration> descriptor = x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>();
return descriptor?.Name;
},
Comparer<string?>.Create((x, y) =>
{
bool xIsNumeric = int.TryParse(x, out int xNum);
bool yIsNumeric = int.TryParse(y, out int yNum);
return (xIsNumeric, yIsNumeric) switch
{
(true, true) => xNum.CompareTo(yNum),
(true, false) => -1,
(false, true) => 1,
_ => string.Compare(x, y, StringComparison.Ordinal)
};
})))
{
if (Wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>()
is IConfigurationDescriptor<WalletConfiguration> configuration)
{
if (Wallet.Services.GetRequiredService<IServiceFactory>() is IServiceFactory factory)
@@ -23,7 +39,7 @@ public class MainViewModelActivationHandler(IPublisher publisher,
Wallet.Services.GetRequiredService<IDecoratorService<ProfileImage<IImageDescriptor>>>();
ProfileImage<IImageDescriptor>? profileImage = profileImageDecorator.Value;
if (factory.Create<WalletNavigationViewModel>(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected)
if (factory.Create<WalletNavigationViewModel>(args => args.Initialize(), configuration.Name, profileImage?.Value ?? null, selected)
is WalletNavigationViewModel viewModel)
{
publisher.Publish(Create.As<IMainNavigationViewModel>(viewModel),
+13
View File
@@ -50,4 +50,17 @@ public partial class OpenWalletViewModel :
}
}
}
//public override async Task OnActivated()
//{
// Publisher.Publish(Activated.As<Wallet>());
// await base.OnActivated();
//}
//public override async Task OnDeactivated()
//{
// Publisher.Publish(Deactivated.As<Wallet>());
// await base.OnDeactivated();
//}
}
+21 -2
View File
@@ -11,8 +11,27 @@ public class WalletActivatedHandler(IWalletHostCollection wallets,
{
if (args.Sender is Wallet<IComponentHost> wallet && wallet.Value is IComponentHost host)
{
List<IComponentHost> sortedWallets = [.. wallets.OrderBy(x => x.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>() is
IConfigurationDescriptor<WalletConfiguration> descriptor ? descriptor.Name : null)];
List<IComponentHost> sortedWallets =
[
.. wallets.OrderBy(wallet =>
{
var descriptor = wallet.Services.GetRequiredService<IConfigurationDescriptor<WalletConfiguration>>();
return descriptor?.Name;
},
Comparer<string?>.Create((x, y) =>
{
bool xIsNumeric = int.TryParse(x, out int xNum);
bool yIsNumeric = int.TryParse(y, out int yNum);
return (xIsNumeric, yIsNumeric) switch
{
(true, true) => xNum.CompareTo(yNum),
(true, false) => -1,
(false, true) => 1,
_ => string.Compare(x, y, StringComparison.Ordinal)
};
})),
];
int index = sortedWallets.IndexOf(host);