diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogService.cs index 18cc541..cddfe02 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/GachaLogService.cs @@ -38,6 +38,15 @@ internal sealed partial class GachaLogService : IGachaLogService } } + public async ValueTask> RefreshArchiveCollectionAsync() + { + using (await archivesLock.LockAsync().ConfigureAwait(false)) + { + archives = null; + return archives = gachaLogRepository.GetGachaArchiveCollection().ToAdvancedDbCollectionView(serviceProvider); + } + } + public async ValueTask GetStatisticsAsync(GachaLogServiceMetadataContext context, GachaArchive archive) { using (ValueStopwatch.MeasureExecution(logger)) diff --git a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/IGachaLogService.cs b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/IGachaLogService.cs index 6775157..47dfc9a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/IGachaLogService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/GachaLog/IGachaLogService.cs @@ -22,4 +22,6 @@ internal interface IGachaLogService ValueTask RemoveArchiveAsync(GachaArchive archive); ValueTask> GetArchiveCollectionAsync(); + + ValueTask> RefreshArchiveCollectionAsync(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Service/UIGF/AbstractUIGF40ImportService.cs b/src/Snap.Hutao/Snap.Hutao/Service/UIGF/AbstractUIGF40ImportService.cs index 27edc31..1ca2e57 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/UIGF/AbstractUIGF40ImportService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/UIGF/AbstractUIGF40ImportService.cs @@ -4,6 +4,7 @@ using Snap.Hutao.Core.ExceptionService; using Snap.Hutao.Model.Entity; using Snap.Hutao.Model.InterChange.GachaLog; using Snap.Hutao.Service.GachaLog; +using Snap.Hutao.ViewModel.GachaLog; using Snap.Hutao.Web.Hoyolab.Hk4e.Event.GachaInfo; using System.Collections.Immutable; @@ -13,6 +14,7 @@ internal abstract partial class AbstractUIGF40ImportService : IUIGFImportService { private readonly IServiceProvider serviceProvider; private readonly ITaskContext taskContext; + private readonly IMessenger messenger; [GeneratedConstructor] public partial AbstractUIGF40ImportService(IServiceProvider serviceProvider); @@ -21,6 +23,7 @@ internal abstract partial class AbstractUIGF40ImportService : IUIGFImportService { await taskContext.SwitchToBackgroundAsync(); ImportGachaArchives(importOptions.UIGF.Hk4e, importOptions.GachaArchiveUids); + messenger.Send(GachaLogImportedMessage.Empty); } private void ImportGachaArchives(ImmutableArray> entries, HashSet uids) diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogImportedMessage.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogImportedMessage.cs new file mode 100644 index 0000000..a63fd12 --- /dev/null +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogImportedMessage.cs @@ -0,0 +1,13 @@ +// Copyright (c) DGP Studio. All rights reserved. +// Licensed under the MIT license. + +namespace Snap.Hutao.ViewModel.GachaLog; + +internal sealed class GachaLogImportedMessage +{ + public static readonly GachaLogImportedMessage Empty = new(); + + private GachaLogImportedMessage() + { + } +} diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogViewModel.cs index 928697a..ee2e529 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/GachaLogViewModel.cs @@ -26,7 +26,7 @@ namespace Snap.Hutao.ViewModel.GachaLog; [BindableCustomPropertyProvider] [Service(ServiceLifetime.Scoped)] -internal sealed partial class GachaLogViewModel : Abstraction.ViewModel +internal sealed partial class GachaLogViewModel : Abstraction.ViewModel, IRecipient { private readonly IContentDialogFactory contentDialogFactory; private readonly IServiceProvider serviceProvider; @@ -127,6 +127,22 @@ internal sealed partial class GachaLogViewModel : Abstraction.ViewModel UpdateStatisticsAsync(Archives?.CurrentItem).SafeForget(); } + public async void Receive(GachaLogImportedMessage message) + { + await RefreshArchiveCollectionAsync().ConfigureAwait(false); + } + + private async ValueTask RefreshArchiveCollectionAsync() + { + using (await EnterCriticalSectionAsync().ConfigureAwait(false)) + { + IAdvancedDbCollectionView archives = await gachaLogService.RefreshArchiveCollectionAsync().ConfigureAwait(false); + await taskContext.SwitchToMainThreadAsync(); + Archives = archives; + Archives.MoveCurrentTo(Archives.Source.SelectedOrFirstOrDefault()); + } + } + [Command("RefreshByWebCacheCommand")] private async Task RefreshByWebCacheAsync() {