完成我的收藏夹页面;修复一些问题

croire 3 years ago
parent 7b5b7de1fb
commit e45107b635

@ -23,8 +23,8 @@ namespace DownKyi.Core.BiliApi.Favorites.Models
public int Count { get; set; }
[JsonProperty("list")]
public List<FavoritesMetaInfo> List { get; set; }
[JsonProperty("has_more")]
public int HasMore { get; set; }
//[JsonProperty("has_more")]
//public bool HasMore { get; set; }
}
}

@ -167,6 +167,8 @@ namespace DownKyi
containerRegistry.RegisterForNavigation<ViewPublication>(ViewPublicationViewModel.Tag);
containerRegistry.RegisterForNavigation<Views.ViewChannel>(ViewModels.ViewChannelViewModel.Tag);
containerRegistry.RegisterForNavigation<ViewMyFavorites>(ViewMyFavoritesViewModel.Tag);
// downloadManager pages
containerRegistry.RegisterForNavigation<ViewDownloading>(ViewDownloadingViewModel.Tag);
containerRegistry.RegisterForNavigation<ViewDownloadFinished>(ViewDownloadFinishedViewModel.Tag);

@ -152,6 +152,7 @@
<Compile Include="ViewModels\ViewLoginViewModel.cs" />
<Compile Include="ViewModels\Settings\ViewNetworkViewModel.cs" />
<Compile Include="ViewModels\Dialogs\ViewParsingSelectorViewModel.cs" />
<Compile Include="ViewModels\ViewMyFavoritesViewModel.cs" />
<Compile Include="ViewModels\ViewMySpaceViewModel.cs" />
<Compile Include="ViewModels\ViewPublicationViewModel.cs" />
<Compile Include="ViewModels\ViewPublicFavoritesViewModel.cs" />
@ -217,6 +218,9 @@
<Compile Include="Views\ViewLogin.xaml.cs">
<DependentUpon>ViewLogin.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ViewMyFavorites.xaml.cs">
<DependentUpon>ViewMyFavorites.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ViewMySpace.xaml.cs">
<DependentUpon>ViewMySpace.xaml</DependentUpon>
</Compile>
@ -398,6 +402,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ViewMyFavorites.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ViewMySpace.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

@ -69,6 +69,13 @@
<system:String x:Key="PublicFavorites">收藏夹</system:String>
<system:String x:Key="FavoritesMediaCount">个内容</system:String>
<!-- MyFavorites -->
<system:String x:Key="FavoritesPlayNumber">播放:</system:String>
<system:String x:Key="FavoritesFavoriteNumber">收藏:</system:String>
<system:String x:Key="FavoritesUpName">UP主</system:String>
<system:String x:Key="FavoritesCreateTime">投稿:</system:String>
<system:String x:Key="FavoritesFavTime">收藏于:</system:String>
<!-- Publication -->
<system:String x:Key="DownloadSelectedPublication">下载选中项</system:String>
<system:String x:Key="DownloadAllPublication">下载全部</system:String>

@ -4,6 +4,7 @@ using DownKyi.Core.Utils;
using DownKyi.ViewModels.PageViewModels;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
@ -80,16 +81,44 @@ namespace DownKyi.Services
return favorites;
}
///// <summary>
///// 获取收藏夹所有内容明细列表
///// </summary>
///// <param name="mediaId"></param>
///// <param name="result"></param>
///// <param name="eventAggregator"></param>
//public void GetFavoritesMediaList(long mediaId, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken)
//{
// List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias = FavoritesResource.GetAllFavoritesMedia(mediaId);
// if (medias.Count == 0) { return; }
// GetFavoritesMediaList(medias, result, eventAggregator, cancellationToken);
//}
///// <summary>
///// 获取收藏夹指定页的内容明细列表
///// </summary>
///// <param name="mediaId"></param>
///// <param name="pn"></param>
///// <param name="ps"></param>
///// <param name="result"></param>
///// <param name="eventAggregator"></param>
//public void GetFavoritesMediaList(long mediaId, int pn, int ps, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken)
//{
// List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias = FavoritesResource.GetFavoritesMedia(mediaId, pn, ps);
// if (medias.Count == 0) { return; }
// GetFavoritesMediaList(medias, result, eventAggregator, cancellationToken);
//}
/// <summary>
/// 获取收藏夹内容明细列表
/// </summary>
/// <param name="mediaId"></param>
/// <returns></returns>
public void GetFavoritesMediaList(long mediaId, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator)
/// <param name="medias"></param>
/// <param name="result"></param>
/// <param name="eventAggregator"></param>
public void GetFavoritesMediaList(List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken)
{
var medias = FavoritesResource.GetAllFavoritesMedia(mediaId);
if (medias.Count == 0) { return; }
int order = 0;
foreach (var media in medias)
{
@ -102,6 +131,17 @@ namespace DownKyi.Services
string coverUrl = media.Cover;
BitmapImage cover = storageCover.GetCoverThumbnail(media.Id, media.Bvid, -1, coverUrl, 200, 125);
// 当地时区
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
// 创建时间
DateTime dateCTime = startTime.AddSeconds(media.Ctime);
string ctime = dateCTime.ToString("yyyy-MM-dd");
// 收藏时间
DateTime dateFavTime = startTime.AddSeconds(media.FavTime);
string favTime = dateFavTime.ToString("yyyy-MM-dd");
App.PropertyChangeAsync(new Action(() =>
{
FavoritesMedia newMedia = new FavoritesMedia(eventAggregator)
@ -116,7 +156,9 @@ 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
UpperMid = media.Upper != null ? media.Upper.Mid : -1,
CreateTime = ctime,
FavTime = favTime
};
if (!result.ToList().Exists(t => t.Avid == newMedia.Avid))
@ -125,7 +167,66 @@ namespace DownKyi.Services
Thread.Sleep(10);
}
}));
// 判断是否该结束线程若为true跳出循环
if (cancellationToken.IsCancellationRequested)
{
break;
}
}
}
/// <summary>
/// 更新我创建的收藏夹列表
/// </summary>
/// <param name="mid"></param>
/// <param name="tabHeaders"></param>
public void GetCreatedFavorites(long mid, ObservableCollection<TabHeader> tabHeaders, CancellationToken cancellationToken)
{
var favorites = FavoritesInfo.GetAllCreatedFavorites(mid);
if (favorites.Count == 0) { return; }
foreach (var item in favorites)
{
//cancellationToken.ThrowIfCancellationRequested();
// 判断是否该结束线程若为true跳出循环
if (cancellationToken.IsCancellationRequested)
{
break;
}
App.PropertyChangeAsync(new Action(() =>
{
tabHeaders.Add(new TabHeader { Id = (int)item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() });
}));
}
}
/// <summary>
/// 更新我收藏的收藏夹列表
/// </summary>
/// <param name="mid"></param>
/// <param name="tabHeaders"></param>
public void GetCollectedFavorites(long mid, ObservableCollection<TabHeader> tabHeaders, CancellationToken cancellationToken)
{
var favorites = FavoritesInfo.GetAllCollectedFavorites(mid);
if (favorites.Count == 0) { return; }
foreach (var item in favorites)
{
// 判断是否该结束线程若为true跳出循环
if (cancellationToken.IsCancellationRequested)
{
break;
}
App.PropertyChangeAsync(new Action(() =>
{
tabHeaders.Add(new TabHeader { Id = (int)item.Id, Title = item.Title, SubTitle = item.MediaCount.ToString() });
}));
}
}
}
}

@ -1,12 +1,19 @@
using DownKyi.ViewModels.PageViewModels;
using Prism.Events;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
namespace DownKyi.Services
{
public interface IFavoritesService
{
Favorites GetFavorites(long mediaId);
void GetFavoritesMediaList(long mediaId, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator);
//void GetFavoritesMediaList(long mediaId, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken);
//void GetFavoritesMediaList(long mediaId, int pn, int ps, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken);
void GetFavoritesMediaList(List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias, ObservableCollection<FavoritesMedia> result, IEventAggregator eventAggregator, CancellationToken cancellationToken);
void GetCreatedFavorites(long mid, ObservableCollection<TabHeader> tabHeaders, CancellationToken cancellationToken);
void GetCollectedFavorites(long mid, ObservableCollection<TabHeader> tabHeaders, CancellationToken cancellationToken);
}
}

@ -85,6 +85,20 @@ namespace DownKyi.ViewModels.PageViewModels
set => SetProperty(ref upName, value);
}
private string createTime;
public string CreateTime
{
get => createTime;
set => SetProperty(ref createTime, value);
}
private string favTime;
public string FavTime
{
get => favTime;
set => SetProperty(ref favTime, value);
}
#endregion
#region 命令申明

@ -39,6 +39,13 @@ namespace DownKyi.ViewModels
#region 页面属性申明
private string pageName = Tag;
public string PageName
{
get => pageName;
set => SetProperty(ref pageName, value);
}
private GifImage loading;
public GifImage Loading
{
@ -138,7 +145,7 @@ namespace DownKyi.ViewModels
ArrowBack.Fill = DictionaryResource.GetColor("ColorText");
// 结束任务
tokenSource.Cancel();
tokenSource?.Cancel();
NavigationParam parameter = new NavigationParam
{
@ -288,12 +295,12 @@ namespace DownKyi.ViewModels
LoadingVisibility = Visibility.Visible;
NoDataVisibility = Visibility.Collapsed;
UpdatePublication(current);
UpdateChannel(current);
return true;
}
private async void UpdatePublication(int current)
private async void UpdateChannel(int current)
{
// 是否正在获取数据
// 在所有的退出分支中都需要设为true
@ -361,7 +368,7 @@ namespace DownKyi.ViewModels
App.PropertyChangeAsync(new Action(() =>
{
ChannelMedia media = new ChannelMedia
ChannelMedia media = new ChannelMedia(eventAggregator)
{
Avid = video.Aid,
Bvid = video.Bvid,
@ -371,7 +378,7 @@ namespace DownKyi.ViewModels
PlayNumber = play,
CreateTime = ctime
};
medias.Add(media);
Medias.Add(media);
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Collapsed;
@ -398,6 +405,7 @@ namespace DownKyi.ViewModels
base.OnNavigatedTo(navigationContext);
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
Medias.Clear();
// 根据传入参数不同执行不同任务
var parameter = navigationContext.Parameters.GetValue<Dictionary<string, object>>("Parameter");

@ -0,0 +1,472 @@
using DownKyi.Core.BiliApi.Favorites;
using DownKyi.Core.BiliApi.VideoStream;
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.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace DownKyi.ViewModels
{
public class ViewMyFavoritesViewModel : BaseViewModel
{
public const string Tag = "PageMyFavorites";
private readonly IDialogService dialogService;
private CancellationTokenSource tokenSource1;
private CancellationTokenSource tokenSource2;
private long mid = -1;
// 每页视频数量,暂时在此写死,以后在设置中增加选项
private readonly int VideoNumberInPage = 20;
#region 页面属性申明
private string pageName = Tag;
public string PageName
{
get => pageName;
set => SetProperty(ref pageName, value);
}
private Visibility contentVisibility;
public Visibility ContentVisibility
{
get => contentVisibility;
set => SetProperty(ref contentVisibility, 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);
}
private GifImage mediaLoading;
public GifImage MediaLoading
{
get => mediaLoading;
set => SetProperty(ref mediaLoading, value);
}
private Visibility mediaLoadingVisibility;
public Visibility MediaLoadingVisibility
{
get => mediaLoadingVisibility;
set => SetProperty(ref mediaLoadingVisibility, value);
}
private Visibility mediaNoDataVisibility;
public Visibility MediaNoDataVisibility
{
get => mediaNoDataVisibility;
set => SetProperty(ref mediaNoDataVisibility, value);
}
private VectorImage arrowBack;
public VectorImage ArrowBack
{
get => arrowBack;
set => SetProperty(ref arrowBack, value);
}
private ObservableCollection<TabHeader> tabHeaders;
public ObservableCollection<TabHeader> TabHeaders
{
get => tabHeaders;
set => SetProperty(ref tabHeaders, value);
}
private int selectTabId;
public int SelectTabId
{
get => selectTabId;
set => SetProperty(ref selectTabId, value);
}
private bool isEnabled = true;
public bool IsEnabled
{
get => isEnabled;
set => SetProperty(ref isEnabled, value);
}
private CustomPagerViewModel pager;
public CustomPagerViewModel Pager
{
get => pager;
set => SetProperty(ref pager, value);
}
private ObservableCollection<FavoritesMedia> medias;
public ObservableCollection<FavoritesMedia> Medias
{
get => medias;
set => SetProperty(ref medias, value);
}
private bool isSelectAll;
public bool IsSelectAll
{
get => isSelectAll;
set => SetProperty(ref isSelectAll, value);
}
#endregion
public ViewMyFavoritesViewModel(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;
MediaLoading = new GifImage(Properties.Resources.loading);
MediaLoading.StartAnimate();
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
ArrowBack = NavigationIcon.Instance().ArrowBack;
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
TabHeaders = new ObservableCollection<TabHeader>();
Medias = new ObservableCollection<FavoritesMedia>();
#endregion
}
#region 命令申明
// 返回事件
private DelegateCommand backSpaceCommand;
public DelegateCommand BackSpaceCommand => backSpaceCommand ?? (backSpaceCommand = new DelegateCommand(ExecuteBackSpace));
/// <summary>
/// 返回事件
/// </summary>
private void ExecuteBackSpace()
{
InitView();
ArrowBack.Fill = DictionaryResource.GetColor("ColorText");
// 结束任务
tokenSource1?.Cancel();
tokenSource2?.Cancel();
NavigationParam parameter = new NavigationParam
{
ViewName = ParentView,
ParentViewName = null,
Parameter = null
};
eventAggregator.GetEvent<NavigationEvent>().Publish(parameter);
}
// 左侧tab点击事件
private DelegateCommand<object> leftTabHeadersCommand;
public DelegateCommand<object> LeftTabHeadersCommand => leftTabHeadersCommand ?? (leftTabHeadersCommand = new DelegateCommand<object>(ExecuteLeftTabHeadersCommand, CanExecuteLeftTabHeadersCommand));
/// <summary>
/// 左侧tab点击事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteLeftTabHeadersCommand(object parameter)
{
if (!(parameter is TabHeader tabHeader)) { return; }
// 页面选择
Pager = new CustomPagerViewModel(1, (int)Math.Ceiling(double.Parse(tabHeader.SubTitle) / VideoNumberInPage));
Pager.CurrentChanged += OnCurrentChanged_Pager;
Pager.CountChanged += OnCountChanged_Pager;
Pager.Current = 1;
}
/// <summary>
/// 左侧tab点击事件是否允许执行
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
private bool CanExecuteLeftTabHeadersCommand(object parameter)
{
return IsEnabled;
}
// 全选按钮点击事件
private DelegateCommand<object> selectAllCommand;
public DelegateCommand<object> SelectAllCommand => selectAllCommand ?? (selectAllCommand = new DelegateCommand<object>(ExecuteSelectAllCommand));
/// <summary>
/// 全选按钮点击事件
/// </summary>
/// <param name="parameter"></param>
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<object> mediasCommand;
public DelegateCommand<object> MediasCommand => mediasCommand ?? (mediasCommand = new DelegateCommand<object>(ExecuteMediasCommand));
/// <summary>
/// 列表选择事件
/// </summary>
/// <param name="parameter"></param>
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));
/// <summary>
/// 添加选中项到下载列表事件
/// </summary>
private void ExecuteAddToDownloadCommand()
{
AddToDownload(true);
}
// 添加所有视频到下载列表事件
private DelegateCommand addAllToDownloadCommand;
public DelegateCommand AddAllToDownloadCommand => addAllToDownloadCommand ?? (addAllToDownloadCommand = new DelegateCommand(ExecuteAddAllToDownloadCommand));
/// <summary>
/// 添加所有视频到下载列表事件
/// </summary>
private void ExecuteAddAllToDownloadCommand()
{
AddToDownload(false);
}
#endregion
/// <summary>
/// 添加到下载
/// </summary>
/// <param name="isOnlySelected"></param>
private async void AddToDownload(bool isOnlySelected)
{
// 收藏夹里只有视频
AddToDownloadService addToDownloadService = new AddToDownloadService(PlayStreamType.VIDEO);
// 选择文件夹
string directory = addToDownloadService.SetDirectory(dialogService);
// 视频计数
int i = 0;
await Task.Run(() =>
{
// 添加到下载
foreach (var media in Medias)
{
// 只下载选中项,跳过未选中项
if (isOnlySelected && !media.IsSelected) { continue; }
/// 有分P的就下载全部
// 开启服务
VideoInfoService videoInfoService = new VideoInfoService(media.Bvid);
addToDownloadService.SetVideoInfoService(videoInfoService);
addToDownloadService.GetVideo();
addToDownloadService.ParseVideo(videoInfoService);
// 下载
i += addToDownloadService.AddToDownload(eventAggregator, directory);
}
});
if (directory == null)
{
return;
}
// 通知用户添加到下载列表的结果
if (i == 0)
{
eventAggregator.GetEvent<MessageEvent>().Publish(DictionaryResource.GetString("TipAddDownloadingZero"));
}
else
{
eventAggregator.GetEvent<MessageEvent>().Publish($"{DictionaryResource.GetString("TipAddDownloadingFinished1")}{i}{DictionaryResource.GetString("TipAddDownloadingFinished2")}");
}
}
private void OnCountChanged_Pager(int count) { }
private bool OnCurrentChanged_Pager(int old, int current)
{
if (!IsEnabled)
{
//Pager.Current = old;
return false;
}
UpdateFavoritesMediaList(current);
return true;
}
private async void UpdateFavoritesMediaList(int current)
{
Medias.Clear();
MediaLoadingVisibility = Visibility.Visible;
MediaNoDataVisibility = Visibility.Collapsed;
// 是否正在获取数据
// 在所有的退出分支中都需要设为true
IsEnabled = false;
var tab = TabHeaders[SelectTabId];
await Task.Run(new Action(() =>
{
CancellationToken cancellationToken = tokenSource2.Token;
List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias = FavoritesResource.GetFavoritesMedia(tab.Id, current, VideoNumberInPage);
if (medias == null || medias.Count == 0)
{
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Visible;
return;
}
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
var service = new FavoritesService();
service.GetFavoritesMediaList(medias, Medias, eventAggregator, cancellationToken);
}), (tokenSource2 = new CancellationTokenSource()).Token);
IsEnabled = true;
}
/// <summary>
/// 初始化页面数据
/// </summary>
private void InitView()
{
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
ContentVisibility = Visibility.Collapsed;
LoadingVisibility = Visibility.Visible;
NoDataVisibility = Visibility.Collapsed;
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
TabHeaders.Clear();
Medias.Clear();
SelectTabId = -1;
}
/// <summary>
/// 导航到VideoDetail页面时执行
/// </summary>
/// <param name="navigationContext"></param>
public override async void OnNavigatedTo(NavigationContext navigationContext)
{
base.OnNavigatedTo(navigationContext);
// 根据传入参数不同执行不同任务
mid = navigationContext.Parameters.GetValue<long>("Parameter");
if (mid == 0)
{
return;
}
InitView();
await Task.Run(new Action(() =>
{
CancellationToken cancellationToken = tokenSource1.Token;
var service = new FavoritesService();
service.GetCreatedFavorites(mid, TabHeaders, cancellationToken);
service.GetCollectedFavorites(mid, TabHeaders, cancellationToken);
}), (tokenSource1 = new CancellationTokenSource()).Token);
if (TabHeaders.Count == 0)
{
ContentVisibility = Visibility.Collapsed;
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Visible;
return;
}
ContentVisibility = Visibility.Visible;
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Collapsed;
// 初始选中项
SelectTabId = 0;
// 页面选择
Pager = new CustomPagerViewModel(1, (int)Math.Ceiling(double.Parse(TabHeaders[0].SubTitle) / VideoNumberInPage));
Pager.CurrentChanged += OnCurrentChanged_Pager;
Pager.CountChanged += OnCountChanged_Pager;
Pager.Current = 1;
}
}
}

@ -340,7 +340,7 @@ namespace DownKyi.ViewModels
switch (SelectedPackage)
{
case 0:
Console.WriteLine(SelectedPackage);
NavigateToView.NavigationView(eventAggregator, ViewMyFavoritesViewModel.Tag, Tag, mid);
break;
case 1:
Console.WriteLine(SelectedPackage);

@ -1,5 +1,7 @@
using DownKyi.Core.BiliApi.VideoStream;
using DownKyi.Core.BiliApi.Favorites;
using DownKyi.Core.BiliApi.VideoStream;
using DownKyi.Core.Logging;
using DownKyi.CustomControl;
using DownKyi.Events;
using DownKyi.Images;
using DownKyi.Services;
@ -11,7 +13,9 @@ using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
@ -23,6 +27,8 @@ namespace DownKyi.ViewModels
private readonly IDialogService dialogService;
private CancellationTokenSource tokenSource;
#region 页面属性申明
private string pageName = Tag;
@ -60,6 +66,21 @@ namespace DownKyi.ViewModels
set => SetProperty(ref contentVisibility, 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
{
@ -67,6 +88,27 @@ namespace DownKyi.ViewModels
set => SetProperty(ref noDataVisibility, value);
}
private GifImage mediaLoading;
public GifImage MediaLoading
{
get => mediaLoading;
set => SetProperty(ref mediaLoading, value);
}
private Visibility mediaLoadingVisibility;
public Visibility MediaLoadingVisibility
{
get => mediaLoadingVisibility;
set => SetProperty(ref mediaLoadingVisibility, value);
}
private Visibility mediaNoDataVisibility;
public Visibility MediaNoDataVisibility
{
get => mediaNoDataVisibility;
set => SetProperty(ref mediaNoDataVisibility, value);
}
#endregion
public ViewPublicFavoritesViewModel(IEventAggregator eventAggregator, IDialogService dialogService) : base(eventAggregator)
@ -75,6 +117,17 @@ namespace DownKyi.ViewModels
#region 属性初始化
// 初始化loading gif
Loading = new GifImage(Properties.Resources.loading);
Loading.StartAnimate();
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Collapsed;
MediaLoading = new GifImage(Properties.Resources.loading);
MediaLoading.StartAnimate();
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
ArrowBack = NavigationIcon.Instance().ArrowBack;
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
@ -94,6 +147,9 @@ namespace DownKyi.ViewModels
/// </summary>
private void ExecuteBackSpace()
{
// 结束任务
tokenSource?.Cancel();
NavigationParam parameter = new NavigationParam
{
ViewName = ParentView,
@ -238,7 +294,10 @@ namespace DownKyi.ViewModels
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
ContentVisibility = Visibility.Collapsed;
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Collapsed;
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
FavoritesMedias.Clear();
}
@ -246,24 +305,43 @@ namespace DownKyi.ViewModels
/// <summary>
/// 更新页面
/// </summary>
private void UpdateView(IFavoritesService favoritesService, long favoritesId)
private void UpdateView(IFavoritesService favoritesService, long favoritesId, CancellationToken cancellationToken)
{
LoadingVisibility = Visibility.Visible;
Favorites = favoritesService.GetFavorites(favoritesId);
if (Favorites == null)
{
LogManager.Debug(Tag, "Favorites is null.");
ContentVisibility = Visibility.Collapsed;
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Visible;
return;
}
else
{
ContentVisibility = Visibility.Visible;
LoadingVisibility = Visibility.Collapsed;
NoDataVisibility = Visibility.Collapsed;
}
favoritesService.GetFavoritesMediaList(favoritesId, FavoritesMedias, eventAggregator);
MediaLoadingVisibility = Visibility.Visible;
List<Core.BiliApi.Favorites.Models.FavoritesMedia> medias = FavoritesResource.GetAllFavoritesMedia(favoritesId);
if (medias == null || medias.Count == 0)
{
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Visible;
return;
}
else
{
MediaLoadingVisibility = Visibility.Collapsed;
MediaNoDataVisibility = Visibility.Collapsed;
}
favoritesService.GetFavoritesMediaList(medias, FavoritesMedias, eventAggregator, cancellationToken);
}
/// <summary>
@ -284,8 +362,10 @@ namespace DownKyi.ViewModels
InitView();
await Task.Run(new Action(() =>
{
UpdateView(new FavoritesService(), parameter);
}));
CancellationToken cancellationToken = tokenSource.Token;
UpdateView(new FavoritesService(), parameter, cancellationToken);
}), (tokenSource = new CancellationTokenSource()).Token);
}
}

@ -40,6 +40,13 @@ namespace DownKyi.ViewModels
#region 页面属性申明
private string pageName = Tag;
public string PageName
{
get => pageName;
set => SetProperty(ref pageName, value);
}
private GifImage loading;
public GifImage Loading
{
@ -147,7 +154,7 @@ namespace DownKyi.ViewModels
ArrowBack.Fill = DictionaryResource.GetColor("ColorText");
// 结束任务
tokenSource.Cancel();
tokenSource?.Cancel();
NavigationParam parameter = new NavigationParam
{
@ -398,7 +405,7 @@ namespace DownKyi.ViewModels
App.PropertyChangeAsync(new Action(() =>
{
PublicationMedia media = new PublicationMedia
PublicationMedia media = new PublicationMedia(eventAggregator)
{
Avid = video.Aid,
Bvid = video.Bvid,
@ -433,6 +440,7 @@ namespace DownKyi.ViewModels
ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark");
TabHeaders.Clear();
Medias.Clear();
SelectTabId = -1;
}
@ -444,8 +452,6 @@ namespace DownKyi.ViewModels
{
base.OnNavigatedTo(navigationContext);
InitView();
// 根据传入参数不同执行不同任务
var parameter = navigationContext.Parameters.GetValue<Dictionary<string, object>>("Parameter");
if (parameter == null)
@ -453,6 +459,8 @@ namespace DownKyi.ViewModels
return;
}
InitView();
mid = (long)parameter["mid"];
int tid = (int)parameter["tid"];
List<PublicationZone> zones = (List<PublicationZone>)parameter["list"];

@ -65,7 +65,7 @@
ToolTip="{Binding Title}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding TitleCommand}" CommandParameter="{Binding Bvid}" />
<i:InvokeCommandAction Command="{Binding TitleCommand}" CommandParameter="{Binding DataContext.PageName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>

@ -0,0 +1,373 @@
<UserControl
x:Class="DownKyi.Views.ViewMyFavorites"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:DownKyi.CustomControl"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
<UserControl.Resources>
<Style x:Key="MediaListStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding IsSelected}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid
Name="nameMediaPanel"
Width="190"
Margin="15,15,10,5">
<Grid.RowDefinitions>
<RowDefinition Height="115" />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Border
Name="nameCover"
Grid.Row="0"
Width="185"
Height="115"
HorizontalAlignment="Center"
CornerRadius="5">
<Border.Background>
<!-- 长宽比1.6 -->
<ImageBrush ImageSource="{Binding Cover}" />
</Border.Background>
<Border
Name="nameInfoPanel"
Background="{DynamicResource BrushMask}"
CornerRadius="5"
Visibility="Hidden">
<StackPanel Margin="20,0,0,0" VerticalAlignment="Center">
<StackPanel Height="20" Orientation="Horizontal">
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{DynamicResource FavoritesPlayNumber}" />
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{Binding PlayNumber}" />
</StackPanel>
<StackPanel Height="20" Orientation="Horizontal">
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{DynamicResource FavoritesFavoriteNumber}" />
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{Binding FavoriteNumber}" />
</StackPanel>
<StackPanel Height="20" Orientation="Horizontal">
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{DynamicResource FavoritesUpName}" />
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{Binding UpName}" />
</StackPanel>
<StackPanel Height="20" Orientation="Horizontal">
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{DynamicResource FavoritesCreateTime}" />
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushText}"
Text="{Binding CreateTime}" />
</StackPanel>
</StackPanel>
</Border>
</Border>
<Image
Name="nameChecked"
Grid.Row="0"
Width="24"
Height="24"
Margin="0,10,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Source="/DownKyi;component/Resources/checked.png" />
<TextBlock
Name="nameTitle"
Grid.Row="1"
Width="185"
Height="35"
Margin="0,5"
Cursor="Hand"
Foreground="{DynamicResource BrushTextDark}"
Tag="{Binding Bvid}"
Text="{Binding Title}"
TextTrimming="CharacterEllipsis"
TextWrapping="WrapWithOverflow"
ToolTip="{Binding Title}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding TitleCommand}" CommandParameter="{Binding DataContext.PageName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushTextGrey}"
Text="{DynamicResource FavoritesFavTime}" />
<TextBlock
FontSize="12"
Foreground="{DynamicResource BrushTextGrey}"
Text="{Binding FavTime}" />
</StackPanel>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="nameChecked" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="nameChecked" Property="Visibility" Value="Hidden" />
</Trigger>
<Trigger SourceName="nameCover" Property="IsMouseOver" Value="True">
<Setter TargetName="nameInfoPanel" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger SourceName="nameTitle" Property="IsMouseOver" Value="True">
<Setter TargetName="nameTitle" Property="Foreground" Value="{DynamicResource BrushPrimary}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="1" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<Button
Grid.Column="0"
Margin="10,5,0,5"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Command="{Binding BackSpaceCommand}"
Style="{StaticResource ImageBtnStyle}">
<StackPanel Orientation="Horizontal">
<ContentControl Width="24" Height="24">
<Path
Width="{Binding ArrowBack.Width}"
Height="{Binding ArrowBack.Height}"
Data="{Binding ArrowBack.Data}"
Fill="{Binding ArrowBack.Fill}"
Stretch="None" />
</ContentControl>
<TextBlock
VerticalAlignment="Center"
FontSize="16"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource PublicFavorites}" />
</StackPanel>
</Button>
</Grid>
<TextBlock Grid.Row="1" Background="{DynamicResource BrushBorder}" />
<Grid Grid.Row="2" Visibility="{Binding ContentVisibility}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!-- 左侧tab header -->
<ListBox
Name="nameLeftTabHeaders"
Grid.Column="0"
BorderThickness="0"
IsEnabled="{Binding IsEnabled}"
ItemContainerStyle="{StaticResource LeftTabHeaderItemStyle}"
ItemsSource="{Binding TabHeaders}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
SelectedIndex="{Binding SelectTabId, Mode=TwoWay}"
Style="{StaticResource LeftTabHeaderStyle}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding LeftTabHeadersCommand}" CommandParameter="{Binding ElementName=nameLeftTabHeaders, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<Grid Name="nameMediaPanel" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="1" />
<RowDefinition Height="49" />
</Grid.RowDefinitions>
<ListBox
x:Name="nameMedias"
Grid.Row="0"
BorderThickness="0"
ItemContainerStyle="{StaticResource MediaListStyle}"
ItemsSource="{Binding Medias}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectionMode="Extended">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding MediasCommand}" CommandParameter="{Binding ElementName=nameMedias, Path=SelectedItems}" />
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Style>
<Style TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Border
x:Name="Bd"
Padding="0"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer Focusable="False">
<ItemsPresenter />
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.Style>
</ListBox>
<!-- 加载gif -->
<StackPanel
Grid.Row="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{Binding MediaLoadingVisibility}">
<ContentControl
Width="40"
Height="40"
Content="{Binding MediaLoading}" />
</StackPanel>
<!-- 没有数据提示 -->
<Image
Grid.Row="0"
Width="256"
Height="256"
Source="/DownKyi;component/Resources/no-data.png"
Visibility="{Binding MediaNoDataVisibility}" />
<TextBlock Grid.Row="1" Background="{DynamicResource BrushBorder}" />
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80" />
<ColumnDefinition />
<ColumnDefinition Width="100" />
<ColumnDefinition Width="80" />
</Grid.ColumnDefinitions>
<CheckBox
Grid.Column="0"
Margin="10,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Command="{Binding SelectAllCommand}"
CommandParameter="{Binding ElementName=nameMedias, Path=SelectedItem}"
Content="{DynamicResource SelectAll}"
Foreground="{DynamicResource BrushTextDark}"
IsChecked="{Binding IsSelectAll, Mode=TwoWay}"
Style="{StaticResource CheckBoxStyle}" />
<custom:CustomPager
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
DataContext="{Binding Pager}" />
<Button
Grid.Column="2"
Margin="0,0,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Command="{Binding AddToDownloadCommand}"
Content="{DynamicResource DownloadSelectedPublication}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}" />
<Button
Grid.Column="3"
Margin="0,0,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Command="{Binding AddAllToDownloadCommand}"
Content="{DynamicResource DownloadAllPublication}"
FontSize="12"
Foreground="{DynamicResource BrushText}"
Style="{StaticResource BtnStyle}" />
</Grid>
</Grid>
</Grid>
<!-- 加载gif -->
<StackPanel
Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{Binding LoadingVisibility}">
<ContentControl
Width="40"
Height="40"
Content="{Binding Loading}" />
<TextBlock
Margin="0,10,0,0"
FontSize="14"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource PublicationWait}" />
</StackPanel>
<!-- 没有数据提示 -->
<Image
Grid.Row="2"
Width="256"
Height="256"
Source="/DownKyi;component/Resources/no-data.png"
Visibility="{Binding NoDataVisibility}" />
</Grid>
</UserControl>

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace DownKyi.Views
{
/// <summary>
/// ViewMyFavorites.xaml 的交互逻辑
/// </summary>
public partial class ViewMyFavorites : UserControl
{
public ViewMyFavorites()
{
InitializeComponent();
}
}
}

@ -468,8 +468,39 @@
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
<!-- 加载gif -->
<StackPanel
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{Binding MediaLoadingVisibility}">
<ContentControl
Width="40"
Height="40"
Content="{Binding MediaLoading}" />
</StackPanel>
</Grid>
<!-- 加载gif -->
<StackPanel
Grid.Row="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Vertical"
Visibility="{Binding LoadingVisibility}">
<ContentControl
Width="40"
Height="40"
Content="{Binding Loading}" />
<TextBlock
Margin="0,10,0,0"
FontSize="14"
Foreground="{DynamicResource BrushTextDark}"
Text="{DynamicResource PublicationWait}" />
</StackPanel>
<!-- 没有数据提示 -->
<Image
Grid.Row="2"

@ -65,7 +65,7 @@
ToolTip="{Binding Title}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<i:InvokeCommandAction Command="{Binding TitleCommand}" CommandParameter="{Binding Bvid}" />
<i:InvokeCommandAction Command="{Binding TitleCommand}" CommandParameter="{Binding DataContext.PageName, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>

Loading…
Cancel
Save