diff --git a/DownKyi.Core/Storage/StorageHeader.cs b/DownKyi.Core/Storage/StorageHeader.cs index 505272b..d38ff91 100644 --- a/DownKyi.Core/Storage/StorageHeader.cs +++ b/DownKyi.Core/Storage/StorageHeader.cs @@ -28,6 +28,7 @@ namespace DownKyi.Core.Storage public BitmapImage GetHeaderThumbnail(long mid, string name, string url, int width, int height) { string header = GetHeader(mid, name, url); + if(header == null) { return null; } return GetHeaderThumbnail(header, width, height); } diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index ff95d7b..906c020 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -170,6 +170,7 @@ namespace DownKyi containerRegistry.RegisterForNavigation(ViewMySpaceViewModel.Tag); containerRegistry.RegisterForNavigation(ViewMyFavoritesViewModel.Tag); containerRegistry.RegisterForNavigation(ViewMyBangumiFollowViewModel.Tag); + containerRegistry.RegisterForNavigation(ViewMyHistoryViewModel.Tag); // downloadManager pages containerRegistry.RegisterForNavigation(ViewDownloadingViewModel.Tag); diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index 7013f51..5ec5bf9 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -104,6 +104,7 @@ + @@ -155,6 +156,7 @@ + @@ -226,6 +228,9 @@ ViewMyFavorites.xaml + + ViewMyHistory.xaml + ViewMySpace.xaml @@ -415,6 +420,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/DownKyi/Images/NormalIcon.cs b/DownKyi/Images/NormalIcon.cs index bd21580..7977bf2 100644 --- a/DownKyi/Images/NormalIcon.cs +++ b/DownKyi/Images/NormalIcon.cs @@ -266,6 +266,73 @@ q-13.21 7.16 -14.32 22.57 l0 259.85 q1.11 15.42 14.32 22.57 q13.21 7.16 26.42 -1.65 l186.09 -129.92 Z", Fill = "#FF000000" }; + + PlatformIpad = new VectorImage + { + Height = 16, + Width = 16, + Data = @"M804.57 0 q40 0 73.72 19.43 q33.71 19.43 53.14 53.15 q19.43 33.72 19.43 73.71 l0 731.42 q0 40 -19.43 73.71 + q-19.43 33.72 -53.14 53.14 q-33.72 19.43 -73.72 19.43 l-585.14 0 q-40 0 -73.72 -19.43 q-33.72 -19.43 -53.15 -53.14 + q-19.43 -33.71 -19.43 -73.71 l0 -731.42 q0 -40 19.43 -73.71 q19.43 -33.72 53.15 -53.15 q33.72 -19.43 73.72 -19.43 + l585.14 0 ZM512 877.71 q-22.86 0 -38.86 16 q-16 16 -16 38.86 q0 22.86 16 38.86 q16 16 38.86 16 q22.86 0 38.86 -16 + q16 -16 16 -38.86 q0 -22.86 -16 -38.86 q-16 -16 -38.86 -16 ZM804.57 73.14 l-585.14 0 q-27.43 0 -48.57 18.28 + q-21.15 18.28 -24.57 46.86 l0 8 l0 621.71 q0 27.43 18.28 48.57 q18.29 21.14 46.86 24.57 l8 0 l585.14 0 + q27.43 0 48.57 -18.28 q21.14 -18.28 24.57 -46.86 l0 -8 l0 -621.71 q0 -30.86 -21.14 -52 q-21.14 -21.14 -52 -21.14 Z", + Fill = "#FF000000" + }; + + PlatformMobile = new VectorImage + { + Height = 16, + Width = 16, + Data = @"M694.86 0 q40 0 73.72 19.43 q33.71 19.43 53.14 53.15 q19.43 33.72 19.43 73.71 l0 731.42 q0 40 -19.43 73.71 + q-19.42 33.72 -53.14 53.14 q-33.72 19.43 -73.72 19.43 l-365.72 0 q-40 0 -73.71 -19.43 q-33.72 -19.43 -53.14 -53.14 + q-19.43 -33.71 -19.43 -73.71 l0 -731.42 q0 -40 19.43 -73.71 q19.42 -33.72 53.14 -53.15 q33.71 -19.43 73.71 -19.43 + l365.72 0 ZM512 877.71 q-22.86 0 -38.86 16 q-16 16 -16 38.86 q0 22.86 16 38.86 q16 16 38.86 16 q22.86 0 38.86 -16 + q16 -16 16 -38.86 q0 -22.86 -16 -38.86 q-16 -16 -38.86 -16 ZM694.86 73.14 l-365.72 0 q-27.43 0 -48.57 18.28 + q-21.14 18.28 -24.57 46.86 l0 8 l0 621.71 q0 27.43 18.28 48.57 q18.29 21.14 46.86 24.57 l8 0 l365.72 0 + q27.43 0 48.57 -18.28 q21.14 -18.28 24.57 -46.86 l0 -8 l0 -621.71 q0 -30.86 -21.14 -52 q-21.14 -21.14 -52 -21.14 Z", + Fill = "#FF000000" + }; + + PlatformPC = new VectorImage + { + Height = 16, + Width = 16, + Data = @"M694.86 804.57 q14.85 0 25.71 10.86 q10.86 10.86 10.86 25.71 q0 14.86 -10.86 25.71 q-10.86 10.86 -25.71 10.86 + l-365.72 0 q-14.85 0 -25.71 -10.86 q-10.86 -10.86 -10.86 -25.71 q0 -14.86 10.86 -25.71 q10.86 -10.86 25.71 -10.86 + l365.72 0 ZM877.71 0 q40 0 73.71 19.43 q33.72 19.43 53.14 53.15 q19.43 33.72 19.43 73.71 l0 438.85 q0 40 -19.43 73.72 + q-19.43 33.72 -53.14 53.14 q-33.71 19.43 -73.71 19.43 l-731.42 0 q-40 0 -73.71 -19.43 q-33.72 -19.43 -53.15 -53.14 + q-19.43 -33.72 -19.43 -73.72 l0 -438.85 q0 -40 19.43 -73.71 q19.43 -33.72 53.15 -53.15 q33.72 -19.43 73.71 -19.43 + l731.42 0 ZM877.71 73.14 l-731.42 0 q-27.43 0 -48.57 18.28 q-21.15 18.28 -24.58 46.86 l0 8 l0 438.85 + q0 27.43 18.28 48.58 q18.28 21.14 46.86 24.57 l8 0 l731.42 0 q27.43 0 48.57 -18.29 q21.14 -18.29 24.58 -46.86 + l0 -8 l0 -438.85 q0 -30.86 -21.14 -52 q-21.14 -21.14 -52 -21.14 ZM347.43 182.86 q34.28 0 63.99 17.14 + q29.72 17.14 46.86 46.85 q17.15 29.72 17.15 64 q0 34.28 -17.15 64 q-17.14 29.71 -46.86 46.86 + q-29.71 17.14 -63.99 17.14 l-91.43 0 l0 109.71 l-73.14 0 l0 -365.71 l164.57 0 ZM694.86 182.86 + q44.57 0 82.85 19.43 q38.29 19.42 63.43 53.71 l-60.57 41.14 q-22.86 -27.43 -56 -37.14 q-33.14 -9.71 -66.28 2.29 + q-33.14 12 -53.14 40.57 q-20 28.57 -20 62.86 q0 34.28 20 62.85 q20 28.57 53.14 40.57 q33.14 12 66.28 2.28 + q33.14 -9.71 56 -37.13 l60.57 41.14 q-38.85 51.43 -101.14 67.43 q-62.29 16 -121.14 -10.86 + q-58.86 -26.86 -87.42 -84.58 q-28.57 -57.71 -14.86 -120.57 q13.71 -62.86 64 -103.43 q50.28 -40.57 114.28 -40.57 + ZM347.43 256 l-91.43 0 l0 109.71 l91.43 0 q22.86 0 38.86 -16 q16 -16 16 -38.85 q0 -22.86 -16 -38.86 q-16 -16 -38.86 -16 Z", + Fill = "#FF000000" + }; + + PlatformTV = new VectorImage + { + Height = 16, + Width = 16, + Data = @"M768 804.57 q14.86 0 25.72 10.86 q10.86 10.86 10.86 25.71 q0 14.86 -10.86 25.71 q-10.86 10.86 -25.72 10.86 + l-512 0 q-14.86 0 -25.72 -10.86 q-10.85 -10.86 -10.85 -25.71 q0 -14.86 10.85 -25.71 q10.85 -10.86 25.72 -10.86 + l512 0 ZM877.71 0 q40 0 73.71 19.43 q33.72 19.43 53.14 53.15 q19.43 33.72 19.43 73.71 l0 438.85 q0 40 -19.43 73.72 + q-19.43 33.72 -53.14 53.14 q-33.71 19.43 -73.71 19.43 l-731.42 0 q-40 0 -73.71 -19.43 q-33.72 -19.43 -53.15 -53.14 + q-19.43 -33.72 -19.43 -73.72 l0 -438.85 q0 -40 19.43 -73.71 q19.43 -33.72 53.15 -53.15 q33.72 -19.43 73.71 -19.43 + l731.42 0 ZM877.71 73.14 l-731.42 0 q-27.43 0 -48.57 18.28 q-21.15 18.28 -24.58 46.86 l0 8 l0 438.85 + q0 27.43 18.28 48.58 q18.28 21.14 46.86 24.57 l8 0 l731.42 0 q27.43 0 48.57 -18.29 q21.14 -18.29 24.58 -46.86 + l0 -8 l0 -438.85 q0 -30.86 -21.14 -52 q-21.14 -21.14 -52 -21.14 ZM585.14 182.86 l109.72 274.28 l109.71 -274.28 + l73.14 0 l-146.28 365.71 l-73.14 0 l-116.58 -292.57 l-176 0 l0 292.57 l-73.14 0 l0 -292.57 l-146.28 0 l0 -73.14 l438.85 0 Z", + Fill = "#FF000000" + }; + } public VectorImage Play { get; private set; } @@ -290,5 +357,11 @@ public VectorImage VideoUp { get; private set; } public VectorImage Channel { get; private set; } + + public VectorImage PlatformIpad { get; private set; } + public VectorImage PlatformMobile { get; private set; } + public VectorImage PlatformPC { get; private set; } + public VectorImage PlatformTV { get; private set; } + } } diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index c3a5163..8180f05 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -82,6 +82,12 @@ 追剧 尚未观看 + + 历史记录 + 已看完 + 刚开始 + 看到 + 下载选中项 下载全部 diff --git a/DownKyi/Services/FavoritesService.cs b/DownKyi/Services/FavoritesService.cs index 4c7f4f2..a04bfe8 100644 --- a/DownKyi/Services/FavoritesService.cs +++ b/DownKyi/Services/FavoritesService.cs @@ -156,7 +156,7 @@ namespace DownKyi.Services FavoriteNumber = media.CntInfo != null ? Format.FormatNumber(media.CntInfo.Collect) : "0", Duration = Format.FormatDuration2(media.Duration), UpName = media.Upper != null ? media.Upper.Name : string.Empty, - UpperMid = media.Upper != null ? media.Upper.Mid : -1, + UpMid = media.Upper != null ? media.Upper.Mid : -1, CreateTime = ctime, FavTime = favTime }; diff --git a/DownKyi/ViewModels/PageViewModels/FavoritesMedia.cs b/DownKyi/ViewModels/PageViewModels/FavoritesMedia.cs index ea8f972..4c8e56a 100644 --- a/DownKyi/ViewModels/PageViewModels/FavoritesMedia.cs +++ b/DownKyi/ViewModels/PageViewModels/FavoritesMedia.cs @@ -18,7 +18,7 @@ namespace DownKyi.ViewModels.PageViewModels public long Avid { get; set; } public string Bvid { get; set; } - public long UpperMid { get; set; } + public long UpMid { get; set; } #region 页面属性申明 @@ -130,7 +130,7 @@ namespace DownKyi.ViewModels.PageViewModels { if (!(parameter is string tag)) { return; } - NavigateToView.NavigateToViewUserSpace(eventAggregator, tag, UpperMid); + NavigateToView.NavigateToViewUserSpace(eventAggregator, tag, UpMid); } #endregion diff --git a/DownKyi/ViewModels/PageViewModels/HistoryMedia.cs b/DownKyi/ViewModels/PageViewModels/HistoryMedia.cs new file mode 100644 index 0000000..6d7516d --- /dev/null +++ b/DownKyi/ViewModels/PageViewModels/HistoryMedia.cs @@ -0,0 +1,175 @@ +using DownKyi.Images; +using DownKyi.Utils; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace DownKyi.ViewModels.PageViewModels +{ + public class HistoryMedia : BindableBase + { + protected readonly IEventAggregator eventAggregator; + + public HistoryMedia(IEventAggregator eventAggregator) + { + this.eventAggregator = eventAggregator; + } + + // bvid + public string Bvid { get; set; } + + // 播放url + public string Url { get; set; } + + // UP主的mid + public long UpMid { get; set; } + + // 类型 + public string Business { get; set; } + + #region 页面属性申明 + + // 是否选中 + private bool isSelected; + public bool IsSelected + { + get => isSelected; + set => SetProperty(ref isSelected, value); + } + + // 封面 + private BitmapImage cover; + public BitmapImage Cover + { + get => cover; + set => SetProperty(ref cover, value); + } + + // 视频标题 + private string title; + public string Title + { + get => title; + set => SetProperty(ref title, value); + } + + // 分P的标题 + private string subTitle; + public string SubTitle + { + get => subTitle; + set => SetProperty(ref subTitle, value); + } + + // 时长 + private long duration; + public long Duration + { + get => duration; + set => SetProperty(ref duration, value); + } + + // tag标签 + private string tagName; + public string TagName + { + get => tagName; + set => SetProperty(ref tagName, value); + } + + // new_desc 剧集或分P描述 + private string partdesc; + public string Partdesc + { + get => partdesc; + set => SetProperty(ref partdesc, value); + } + + // 观看进度 + private string progress; + public string Progress + { + get => progress; + set => SetProperty(ref progress, value); + } + + // 观看平台 + private VectorImage platform; + public VectorImage Platform + { + get => platform; + set => SetProperty(ref platform, value); + } + + // UP主的昵称 + private string upName; + public string UpName + { + get => upName; + set => SetProperty(ref upName, value); + } + + // UP主的头像 + private BitmapImage upHeader; + public BitmapImage UpHeader + { + get => upHeader; + set => SetProperty(ref upHeader, value); + } + + // 是否显示Partdesc + private Visibility partdescVisibility; + public Visibility PartdescVisibility + { + get => partdescVisibility; + set => SetProperty(ref partdescVisibility, value); + } + + // 是否显示UP主信息和分区信息 + private Visibility upAndTagVisibility; + public Visibility UpAndTagVisibility + { + get => upAndTagVisibility; + set => SetProperty(ref upAndTagVisibility, value); + } + + #endregion + + #region 命令申明 + + // 视频标题点击事件 + private DelegateCommand titleCommand; + public DelegateCommand TitleCommand => titleCommand ?? (titleCommand = new DelegateCommand(ExecuteTitleCommand)); + + /// + /// 视频标题点击事件 + /// + /// + private void ExecuteTitleCommand(object parameter) + { + if (!(parameter is string tag)) { return; } + + NavigateToView.NavigationView(eventAggregator, ViewVideoDetailViewModel.Tag, tag, Url); + } + + // 视频标题点击事件 + private DelegateCommand upCommand; + public DelegateCommand UpCommand => upCommand ?? (upCommand = new DelegateCommand(ExecuteUpCommand)); + + /// + /// 视频标题点击事件 + /// + /// + private void ExecuteUpCommand(object parameter) + { + if (!(parameter is string tag)) { return; } + + NavigateToView.NavigateToViewUserSpace(eventAggregator, tag, UpMid); + } + + #endregion + + } +} diff --git a/DownKyi/ViewModels/ViewChannelViewModel.cs b/DownKyi/ViewModels/ViewChannelViewModel.cs index ae5d324..875953e 100644 --- a/DownKyi/ViewModels/ViewChannelViewModel.cs +++ b/DownKyi/ViewModels/ViewChannelViewModel.cs @@ -411,6 +411,7 @@ namespace DownKyi.ViewModels ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); Medias.Clear(); + IsSelectAll = false; // 根据传入参数不同执行不同任务 var parameter = navigationContext.Parameters.GetValue>("Parameter"); diff --git a/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs b/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs index 99413c2..e4e0058 100644 --- a/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs +++ b/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs @@ -471,6 +471,7 @@ namespace DownKyi.ViewModels NoDataVisibility = Visibility.Collapsed; Medias.Clear(); + IsSelectAll = false; } /// @@ -481,6 +482,8 @@ namespace DownKyi.ViewModels { base.OnNavigatedTo(navigationContext); + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + // 根据传入参数不同执行不同任务 mid = navigationContext.Parameters.GetValue("Parameter"); if (mid == 0) diff --git a/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs b/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs index 4eb713d..ddc2702 100644 --- a/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs +++ b/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs @@ -422,6 +422,7 @@ namespace DownKyi.ViewModels TabHeaders.Clear(); Medias.Clear(); SelectTabId = -1; + IsSelectAll = false; } /// diff --git a/DownKyi/ViewModels/ViewMyHistoryViewModel.cs b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs new file mode 100644 index 0000000..71dbe07 --- /dev/null +++ b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs @@ -0,0 +1,499 @@ +using DownKyi.Core.BiliApi.History; +using DownKyi.Core.BiliApi.VideoStream; +using DownKyi.Core.Storage; +using DownKyi.Core.Utils; +using DownKyi.CustomControl; +using DownKyi.Events; +using DownKyi.Images; +using DownKyi.Services; +using DownKyi.Services.Download; +using DownKyi.Utils; +using DownKyi.ViewModels.PageViewModels; +using Prism.Commands; +using Prism.Events; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace DownKyi.ViewModels +{ + public class ViewMyHistoryViewModel : BaseViewModel + { + public const string Tag = "PageMyHistory"; + + private readonly IDialogService dialogService; + + private CancellationTokenSource tokenSource; + + // 每页视频数量,暂时在此写死,以后在设置中增加选项 + private readonly int VideoNumberInPage = 30; + + #region 页面属性申明 + + private string pageName = Tag; + public string PageName + { + get => pageName; + set => SetProperty(ref pageName, value); + } + + private VectorImage arrowBack; + public VectorImage ArrowBack + { + get => arrowBack; + set => SetProperty(ref arrowBack, value); + } + + private Visibility contentVisibility; + public Visibility ContentVisibility + { + get => contentVisibility; + set => SetProperty(ref contentVisibility, value); + } + + private ObservableCollection medias; + public ObservableCollection Medias + { + get => medias; + set => SetProperty(ref medias, value); + } + + private bool isSelectAll; + public bool IsSelectAll + { + get => isSelectAll; + set => SetProperty(ref isSelectAll, value); + } + + private GifImage loading; + public GifImage Loading + { + get => loading; + set => SetProperty(ref loading, value); + } + + private Visibility loadingVisibility; + public Visibility LoadingVisibility + { + get => loadingVisibility; + set => SetProperty(ref loadingVisibility, value); + } + + private Visibility noDataVisibility; + public Visibility NoDataVisibility + { + get => noDataVisibility; + set => SetProperty(ref noDataVisibility, value); + } + + #endregion + + public ViewMyHistoryViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator) + { + this.dialogService = dialogService; + + #region 属性初始化 + + // 初始化loading gif + Loading = new GifImage(Properties.Resources.loading); + Loading.StartAnimate(); + LoadingVisibility = Visibility.Collapsed; + NoDataVisibility = Visibility.Collapsed; + + ArrowBack = NavigationIcon.Instance().ArrowBack; + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + + Medias = new ObservableCollection(); + + #endregion + + } + + #region 命令申明 + + // 返回事件 + private DelegateCommand backSpaceCommand; + public DelegateCommand BackSpaceCommand => backSpaceCommand ?? (backSpaceCommand = new DelegateCommand(ExecuteBackSpace)); + + /// + /// 返回事件 + /// + private void ExecuteBackSpace() + { + InitView(); + + ArrowBack.Fill = DictionaryResource.GetColor("ColorText"); + + // 结束任务 + tokenSource?.Cancel(); + + NavigationParam parameter = new NavigationParam + { + ViewName = ParentView, + ParentViewName = null, + Parameter = null + }; + eventAggregator.GetEvent().Publish(parameter); + } + + // 全选按钮点击事件 + private DelegateCommand selectAllCommand; + public DelegateCommand SelectAllCommand => selectAllCommand ?? (selectAllCommand = new DelegateCommand(ExecuteSelectAllCommand)); + + /// + /// 全选按钮点击事件 + /// + /// + private void ExecuteSelectAllCommand(object parameter) + { + if (IsSelectAll) + { + foreach (var item in Medias) + { + item.IsSelected = true; + } + } + else + { + foreach (var item in Medias) + { + item.IsSelected = false; + } + } + } + + // 列表选择事件 + private DelegateCommand mediasCommand; + public DelegateCommand MediasCommand => mediasCommand ?? (mediasCommand = new DelegateCommand(ExecuteMediasCommand)); + + /// + /// 列表选择事件 + /// + /// + private void ExecuteMediasCommand(object parameter) + { + if (!(parameter is IList selectedMedia)) { return; } + + if (selectedMedia.Count == Medias.Count) + { + IsSelectAll = true; + } + else + { + IsSelectAll = false; + } + } + + // 添加选中项到下载列表事件 + private DelegateCommand addToDownloadCommand; + public DelegateCommand AddToDownloadCommand => addToDownloadCommand ?? (addToDownloadCommand = new DelegateCommand(ExecuteAddToDownloadCommand)); + + /// + /// 添加选中项到下载列表事件 + /// + private void ExecuteAddToDownloadCommand() + { + AddToDownload(true); + } + + // 添加所有视频到下载列表事件 + private DelegateCommand addAllToDownloadCommand; + public DelegateCommand AddAllToDownloadCommand => addAllToDownloadCommand ?? (addAllToDownloadCommand = new DelegateCommand(ExecuteAddAllToDownloadCommand)); + + /// + /// 添加所有视频到下载列表事件 + /// + private void ExecuteAddAllToDownloadCommand() + { + AddToDownload(false); + } + + #endregion + + /// + /// 添加到下载 + /// + /// + private async void AddToDownload(bool isOnlySelected) + { + // BANGUMI类型 + AddToDownloadService addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO); + + // 选择文件夹 + string directory = addToDownloadService.SetDirectory(dialogService); + + // 视频计数 + int i = 0; + await Task.Run(() => + { + // 为了避免执行其他操作时, + // Medias变化导致的异常 + var list = Medias.ToList(); + + // 添加到下载 + foreach (var media in list) + { + // 只下载选中项,跳过未选中项 + if (isOnlySelected && !media.IsSelected) { continue; } + + /// 有分P的就下载全部 + + // 开启服务 + IInfoService service = null; + switch (media.Business) + { + case "archive": + service = new VideoInfoService(media.Url); + break; + case "pgc": + service = new BangumiInfoService(media.Url); + break; + } + if (service == null) { return; } + + addToDownloadService.SetVideoInfoService(service); + addToDownloadService.GetVideo(); + addToDownloadService.ParseVideo(service); + // 下载 + i += addToDownloadService.AddToDownload(eventAggregator, directory); + } + }); + + if (directory == null) + { + return; + } + + // 通知用户添加到下载列表的结果 + if (i == 0) + { + eventAggregator.GetEvent().Publish(DictionaryResource.GetString("TipAddDownloadingZero")); + } + else + { + eventAggregator.GetEvent().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}"); + } + } + + private async void UpdateHistoryMediaList() + { + LoadingVisibility = Visibility.Visible; + NoDataVisibility = Visibility.Collapsed; + Medias.Clear(); + + await Task.Run(() => + { + CancellationToken cancellationToken = tokenSource.Token; + + var historyList = History.GetHistory(0, 0, VideoNumberInPage); + if (historyList == null || historyList.List == null || historyList.List.Count == 0) + { + LoadingVisibility = Visibility.Collapsed; + NoDataVisibility = Visibility.Visible; + return; + } + + foreach (var history in historyList.List) + { + if (history.History == null) { continue; } + + if (history.History.Business != "archive" && history.History.Business != "pgc") + { continue; } + + // 播放url + string url = "https://www.bilibili.com"; + switch (history.History.Business) + { + case "archive": + url = "https://www.bilibili.com/video/" + history.History.Bvid; + break; + case "pgc": + url = history.Uri; + break; + } + + // 查询、保存封面 + string coverUrl = history.Cover; + BitmapImage cover; + if (coverUrl == null || coverUrl == "") + { + cover = null; + } + else + { + if (!coverUrl.ToLower().StartsWith("http")) + { + coverUrl = $"https:{history.Cover}"; + } + + StorageCover storageCover = new StorageCover(); + cover = storageCover.GetCoverThumbnail(history.History.Oid, history.History.Bvid, history.History.Cid, coverUrl, 160, 100); + } + + // 获取用户头像 + string upName; + BitmapImage upHeader; + if (history.AuthorFace != null) + { + upName = history.AuthorName; + StorageHeader storageHeader = new StorageHeader(); + upHeader = storageHeader.GetHeaderThumbnail(history.AuthorMid, upName, history.AuthorFace, 24, 24); + } + else + { + upName = ""; + upHeader = null; + } + + // 观看进度 + // -1 已看完 + // 0 刚开始 + // >0 看到 progress + string progress; + if (history.Progress == -1) { progress = DictionaryResource.GetString("HistoryFinished"); } + else if (history.Progress == 0) { progress = DictionaryResource.GetString("HistoryStarted"); } + else { progress = DictionaryResource.GetString("HistoryWatch") + " " + Format.FormatDuration3(history.Progress); } + + // 观看平台 + VectorImage platform; + switch (history.History.Dt) + { + case 1: + case 3: + case 5: + case 7: + // 手机端 + platform = NormalIcon.Instance().PlatformMobile; + break; + case 2: + // web端 + platform = NormalIcon.Instance().PlatformPC; + break; + case 4: + case 6: + // pad端 + platform = NormalIcon.Instance().PlatformIpad; + break; + case 33: + // TV端 + platform = NormalIcon.Instance().PlatformTV; + break; + default: + // 其他 + platform = null; + break; + } + + // 是否显示Partdesc + Visibility partdescVisibility; + if (history.NewDesc == "") + { + partdescVisibility = Visibility.Hidden; + } + else + { + partdescVisibility = Visibility.Visible; + } + + // 是否显示UP主信息和分区信息 + Visibility upAndTagVisibility; + if (history.History.Business == "archive") + { + upAndTagVisibility = Visibility.Visible; + } + else + { + upAndTagVisibility = Visibility.Hidden; + } + + App.PropertyChangeAsync(() => + { + HistoryMedia media = new HistoryMedia(eventAggregator) + { + Business = history.History.Business, + Bvid = history.History.Bvid, + Url = url, + UpMid = history.AuthorMid, + Cover = cover ?? new BitmapImage(new Uri($"pack://application:,,,/Resources/video-placeholder.png")), + Title = history.Title, + SubTitle = history.ShowTitle, + Duration = history.Duration, + TagName = history.TagName, + Partdesc = history.NewDesc, + Progress = progress, + Platform = platform, + UpName = upName, + UpHeader = upHeader, + + PartdescVisibility = partdescVisibility, + UpAndTagVisibility = upAndTagVisibility, + }; + + Medias.Add(media); + + ContentVisibility = Visibility.Visible; + LoadingVisibility = Visibility.Collapsed; + NoDataVisibility = Visibility.Collapsed; + }); + + // 判断是否该结束线程,若为true,跳出循环 + if (cancellationToken.IsCancellationRequested) + { + break; + } + } + }, (tokenSource = new CancellationTokenSource()).Token); + } + + /// + /// 初始化页面数据 + /// + private void InitView() + { + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + + ContentVisibility = Visibility.Collapsed; + LoadingVisibility = Visibility.Collapsed; + NoDataVisibility = Visibility.Collapsed; + + Medias.Clear(); + IsSelectAll = false; + } + + /// + /// 导航到VideoDetail页面时执行 + /// + /// + public override void OnNavigatedTo(NavigationContext navigationContext) + { + base.OnNavigatedTo(navigationContext); + + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + + // 根据传入参数不同执行不同任务 + long mid = navigationContext.Parameters.GetValue("Parameter"); + if (mid == 0) + { + IsSelectAll = false; + foreach (var media in Medias) + { + media.IsSelected = false; + } + + return; + } + + InitView(); + + UpdateHistoryMediaList(); + } + + } +} diff --git a/DownKyi/ViewModels/ViewMySpaceViewModel.cs b/DownKyi/ViewModels/ViewMySpaceViewModel.cs index d5cbe0e..40763e6 100644 --- a/DownKyi/ViewModels/ViewMySpaceViewModel.cs +++ b/DownKyi/ViewModels/ViewMySpaceViewModel.cs @@ -349,7 +349,7 @@ namespace DownKyi.ViewModels Console.WriteLine(SelectedPackage); break; case 3: - Console.WriteLine(SelectedPackage); + NavigateToView.NavigationView(eventAggregator, ViewMyHistoryViewModel.Tag, Tag, mid); break; default: break; diff --git a/DownKyi/ViewModels/ViewPublicationViewModel.cs b/DownKyi/ViewModels/ViewPublicationViewModel.cs index 37051d5..c7b4fdd 100644 --- a/DownKyi/ViewModels/ViewPublicationViewModel.cs +++ b/DownKyi/ViewModels/ViewPublicationViewModel.cs @@ -446,6 +446,7 @@ namespace DownKyi.ViewModels TabHeaders.Clear(); Medias.Clear(); SelectTabId = -1; + IsSelectAll = false; } /// diff --git a/DownKyi/Views/ViewMyBangumiFollow.xaml b/DownKyi/Views/ViewMyBangumiFollow.xaml index f6a0a5b..ab25214 100644 --- a/DownKyi/Views/ViewMyBangumiFollow.xaml +++ b/DownKyi/Views/ViewMyBangumiFollow.xaml @@ -234,7 +234,7 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +