Skip to content

Commit

Permalink
feat: export record
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Jul 24, 2024
1 parent c3f8172 commit 0edf8a5
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 33 deletions.
27 changes: 27 additions & 0 deletions Hollow/Languages/Lang.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Hollow/Languages/Lang.resx
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@
<data name="SignalSearch_Detailed_SingleOrConsecutive_Consecutive" xml:space="preserve">
<value>Consecutive - {0} poll</value>
</data>
<data name="SignalSearch_Export_Tip" xml:space="preserve">
<value>Select the UIDs to be exported:</value>
</data>
<data name="Dialog_Ok" xml:space="preserve">
<value>Ok</value>
</data>
<data name="Dialog_Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Hollow/Languages/Lang.zh-cn.resx
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,13 @@
<data name="SignalSearch_Detailed_SingleOrConsecutive_Consecutive" xml:space="preserve">
<value>十连 - 第{0}抽</value>
</data>
<data name="SignalSearch_Export_Tip" xml:space="preserve">
<value>选择需要导出的 UIDs:</value>
</data>
<data name="Dialog_Ok" xml:space="preserve">
<value>确认</value>
</data>
<data name="Dialog_Cancel" xml:space="preserve">
<value>取消</value>
</data>
</root>
18 changes: 17 additions & 1 deletion Hollow/ViewModels/Pages/SignalSearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Hollow.Abstractions.Models;
Expand All @@ -17,6 +19,7 @@
using Hollow.Models.Pages.SignalSearch;
using Hollow.Services.GachaService;
using Hollow.Services.NavigationService;
using Hollow.Views;
using Hollow.Views.Controls;
using Hollow.Views.Dialogs;
using Hollow.Views.Pages;
Expand Down Expand Up @@ -105,7 +108,20 @@ private async Task LoadGachaRecords(string? updatedUid = null)
[RelayCommand]
private void ExportRecords()
{
HollowHost.ShowDialog(new StandardDialog());
HollowHost.ShowDialog(new ExportDialog(UidList, SelectedUidListCallback));
}

private async void SelectedUidListCallback(string[] selectedUidList)
{
if (selectedUidList.Length == 0) return;
var gachaRecords = new GachaRecords { Info = { ExportAppVersion = AppInfo.AppVersion, ExportTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() }, Profiles = selectedUidList.Select(uid => _gachaProfiles![uid]).ToList() };

var topLevel = TopLevel.GetTopLevel(App.GetService<MainWindow>());
var file = await topLevel!.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions { Title = "Save Text File", SuggestedFileName = $"Hollow_{gachaRecords.Info.ExportTimestamp}.json"});
if (file is null) return;
await using var stream = await file.OpenWriteAsync();
await using var streamWriter = new StreamWriter(stream);
await streamWriter.WriteLineAsync(JsonSerializer.Serialize(gachaRecords, HollowJsonSerializer.Options));
}

[RelayCommand]
Expand Down
32 changes: 32 additions & 0 deletions Hollow/Views/Dialogs/ExportDialog.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<UserControl
MinWidth="300"
x:Class="Hollow.Views.Dialogs.ExportDialog"
x:DataType="dialogs:ExportDialogViewModel"
xmlns="https://github.com/avaloniaui"
xmlns:dialogs="clr-namespace:Hollow.Views.Dialogs"
xmlns:languages="clr-namespace:Hollow.Languages"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Spacing="17">
<TextBlock Text="{I18N {x:Static languages:LangKeys.SignalSearch_Export_Tip}}" />

<ListBox
ItemsSource="{Binding UidList}"
SelectedItems="{Binding SelectedUidList, Mode=TwoWay}"
SelectionMode="Multiple, Toggle" />

<Grid ColumnDefinitions="*, 10, *">
<Button
Command="{Binding CancelCommand}"
Content="{I18N {x:Static languages:LangKeys.Dialog_Cancel}}"
Grid.Column="0"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center" />
<Button
Command="{Binding OkCommand}"
Content="{I18N {x:Static languages:LangKeys.Dialog_Ok}}"
Grid.Column="2"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center" />
</Grid>
</StackPanel>
</UserControl>
15 changes: 15 additions & 0 deletions Hollow/Views/Dialogs/ExportDialog.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.ObjectModel;
using Avalonia.Controls;

namespace Hollow.Views.Dialogs;

public partial class ExportDialog : UserControl
{
public ExportDialog(ObservableCollection<string> uidList, Action<string[]> selectedUidListCallback)
{
InitializeComponent();

DataContext = new ExportDialogViewModel(uidList, selectedUidListCallback);
}
}
33 changes: 33 additions & 0 deletions Hollow/Views/Dialogs/ExportDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Hollow.Views.Controls;

namespace Hollow.Views.Dialogs;

public partial class ExportDialogViewModel(
ObservableCollection<string> uidList,
Action<string[]> selectedUidListCallback)
: ObservableObject
{
[ObservableProperty]
private ObservableCollection<string> _uidList = uidList;

[ObservableProperty]
private ObservableCollection<string> _selectedUidList = [];

[RelayCommand]
private void Ok()
{
selectedUidListCallback(SelectedUidList.ToArray());
HollowHost.CloseDialog();
}

[RelayCommand]
private void Cancel()
{
HollowHost.CloseDialog();
}
}
14 changes: 0 additions & 14 deletions Hollow/Views/Dialogs/StandardDialog.axaml

This file was deleted.

18 changes: 0 additions & 18 deletions Hollow/Views/Dialogs/StandardDialog.axaml.cs

This file was deleted.

0 comments on commit 0edf8a5

Please sign in to comment.