Skip to content

Commit

Permalink
feat: 加入已下载列表按下载时间倒序 Fixes: #114
Browse files Browse the repository at this point in the history
  • Loading branch information
yaobiao131 committed Jul 10, 2024
1 parent f18e79a commit de02abd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
7 changes: 4 additions & 3 deletions DownKyi.Core/Settings/DownloadFinishedSort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

public enum DownloadFinishedSort
{
NOT_SET = 0,
DOWNLOAD,
NUMBER
NotSet = 0,
DownloadAsc,
DownloadDesc,
Number
}
2 changes: 1 addition & 1 deletion DownKyi.Core/Settings/Models/BasicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BasicSettings
public AllowStatus IsAutoParseVideo { get; set; } = AllowStatus.NONE;
public ParseScope ParseScope { get; set; } = ParseScope.NOT_SET;
public AllowStatus IsAutoDownloadAll { get; set; } = AllowStatus.NONE;
public DownloadFinishedSort DownloadFinishedSort { get; set; } = DownloadFinishedSort.NOT_SET;
public DownloadFinishedSort DownloadFinishedSort { get; set; } = DownloadFinishedSort.NotSet;
public RepeatDownloadStrategy RepeatDownloadStrategy { get; set; } = RepeatDownloadStrategy.Ask;
public bool RepeatFileAutoAddNumberSuffix { get; set; } = false;
}
4 changes: 2 additions & 2 deletions DownKyi.Core/Settings/SettingsManager.Basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public partial class SettingsManager
private readonly AllowStatus _isAutoDownloadAll = AllowStatus.NO;

// 下载完成列表排序
private readonly DownloadFinishedSort _finishedSort = DownloadFinishedSort.DOWNLOAD;
private readonly DownloadFinishedSort _finishedSort = DownloadFinishedSort.DownloadAsc;

// 重复下载策略
private readonly RepeatDownloadStrategy _repeatDownloadStrategy = RepeatDownloadStrategy.Ask;
Expand Down Expand Up @@ -192,7 +192,7 @@ public bool IsAutoDownloadAll(AllowStatus isAutoDownloadAll)
public DownloadFinishedSort GetDownloadFinishedSort()
{
appSettings = GetSettings();
if (appSettings.Basic.DownloadFinishedSort == DownloadFinishedSort.NOT_SET)
if (appSettings.Basic.DownloadFinishedSort == DownloadFinishedSort.NotSet)
{
// 第一次获取,先设置默认值
SetDownloadFinishedSort(_finishedSort);
Expand Down
8 changes: 6 additions & 2 deletions DownKyi/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,15 @@ public static void SortDownloadedList(DownloadFinishedSort finishedSort)
var list = DownloadedList?.ToList();
switch (finishedSort)
{
case DownloadFinishedSort.DOWNLOAD:
case DownloadFinishedSort.DownloadAsc:
// 按下载先后排序
list?.Sort((x, y) => x.Downloaded.FinishedTimestamp.CompareTo(y.Downloaded.FinishedTimestamp));
break;
case DownloadFinishedSort.NUMBER:
case DownloadFinishedSort.DownloadDesc:
// 按下载先后排序
list?.Sort((x, y) => y.Downloaded.FinishedTimestamp.CompareTo(x.Downloaded.FinishedTimestamp));
break;
case DownloadFinishedSort.Number:
// 按序号排序
list?.Sort((x, y) =>
{
Expand Down
3 changes: 2 additions & 1 deletion DownKyi/Languanges/Default.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
<system:String x:Key="DeleteAllDownloading">全部删除</system:String>
<system:String x:Key="TotalDownloaded1">已下载</system:String>
<system:String x:Key="TotalDownloaded2">个视频!</system:String>
<system:String x:Key="DownloadedSortByTime">按下载先后排序</system:String>
<system:String x:Key="DownloadedSortByTimeAsc">按下载时间升序</system:String>
<system:String x:Key="DownloadedSortByTimeDesc">按下载时间降序</system:String>
<system:String x:Key="DownloadedSortByOrder">按序号排序</system:String>
<system:String x:Key="ClearAllDownloaded">清空所有记录</system:String>
<system:String x:Key="StartDownload">开始</system:String>
Expand Down
26 changes: 16 additions & 10 deletions DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator, IDialogSe
};
SetDialogService();

DownloadFinishedSort finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort();
var finishedSort = SettingsManager.GetInstance().GetDownloadFinishedSort();
FinishedSortBy = finishedSort switch
{
DownloadFinishedSort.DOWNLOAD => 0,
DownloadFinishedSort.NUMBER => 1,
DownloadFinishedSort.DownloadAsc => 0,
DownloadFinishedSort.DownloadDesc => 1,
DownloadFinishedSort.Number => 2,
_ => 0
};
App.SortDownloadedList(finishedSort);
Expand All @@ -73,24 +74,29 @@ public ViewDownloadFinishedViewModel(IEventAggregator eventAggregator, IDialogSe
/// <param name="parameter"></param>
private void ExecuteFinishedSortCommand(object parameter)
{
if (!(parameter is int index)) { return; }
if (parameter is not int index) { return; }

switch (index)
{
case 0:
App.SortDownloadedList(DownloadFinishedSort.DOWNLOAD);
App.SortDownloadedList(DownloadFinishedSort.DownloadAsc);
// 更新设置
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.DOWNLOAD);
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.DownloadAsc);
break;
case 1:
App.SortDownloadedList(DownloadFinishedSort.NUMBER);
App.SortDownloadedList(DownloadFinishedSort.DownloadDesc);
// 更新设置
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.NUMBER);
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.DownloadDesc);
break;
case 2:
App.SortDownloadedList(DownloadFinishedSort.Number);
// 更新设置
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.Number);
break;
default:
App.SortDownloadedList(DownloadFinishedSort.DOWNLOAD);
App.SortDownloadedList(DownloadFinishedSort.DownloadAsc);
// 更新设置
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.DOWNLOAD);
SettingsManager.GetInstance().SetDownloadFinishedSort(DownloadFinishedSort.DownloadAsc);
break;
}
}
Expand Down
3 changes: 2 additions & 1 deletion DownKyi/Views/DownloadManager/ViewDownloadFinished.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@
CommandParameter="{Binding ElementName=NameFinishedSort, Path=SelectedIndex}" />
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<ComboBoxItem Content="{DynamicResource DownloadedSortByTime}" />
<ComboBoxItem Content="{DynamicResource DownloadedSortByTimeAsc}" />
<ComboBoxItem Content="{DynamicResource DownloadedSortByTimeDesc}" />
<ComboBoxItem Content="{DynamicResource DownloadedSortByOrder}" />
</ComboBox>

Expand Down

0 comments on commit de02abd

Please sign in to comment.