Partial work on WalletActivityService
This commit is contained in:
@@ -73,6 +73,8 @@ public partial class App : Application
|
|||||||
services.AddTransient(_ =>
|
services.AddTransient(_ =>
|
||||||
provider.GetServices<IConfigurationDescriptor<ItemConfiguration>>());
|
provider.GetServices<IConfigurationDescriptor<ItemConfiguration>>());
|
||||||
|
|
||||||
|
services.AddInitializer<WalletActivityService>();
|
||||||
|
|
||||||
services.AddTransient<IWalletFactory, WalletFactory>();
|
services.AddTransient<IWalletFactory, WalletFactory>();
|
||||||
|
|
||||||
services.AddTransient<IKeyGenerator, KeyGenerator>();
|
services.AddTransient<IKeyGenerator, KeyGenerator>();
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public interface IWalletActivityService :
|
||||||
|
IInitialization,
|
||||||
|
IDisposable;
|
||||||
@@ -28,8 +28,7 @@ public class ItemCreatedHandler(IServiceProvider serviceProvider,
|
|||||||
int index = cache.IndexOf(cachedItem);
|
int index = cache.IndexOf(cachedItem);
|
||||||
decoratorService.Set(cachedItem);
|
decoratorService.Set(cachedItem);
|
||||||
|
|
||||||
publisher.Publish(Insert.As(index, viewModel),
|
publisher.Publish(Insert.As(index, viewModel), "All");
|
||||||
nameof(ItemNavigationCollectionViewModel));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using Toolkit.Foundation;
|
||||||
|
using Timer = System.Threading.Timer;
|
||||||
|
|
||||||
|
namespace Wallet;
|
||||||
|
|
||||||
|
public class WalletActivityService(ISubscriber subscriber,
|
||||||
|
IPublisher publisher) :
|
||||||
|
IWalletActivityService,
|
||||||
|
INotificationHandler<ActivatedEventArgs<Wallet>>,
|
||||||
|
INotificationHandler<DeactivatedEventArgs<Wallet>>,
|
||||||
|
INotificationHandler<OpenedEventArgs<Wallet>>,
|
||||||
|
INotificationHandler<ClosedEventArgs<Wallet>>
|
||||||
|
{
|
||||||
|
private bool isOpen;
|
||||||
|
private readonly int timeout = 10000;
|
||||||
|
private Timer? timer;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
timer?.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(ActivatedEventArgs<Wallet> args)
|
||||||
|
{
|
||||||
|
if (isOpen)
|
||||||
|
{
|
||||||
|
timer?.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(DeactivatedEventArgs<Wallet> args)
|
||||||
|
{
|
||||||
|
if (isOpen)
|
||||||
|
{
|
||||||
|
timer?.Change(timeout, Timeout.Infinite);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(OpenedEventArgs<Wallet> args)
|
||||||
|
{
|
||||||
|
isOpen = true;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task Handle(ClosedEventArgs<Wallet> args)
|
||||||
|
{
|
||||||
|
isOpen = false;
|
||||||
|
timer?.Change(Timeout.Infinite, Timeout.Infinite);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
subscriber.Subscribe(this);
|
||||||
|
timer = new Timer(OnTimedEvent, null, Timeout.Infinite, Timeout.Infinite);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimedEvent(object? state)
|
||||||
|
{
|
||||||
|
if (isOpen)
|
||||||
|
{
|
||||||
|
publisher.PublishUI(new ClosedEventArgs<Wallet>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user