diff --git a/DownKyi/App.xaml.cs b/DownKyi/App.xaml.cs index 59124ef..b82f7a6 100644 --- a/DownKyi/App.xaml.cs +++ b/DownKyi/App.xaml.cs @@ -164,6 +164,7 @@ namespace DownKyi containerRegistry.RegisterForNavigation(ViewUserSpaceViewModel.Tag); containerRegistry.RegisterForNavigation(ViewMySpaceViewModel.Tag); containerRegistry.RegisterForNavigation(ViewPublicFavoritesViewModel.Tag); + containerRegistry.RegisterForNavigation(ViewPublicationViewModel.Tag); // downloadManager pages containerRegistry.RegisterForNavigation(ViewDownloadingViewModel.Tag); diff --git a/DownKyi/CustomControl/CustomPager.xaml b/DownKyi/CustomControl/CustomPager.xaml new file mode 100644 index 0000000..22c53aa --- /dev/null +++ b/DownKyi/CustomControl/CustomPager.xaml @@ -0,0 +1,325 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DownKyi/CustomControl/CustomPager.xaml.cs b/DownKyi/CustomControl/CustomPager.xaml.cs new file mode 100644 index 0000000..fca169d --- /dev/null +++ b/DownKyi/CustomControl/CustomPager.xaml.cs @@ -0,0 +1,275 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace DownKyi.ui.CustomControl +{ + /// + /// CustomPager.xaml 的交互逻辑 + /// + public partial class CustomPager : UserControl + { + public CustomPager() + { + InitializeComponent(); + DataContext = this; + } + + // Current修改的回调 + public delegate void CurrentChangedHandler(int current); + public event CurrentChangedHandler CurrentChanged; + protected virtual void OnCurrentChanged(int current) + { + CurrentChanged?.Invoke(current); + } + + // Count修改的回调 + public delegate void CountChangedHandler(int current); + public event CountChangedHandler CountChanged; + protected virtual void OnCountChanged(int count) + { + CountChanged?.Invoke(count); + } + + private int current; + public int Current + { + get + { + var value = GetValue(CurrentProperty); + if (value == null) { return 1; } + + if ((int)value < 1) + { + return 1; + } + return (int)value; + } + set + { + SetValue(CurrentProperty, value); + + if (Count > 0 && (value > Count || value < 1)) + { + //throw new Exception("数值不在允许的范围内。"); + } + else + { + current = value; + SetView(); + + OnCurrentChanged(current); + } + } + } + + public static readonly DependencyProperty CurrentProperty = + DependencyProperty.Register( + "Current", + typeof(object), + typeof(CustomPager), + new PropertyMetadata(default, OnCurrentPropertyChanged)); + + private static void OnCurrentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + //CustomPager source = d as CustomPager; + } + + //private int count; + public int Count + { + get + { + return (int)GetValue(CountProperty); + } + set + { + SetValue(CountProperty, value); + + //if (value < Current || value < 1) + //{ + // //throw new Exception("数值不在允许的范围内。"); + //} + //else + //{ + // count = value; + // if (count == 1) { Visibility = Visibility.Hidden; } + // else { Visibility = Visibility.Visible; } + + // SetView(); + + // OnCountChanged(count); + //} + } + } + + public static readonly DependencyProperty CountProperty = + DependencyProperty.Register( + "Count", + typeof(object), + typeof(CustomPager), + new PropertyMetadata(default, OnCountPropertyChanged)); + + private static void OnCountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + CustomPager source = d as CustomPager; + + if ((int)e.NewValue < source.Current || (int)e.NewValue < 1) + { + //throw new Exception("数值不在允许的范围内。"); + } + else + { + //source.Count = (int)e.NewValue; + if (source.Count == 1) { source.Visibility = Visibility.Hidden; } + else { source.Visibility = Visibility.Visible; } + + source.SetView(); + + source.OnCountChanged(source.Count); + } + } + + private void Previous_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current -= 1; + } + + private void First_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current = 1; + } + + private void PreviousSecond_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current -= 2; + } + + private void PreviousFirst_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current -= 1; + } + + private void Current_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { } + + private void NextFirst_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current += 1; + } + + private void NextSecond_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current += 2; + } + + private void Last_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current = Count; + } + + private void Next_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + Current += 1; + } + + /// + /// 控制显示,暴力实现,以后重构 + /// + protected void SetView() + { + nameFirstText.Text = "1"; + namePreviousSecondText.Text = (Current - 2).ToString(); + namePreviousFirstText.Text = (Current - 1).ToString(); + nameCurrentText.Text = Current.ToString(); + nameNextFirstText.Text = (Current + 1).ToString(); + nameNextSecondText.Text = (Current + 2).ToString(); + nameLastText.Text = Count.ToString(); + + // 控制Current左边的控件 + if (Current == 1) + { + namePrevious.Visibility = Visibility.Collapsed; + nameFirst.Visibility = Visibility.Collapsed; + nameLeftJump.Visibility = Visibility.Collapsed; + namePreviousSecond.Visibility = Visibility.Collapsed; + namePreviousFirst.Visibility = Visibility.Collapsed; + } + else if (Current == 2) + { + namePrevious.Visibility = Visibility.Visible; + nameFirst.Visibility = Visibility.Collapsed; + nameLeftJump.Visibility = Visibility.Collapsed; + namePreviousSecond.Visibility = Visibility.Collapsed; + namePreviousFirst.Visibility = Visibility.Visible; + } + else if (Current == 3) + { + namePrevious.Visibility = Visibility.Visible; + nameFirst.Visibility = Visibility.Collapsed; + nameLeftJump.Visibility = Visibility.Collapsed; + namePreviousSecond.Visibility = Visibility.Visible; + namePreviousFirst.Visibility = Visibility.Visible; + } + else if (Current == 4) + { + namePrevious.Visibility = Visibility.Visible; + nameFirst.Visibility = Visibility.Visible; + nameLeftJump.Visibility = Visibility.Collapsed; + namePreviousSecond.Visibility = Visibility.Visible; + namePreviousFirst.Visibility = Visibility.Visible; + } + else + { + namePrevious.Visibility = Visibility.Visible; + nameFirst.Visibility = Visibility.Visible; + nameLeftJump.Visibility = Visibility.Visible; + namePreviousSecond.Visibility = Visibility.Visible; + namePreviousFirst.Visibility = Visibility.Visible; + } + + // 控制Current右边的控件 + if (Current == Count) + { + nameNextFirst.Visibility = Visibility.Collapsed; + nameNextSecond.Visibility = Visibility.Collapsed; + nameRightJump.Visibility = Visibility.Collapsed; + nameLast.Visibility = Visibility.Collapsed; + nameNext.Visibility = Visibility.Collapsed; + } + else if (Current == Count - 1) + { + nameNextFirst.Visibility = Visibility.Visible; + nameNextSecond.Visibility = Visibility.Collapsed; + nameRightJump.Visibility = Visibility.Collapsed; + nameLast.Visibility = Visibility.Collapsed; + nameNext.Visibility = Visibility.Visible; + } + else if (Current == Count - 2) + { + nameNextFirst.Visibility = Visibility.Visible; + nameNextSecond.Visibility = Visibility.Visible; + nameRightJump.Visibility = Visibility.Collapsed; + nameLast.Visibility = Visibility.Collapsed; + nameNext.Visibility = Visibility.Visible; + } + else if (Current == Count - 3) + { + nameNextFirst.Visibility = Visibility.Visible; + nameNextSecond.Visibility = Visibility.Visible; + nameRightJump.Visibility = Visibility.Collapsed; + nameLast.Visibility = Visibility.Visible; + nameNext.Visibility = Visibility.Visible; + } + else + { + nameNextFirst.Visibility = Visibility.Visible; + nameNextSecond.Visibility = Visibility.Visible; + nameRightJump.Visibility = Visibility.Visible; + nameLast.Visibility = Visibility.Visible; + nameNext.Visibility = Visibility.Visible; + } + } + + } +} diff --git a/DownKyi/DownKyi.csproj b/DownKyi/DownKyi.csproj index 1727b3b..01c4758 100644 --- a/DownKyi/DownKyi.csproj +++ b/DownKyi/DownKyi.csproj @@ -80,6 +80,9 @@ Designer + + CustomPager.xaml + @@ -145,6 +148,7 @@ + @@ -208,6 +212,9 @@ ViewMySpace.xaml + + ViewPublication.xaml + ViewPublicFavorites.xaml @@ -223,6 +230,10 @@ ViewVideoDetail.xaml + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -379,6 +390,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/DownKyi/Languages/Default.xaml b/DownKyi/Languages/Default.xaml index 60c0bdb..40dd37b 100644 --- a/DownKyi/Languages/Default.xaml +++ b/DownKyi/Languages/Default.xaml @@ -64,6 +64,14 @@ 投稿视频 频道 + + 收藏夹 + 个内容 + + + 下载选中项 + 下载全部 + 复制封面图片 复制封面URL @@ -252,10 +260,6 @@ 提取音频 提取视频 - - 收藏夹 - 个内容 - 取消 请选择文件夹 diff --git a/DownKyi/Themes/Styles/StyleListBox.xaml b/DownKyi/Themes/Styles/StyleListBox.xaml index 5edeebd..9db2e98 100644 --- a/DownKyi/Themes/Styles/StyleListBox.xaml +++ b/DownKyi/Themes/Styles/StyleListBox.xaml @@ -6,7 +6,13 @@ + + + + + + + Foreground="{DynamicResource BrushTextDark}" + Text="{Binding Title}" + TextTrimming="CharacterEllipsis" /> + + diff --git a/DownKyi/ViewModels/UserSpace/ViewArchiveViewModel.cs b/DownKyi/ViewModels/UserSpace/ViewArchiveViewModel.cs index 8f2cea5..407000d 100644 --- a/DownKyi/ViewModels/UserSpace/ViewArchiveViewModel.cs +++ b/DownKyi/ViewModels/UserSpace/ViewArchiveViewModel.cs @@ -1,10 +1,13 @@ using DownKyi.Core.BiliApi.Users.Models; using DownKyi.Core.BiliApi.Zone; +using DownKyi.Events; using DownKyi.Utils; +using Prism.Commands; using Prism.Events; using Prism.Regions; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Windows; using System.Windows.Media; @@ -12,7 +15,9 @@ namespace DownKyi.ViewModels.UserSpace { public class ViewArchiveViewModel : BaseViewModel { - public const string Tag = "ArchiveView"; + public const string Tag = "PageUserSpaceArchiveView"; + + private long mid = -1; #region 页面属性申明 @@ -23,6 +28,13 @@ namespace DownKyi.ViewModels.UserSpace set => SetProperty(ref publicationZones, value); } + private int selectedItem; + public int SelectedItem + { + get => selectedItem; + set => SetProperty(ref selectedItem, value); + } + #endregion public ViewArchiveViewModel(IEventAggregator eventAggregator) : base(eventAggregator) @@ -35,6 +47,38 @@ namespace DownKyi.ViewModels.UserSpace } #region 命令申明 + + // 视频选择事件 + private DelegateCommand publicationZonesCommand; + public DelegateCommand PublicationZonesCommand => publicationZonesCommand ?? (publicationZonesCommand = new DelegateCommand(ExecutePublicationZonesCommand)); + + /// + /// 视频选择事件 + /// + /// + private void ExecutePublicationZonesCommand(object parameter) + { + if (!(parameter is PublicationZone zone)) { return; } + + Dictionary data = new Dictionary + { + { "mid", mid }, + { "tid", zone.Tid }, + { "list", PublicationZones.ToList() } + }; + + // 进入视频页面 + NavigationParam param = new NavigationParam + { + ViewName = ViewPublicationViewModel.Tag, + ParentViewName = ViewUserSpaceViewModel.Tag, + Parameter = data + }; + eventAggregator.GetEvent().Publish(param); + + SelectedItem = -1; + } + #endregion public override void OnNavigatedFrom(NavigationContext navigationContext) @@ -42,6 +86,7 @@ namespace DownKyi.ViewModels.UserSpace base.OnNavigatedFrom(navigationContext); PublicationZones.Clear(); + SelectedItem = -1; } /// @@ -53,6 +98,7 @@ namespace DownKyi.ViewModels.UserSpace base.OnNavigatedTo(navigationContext); PublicationZones.Clear(); + SelectedItem = -1; // 根据传入参数不同执行不同任务 var parameter = navigationContext.Parameters.GetValue>("object"); @@ -61,6 +107,9 @@ namespace DownKyi.ViewModels.UserSpace return; } + // 传入mid + mid = navigationContext.Parameters.GetValue("mid"); + int VideoCount = 0; foreach (var zone in parameter) { diff --git a/DownKyi/ViewModels/UserSpace/ViewChannelViewModel.cs b/DownKyi/ViewModels/UserSpace/ViewChannelViewModel.cs index 88f2da9..f6f38c2 100644 --- a/DownKyi/ViewModels/UserSpace/ViewChannelViewModel.cs +++ b/DownKyi/ViewModels/UserSpace/ViewChannelViewModel.cs @@ -12,7 +12,7 @@ namespace DownKyi.ViewModels.UserSpace { public class ViewChannelViewModel : BaseViewModel { - public const string Tag = "Channel"; + public const string Tag = "PageUserSpaceChannel"; #region 页面属性申明 diff --git a/DownKyi/ViewModels/ViewPublicationViewModel.cs b/DownKyi/ViewModels/ViewPublicationViewModel.cs new file mode 100644 index 0000000..cdcec1e --- /dev/null +++ b/DownKyi/ViewModels/ViewPublicationViewModel.cs @@ -0,0 +1,171 @@ +using DownKyi.Events; +using DownKyi.Images; +using DownKyi.Utils; +using DownKyi.ViewModels.PageViewModels; +using DownKyi.ViewModels.UserSpace; +using Prism.Commands; +using Prism.Events; +using Prism.Regions; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DownKyi.ViewModels +{ + public class ViewPublicationViewModel : BaseViewModel + { + public const string Tag = "PagePublication"; + + private long mid = -1; + + // 每页视频数量,暂时在此写死,以后在设置中增加选项 + private readonly int VideoNumberInPage = 30; + + #region 页面属性申明 + + private VectorImage arrowBack; + public VectorImage ArrowBack + { + get => arrowBack; + set => SetProperty(ref arrowBack, value); + } + + private ObservableCollection tabHeaders; + public ObservableCollection TabHeaders + { + get => tabHeaders; + set => SetProperty(ref tabHeaders, value); + } + + private int selectTabId; + public int SelectTabId + { + get => selectTabId; + set => SetProperty(ref selectTabId, value); + } + + private int countPage; + public int CountPage + { + get => countPage; + set => SetProperty(ref countPage, value); + } + + private int currentPage; + public int CurrentPage + { + get => currentPage; + set => SetProperty(ref currentPage, value); + } + + #endregion + + public ViewPublicationViewModel(IEventAggregator eventAggregator) : base(eventAggregator) + { + #region 属性初始化 + + ArrowBack = NavigationIcon.Instance().ArrowBack; + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + + TabHeaders = new ObservableCollection(); + + #endregion + } + + #region 命令申明 + + // 返回事件 + private DelegateCommand backSpaceCommand; + public DelegateCommand BackSpaceCommand => backSpaceCommand ?? (backSpaceCommand = new DelegateCommand(ExecuteBackSpace)); + + /// + /// 返回事件 + /// + private void ExecuteBackSpace() + { + ArrowBack.Fill = DictionaryResource.GetColor("ColorText"); + + NavigationParam parameter = new NavigationParam + { + ViewName = ParentView, + ParentViewName = null, + Parameter = null + }; + eventAggregator.GetEvent().Publish(parameter); + } + + // 左侧tab点击事件 + private DelegateCommand leftTabHeadersCommand; + public DelegateCommand LeftTabHeadersCommand => leftTabHeadersCommand ?? (leftTabHeadersCommand = new DelegateCommand(ExecuteLeftTabHeadersCommand)); + + /// + /// 左侧tab点击事件 + /// + /// + private void ExecuteLeftTabHeadersCommand(object parameter) + { + if (!(parameter is TabHeader tabHeader)) { return; } + + // 页面选择 + CountPage = (int)Math.Ceiling(double.Parse(tabHeader.SubTitle) / VideoNumberInPage); + CurrentPage = 1; + } + + #endregion + + /// + /// 初始化页面数据 + /// + private void InitView() + { + ArrowBack.Fill = DictionaryResource.GetColor("ColorTextDark"); + + TabHeaders.Clear(); + SelectTabId = -1; + } + + /// + /// 导航到VideoDetail页面时执行 + /// + /// + public override void OnNavigatedTo(NavigationContext navigationContext) + { + base.OnNavigatedTo(navigationContext); + + InitView(); + + // 根据传入参数不同执行不同任务 + var parameter = navigationContext.Parameters.GetValue>("Parameter"); + if (parameter == null) + { + return; + } + + mid = (long)parameter["mid"]; + int tid = (int)parameter["tid"]; + List zones = (List)parameter["list"]; + + foreach (var item in zones) + { + TabHeaders.Add(new TabHeader + { + Id = item.Tid, + Title = item.Name, + SubTitle = item.Count.ToString() + }); + } + + // 初始选中项 + var selectTab = TabHeaders.FirstOrDefault(item => item.Id == tid); + SelectTabId = TabHeaders.IndexOf(selectTab); + + // 页面选择 + CountPage = (int)Math.Ceiling(double.Parse(selectTab.SubTitle) / VideoNumberInPage); + CurrentPage = 1; + } + + } +} diff --git a/DownKyi/ViewModels/ViewUserSpaceViewModel.cs b/DownKyi/ViewModels/ViewUserSpaceViewModel.cs index ba5b274..ad225bb 100644 --- a/DownKyi/ViewModels/ViewUserSpaceViewModel.cs +++ b/DownKyi/ViewModels/ViewUserSpaceViewModel.cs @@ -216,6 +216,7 @@ namespace DownKyi.ViewModels NavigationParameters param = new NavigationParameters() { { "object", banner.Object }, + { "mid", mid }, }; switch (banner.Id) diff --git a/DownKyi/Views/UserSpace/ViewArchive.xaml b/DownKyi/Views/UserSpace/ViewArchive.xaml index 52cc0e3..7854d6c 100644 --- a/DownKyi/Views/UserSpace/ViewArchive.xaml +++ b/DownKyi/Views/UserSpace/ViewArchive.xaml @@ -2,6 +2,7 @@ x:Class="DownKyi.Views.UserSpace.ViewArchive" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:prism="http://prismlibrary.com/" prism:ViewModelLocator.AutoWireViewModel="True"> @@ -10,9 +11,16 @@ + ScrollViewer.HorizontalScrollBarVisibility="Disabled" + SelectedIndex="{Binding SelectedItem}"> + + + + + diff --git a/DownKyi/Views/ViewPublication.xaml b/DownKyi/Views/ViewPublication.xaml new file mode 100644 index 0000000..e89810f --- /dev/null +++ b/DownKyi/Views/ViewPublication.xaml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +