Skip to content

Commit

Permalink
impl #1100
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed May 1, 2024
1 parent c02e7b0 commit b0328bd
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ internal sealed partial class SettingEntry
public const string ElementTheme = "ElementTheme";
public const string BackgroundImageType = "BackgroundImageType";

public const string IsAutoUploadGachaLogEnabled = "IsAutoUploadGachaLogEnabled";
public const string IsAutoUploadSpiralAbyssRecordEnabled = "IsAutoUploadSpiralAbyssRecordEnabled";

public const string AnnouncementRegion = "AnnouncementRegion";

public const string IsEmptyHistoryWishVisible = "IsEmptyHistoryWishVisible";
Expand Down
18 changes: 18 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,24 @@
<data name="ViewpageSettingHomeHeader" xml:space="preserve">
<value>主页</value>
</data>
<data name="ViewPageSettingHutaoCloudAutoUploadDescription" xml:space="preserve">
<value>登录胡桃通行证后自动上传至胡桃云</value>
</data>
<data name="ViewPageSettingHutaoCloudAutoUploadHeader" xml:space="preserve">
<value>自动上传</value>
</data>
<data name="ViewPageSettingHutaoCloudGachaLogAutoUploadDescription" xml:space="preserve">
<value>刷新祈愿记录后自动上传至胡桃云,需要有效的胡桃云服务</value>
</data>
<data name="ViewPageSettingHutaoCloudGachaLogAutoUploadHeader" xml:space="preserve">
<value>自动上传祈愿记录</value>
</data>
<data name="ViewPageSettingHutaoCloudSpiralAbyssAutoUploadDescription" xml:space="preserve">
<value>刷新深境螺旋数据后自动上传至胡桃云</value>
</data>
<data name="ViewPageSettingHutaoCloudSpiralAbyssAutoUploadHeader" xml:space="preserve">
<value>自动上传深境螺旋数据</value>
</data>
<data name="ViewPageSettingHutaoPassportDangerZoneDescription" xml:space="preserve">
<value>三思而后行</value>
</data>
Expand Down
14 changes: 14 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Snap.Hutao.Service;
[Injection(InjectAs.Singleton)]
internal sealed partial class AppOptions : DbStoreOptions
{
private bool? isAutoUploadGachaLogEnabled;
private bool? isAutoUploadSpiralAbyssRecordEnabled;
private bool? isEmptyHistoryWishVisible;
private bool? isUnobtainedWishItemVisible;
private BackdropType? backdropType;
Expand All @@ -23,6 +25,18 @@ internal sealed partial class AppOptions : DbStoreOptions
private Region? region;
private string? geetestCustomCompositeUrl;

public bool IsAutoUploadGachaLogEnabled
{
get => GetOption(ref isAutoUploadGachaLogEnabled, SettingEntry.IsAutoUploadGachaLogEnabled, false);
set => SetOption(ref isAutoUploadGachaLogEnabled, SettingEntry.IsAutoUploadGachaLogEnabled, value);
}

public bool IsAutoUploadSpiralAbyssRecordEnabled
{
get => GetOption(ref isAutoUploadSpiralAbyssRecordEnabled, SettingEntry.IsAutoUploadSpiralAbyssRecordEnabled, false);
set => SetOption(ref isAutoUploadSpiralAbyssRecordEnabled, SettingEntry.IsAutoUploadSpiralAbyssRecordEnabled, value);
}

public bool IsEmptyHistoryWishVisible
{
get => GetOption(ref isEmptyHistoryWishVisible, SettingEntry.IsEmptyHistoryWishVisible, false);
Expand Down
16 changes: 16 additions & 0 deletions src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
</ScrollViewer>
<ScrollViewer>
<cwc:SettingsExpander
Description="{shcm:ResourceString Name=ViewPageSettingHutaoCloudAutoUploadDescription}"
Header="{shcm:ResourceString Name=ViewPageSettingHutaoCloudAutoUploadHeader}"
HeaderIcon="{shcm:FontIcon Glyph=&#xE898;}"
IsExpanded="True">
<cwc:SettingsExpander.Items>
<cwc:SettingsCard Description="{shcm:ResourceString Name=ViewPageSettingHutaoCloudGachaLogAutoUploadDescription}" Header="{shcm:ResourceString Name=ViewPageSettingHutaoCloudGachaLogAutoUploadHeader}">
<ToggleSwitch IsOn="{Binding AppOptions.IsAutoUploadGachaLogEnabled, Mode=TwoWay}"/>
</cwc:SettingsCard>
<cwc:SettingsCard Description="{shcm:ResourceString Name=ViewPageSettingHutaoCloudSpiralAbyssAutoUploadDescription}" Header="{shcm:ResourceString Name=ViewPageSettingHutaoCloudSpiralAbyssAutoUploadHeader}">
<ToggleSwitch IsOn="{Binding AppOptions.IsAutoUploadSpiralAbyssRecordEnabled, Mode=TwoWay}"/>
</cwc:SettingsCard>
</cwc:SettingsExpander.Items>
</cwc:SettingsExpander>
</ScrollViewer>
</StackPanel>
</Border>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Snap.Hutao.Factory.Progress;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.InterChange.GachaLog;
using Snap.Hutao.Service;
using Snap.Hutao.Service.GachaLog;
using Snap.Hutao.Service.GachaLog.QueryProvider;
using Snap.Hutao.Service.Notification;
Expand Down Expand Up @@ -38,6 +39,7 @@ internal sealed partial class GachaLogViewModel : Abstraction.ViewModel
private readonly IInfoBarService infoBarService;
private readonly JsonSerializerOptions options;
private readonly ITaskContext taskContext;
private readonly AppOptions appOptions;

private ObservableCollection<GachaArchive>? archives;
private GachaArchive? selectedArchive;
Expand Down Expand Up @@ -198,6 +200,11 @@ private async ValueTask RefreshInternalAsync(RefreshOption option)
{
await SetSelectedArchiveAndUpdateStatisticsAsync(gachaLogService.CurrentArchive, true).ConfigureAwait(false);
await hideToken.DisposeAsync().ConfigureAwait(false);

if (HutaoCloudViewModel.Options.IsCloudServiceAllowed && appOptions.IsAutoUploadGachaLogEnabled)
{
await HutaoCloudViewModel.UploadAsync(gachaLogService.CurrentArchive).ConfigureAwait(false);
}
}
else
{
Expand Down
58 changes: 29 additions & 29 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/GachaLog/HutaoCloudViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ internal sealed partial class HutaoCloudViewModel : Abstraction.ViewModel
/// </summary>
internal ICommand RetrieveCommand { get; set; }

[Command("UploadCommand")]
internal async Task UploadAsync(GachaArchive? gachaArchive)
{
if (gachaArchive is not null)
{
ContentDialog dialog = await contentDialogFactory
.CreateForIndeterminateProgressAsync(SH.ViewModelGachaLogUploadToHutaoCloudProgress)
.ConfigureAwait(false);

bool isOk;
string message;

using (await dialog.BlockAsync(taskContext).ConfigureAwait(false))
{
(isOk, message) = await hutaoCloudService.UploadGachaItemsAsync(gachaArchive).ConfigureAwait(false);
}

if (isOk)
{
infoBarService.Success(message);
await RefreshUidCollectionAsync().ConfigureAwait(false);
}
else
{
infoBarService.Warning(message);
}
}
}

/// <summary>
/// 异步获取祈愿记录
/// </summary>
Expand Down Expand Up @@ -77,35 +106,6 @@ private static async Task NavigateToAfdianSkuAsync()
await Windows.System.Launcher.LaunchUriAsync("https://afdian.net/item/80d3b9decf9011edb5f452540025c377".ToUri());
}

[Command("UploadCommand")]
private async Task UploadAsync(GachaArchive? gachaArchive)
{
if (gachaArchive is not null)
{
ContentDialog dialog = await contentDialogFactory
.CreateForIndeterminateProgressAsync(SH.ViewModelGachaLogUploadToHutaoCloudProgress)
.ConfigureAwait(false);

bool isOk;
string message;

using (await dialog.BlockAsync(taskContext).ConfigureAwait(false))
{
(isOk, message) = await hutaoCloudService.UploadGachaItemsAsync(gachaArchive).ConfigureAwait(false);
}

if (isOk)
{
infoBarService.Success(message);
await RefreshUidCollectionAsync().ConfigureAwait(false);
}
else
{
infoBarService.Warning(message);
}
}
}

[Command("DeleteCommand")]
private async Task DeleteAsync(string? uid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CommunityToolkit.Mvvm.Messaging;
using Snap.Hutao.Factory.ContentDialog;
using Snap.Hutao.Message;
using Snap.Hutao.Service;
using Snap.Hutao.Service.Hutao;
using Snap.Hutao.Service.Navigation;
using Snap.Hutao.Service.Notification;
Expand Down Expand Up @@ -37,6 +38,7 @@ internal sealed partial class SpiralAbyssRecordViewModel : Abstraction.ViewModel
private readonly IUserService userService;
private readonly HutaoDatabaseViewModel hutaoDatabaseViewModel;
private readonly HutaoUserOptions hutaoUserOptions;
private readonly AppOptions appOptions;

private ObservableCollection<SpiralAbyssView>? spiralAbyssEntries;
private SpiralAbyssView? selectedView;
Expand Down Expand Up @@ -127,6 +129,11 @@ await spiralAbyssRecordService

await taskContext.SwitchToMainThreadAsync();
SelectedView = SpiralAbyssEntries.FirstOrDefault(s => s.Engaged);

if (hutaoUserOptions.IsLoggedIn && appOptions.IsAutoUploadSpiralAbyssRecordEnabled)
{
await UploadSpiralAbyssRecordCoreAsync(userAndUid).ConfigureAwait(false);
}
}
}
}
Expand All @@ -150,30 +157,35 @@ private async Task UploadSpiralAbyssRecordAsync()
}
}

SimpleRecord? record = await spiralAbyssClient.GetPlayerRecordAsync(userAndUid).ConfigureAwait(false);
if (record is not null)
{
Web.Response.Response response = await spiralAbyssClient.UploadRecordAsync(record).ConfigureAwait(false);
await UploadSpiralAbyssRecordCoreAsync(userAndUid).ConfigureAwait(false);
}
else
{
infoBarService.Warning(SH.MustSelectUserAndUid);
}
}

private async ValueTask UploadSpiralAbyssRecordCoreAsync(UserAndUid userAndUid)
{
SimpleRecord? record = await spiralAbyssClient.GetPlayerRecordAsync(userAndUid).ConfigureAwait(false);
if (record is not null)
{
Web.Response.Response response = await spiralAbyssClient.UploadRecordAsync(record).ConfigureAwait(false);

if (response is { ReturnCode: 0 })
if (response is { ReturnCode: 0 })
{
if (response is ILocalizableResponse localizableResponse)
{
if (response is ILocalizableResponse localizableResponse)
{
infoBarService.Success(localizableResponse.GetLocalizationMessage());
}
infoBarService.Success(localizableResponse.GetLocalizationMessage());
}
else
}
else
{
if (response is ILocalizableResponse localizableResponse)
{
if (response is ILocalizableResponse localizableResponse)
{
infoBarService.Warning(localizableResponse.GetLocalizationMessage());
}
infoBarService.Warning(localizableResponse.GetLocalizationMessage());
}
}
}
else
{
infoBarService.Warning(SH.MustSelectUserAndUid);
}
}
}
}

0 comments on commit b0328bd

Please sign in to comment.