Skip to content

Commit

Permalink
完成清理下载列表功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Dec 21, 2023
1 parent c22252e commit be0fa42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public partial record MainModel
private INavigator _navigator;
private readonly DownloadFileListManager _downloadFileListManager;

public MainModel(
public MainModel
(
IStringLocalizer localizer,
IOptions<AppConfig> appInfo,
INavigator navigator, DownloadFileListManager downloadFileListManager)
INavigator navigator,
DownloadFileListManager downloadFileListManager
)
{
_navigator = navigator;
_downloadFileListManager = downloadFileListManager;
Title = localizer["Main"];
Title += $" - {localizer["ApplicationName"]}";
Title += $" - {appInfo?.Value?.Environment}";

UpdateDownloadFileInfoViewList();
_downloadFileListManager.DownloadFileInfoList.CollectionChanged += DownloadFileInfoList_CollectionChanged;
Expand All @@ -33,19 +33,9 @@ private void DownloadFileInfoList_CollectionChanged(object? sender, System.Colle
UpdateDownloadFileInfoViewList();
}

public string? Title { get; }

public ObservableCollection<DownloadFileInfo> DownloadFileInfoViewList { get; } =
new ObservableCollection<DownloadFileInfo>();

public IState<string> Name => State<string>.Value(this, () => string.Empty);

public async Task GoToSecond()
{
var name = await Name;
await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!));
}

public async Task GotToNewTask()
{
await _navigator.NavigateViewModelAsync<NewTaskModel>(this);
Expand All @@ -56,6 +46,12 @@ public async Task GoToAbout()
await _navigator.NavigateViewModelAsync<AboutModel>(this);
}

public async Task CleanDownloadList()
{
_downloadFileListManager.DownloadFileInfoList.Clear();
await _downloadFileListManager.SaveAsync();
}

private void UpdateDownloadFileInfoViewList()
{
DownloadFileInfoViewList.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
Grid.Column="4"
Style="{StaticResource TitleBarButtonStyle}"
AutomationProperties.Name="[Clear List Button]"
ToolTipService.ToolTip="[Clear List]">
ToolTipService.ToolTip="[Clear List]"
Command="{Binding CleanDownloadList}">
<Button.Content>
<SymbolIcon Symbol="Delete" />
</Button.Content>
Expand Down

0 comments on commit be0fa42

Please sign in to comment.