diff --git a/src/App/Controls/Bili/BannerItem.cs b/src/App/Controls/Bili/BannerItem.cs index c2ec2681a3b8a090dae4e0e9f50439c6ccbb4f58..78030b77149376d34afdf282eb986310336fbedd 100644 --- a/src/App/Controls/Bili/BannerItem.cs +++ b/src/App/Controls/Bili/BannerItem.cs @@ -5,7 +5,6 @@ using Windows.System; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; namespace Richasy.Bili.App.Controls { @@ -18,7 +17,7 @@ namespace Richasy.Bili.App.Controls /// 的依赖属性. /// public static readonly DependencyProperty SourceProperty = - DependencyProperty.Register(nameof(Source), typeof(ImageSource), typeof(BannerItem), new PropertyMetadata(null)); + DependencyProperty.Register(nameof(Source), typeof(object), typeof(BannerItem), new PropertyMetadata(null)); /// /// 的依赖属性. @@ -43,9 +42,9 @@ namespace Richasy.Bili.App.Controls /// /// 图片源. /// - public ImageSource Source + public object Source { - get { return (ImageSource)GetValue(SourceProperty); } + get { return GetValue(SourceProperty); } set { SetValue(SourceProperty, value); } } @@ -85,6 +84,23 @@ namespace Richasy.Bili.App.Controls /// protected override void OnPointerReleased(PointerRoutedEventArgs e) + { + BackToNormal(e); + } + + /// + protected override void OnPointerCanceled(PointerRoutedEventArgs e) + { + BackToNormal(e); + } + + /// + protected override void OnPointerCaptureLost(PointerRoutedEventArgs e) + { + BackToNormal(e); + } + + private void BackToNormal(PointerRoutedEventArgs e) { VisualStateManager.GoToState(this, "NormalState", true); this.ReleasePointerCapture(e.Pointer); diff --git a/src/App/Controls/Bili/VideoView.xaml.cs b/src/App/Controls/Bili/VideoView.xaml.cs index f7492b34bba8017587c46eeab625efe4cb8c905e..17f6223037339050ef2a3bb103a7cf3c365a6594 100644 --- a/src/App/Controls/Bili/VideoView.xaml.cs +++ b/src/App/Controls/Bili/VideoView.xaml.cs @@ -50,6 +50,12 @@ namespace Richasy.Bili.App.Controls public static readonly DependencyProperty AdditionalContentProperty = DependencyProperty.Register(nameof(AdditionalContent), typeof(object), typeof(VideoView), new PropertyMetadata(null)); + /// + /// 的依赖属性. + /// + public static readonly DependencyProperty IsAutoFillEnableProperty = + DependencyProperty.Register(nameof(IsAutoFillEnable), typeof(bool), typeof(VideoView), new PropertyMetadata(true)); + private ScrollViewer _parentScrollViewer; /// @@ -67,12 +73,6 @@ namespace Richasy.Bili.App.Controls /// public event EventHandler RequestLoadMore; - /// - /// 当有新的条目添加并准备好与用户交互时发生. - /// 会返回新条目的索引值与其实际高度的乘积,用以估算列表总高度. - /// - public event EventHandler NewItemAdded; - /// /// 条目模板. /// @@ -127,6 +127,15 @@ namespace Richasy.Bili.App.Controls set { SetValue(AdditionalContentProperty, value); } } + /// + /// 是否允许根据容器剩余空间自行计算视频条目容量,并主动发起请求填满整个容器. + /// + public bool IsAutoFillEnable + { + get { return (bool)GetValue(IsAutoFillEnableProperty); } + set { SetValue(IsAutoFillEnableProperty, value); } + } + private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var instance = d as VideoView; @@ -208,7 +217,28 @@ namespace Richasy.Bili.App.Controls if (args.Element != null && args.Element is VideoItem item) { item.Orientation = ItemOrientation; - NewItemAdded?.Invoke(this, args); + if (IsAutoFillEnable && + ItemsSource is ObservableCollection collectionSource && + _parentScrollViewer != null && + args.Index >= collectionSource.Count - 1) + { + var size = item.GetHolderSize(); + var isNeedLoadMore = false; + if (double.IsInfinity(size.Width)) + { + isNeedLoadMore = (args.Index + 1) * size.Height <= _parentScrollViewer.ViewportHeight; + } + else + { + var rowCount = args.Index / (_parentScrollViewer.ViewportWidth / size.Width); + isNeedLoadMore = rowCount * size.Height <= _parentScrollViewer.ViewportHeight; + } + + if (isNeedLoadMore) + { + RequestLoadMore?.Invoke(this, EventArgs.Empty); + } + } } } } diff --git a/src/App/Pages/Overlay/PartitionDetailPage.xaml b/src/App/Pages/Overlay/PartitionDetailPage.xaml index e83415db07645d6179e02f5e4c94a0a6beb16659..3e621f5b83fa7d7a9ed41c6f88ac2f3529cfd65b 100644 --- a/src/App/Pages/Overlay/PartitionDetailPage.xaml +++ b/src/App/Pages/Overlay/PartitionDetailPage.xaml @@ -5,6 +5,7 @@ xmlns:controls="using:Richasy.Bili.App.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:enums="using:Richasy.Bili.Models.Enums" + xmlns:icons="using:Fluent.Icons" xmlns:loc="using:Richasy.Bili.Locator.Uwp" xmlns:local="using:Richasy.Bili.App.Pages.Overlay" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -91,7 +92,8 @@ x:Name="BannerView" Margin="0,0,0,12" VerticalAlignment="Top" - ItemsSource="{x:Bind ViewModel.CurrentSelectedSubPartition.BannerCollection, Mode=OneWay}" /> + ItemsSource="{x:Bind ViewModel.CurrentSelectedSubPartition.BannerCollection, Mode=OneWay}" + Visibility="{x:Bind ViewModel.CurrentSelectedSubPartition.IsShowBanner, Mode=OneWay}" /> - - - - - - - + + + + + + + + + + diff --git a/src/App/Pages/Overlay/PartitionDetailPage.xaml.cs b/src/App/Pages/Overlay/PartitionDetailPage.xaml.cs index 970ca6ab7664f38470cc19c3c1786f8bc9395d4a..efeba51ede66897e44c4976d3932946201e98da7 100644 --- a/src/App/Pages/Overlay/PartitionDetailPage.xaml.cs +++ b/src/App/Pages/Overlay/PartitionDetailPage.xaml.cs @@ -1,7 +1,6 @@ // Copyright (c) Richasy. All rights reserved. using System.ComponentModel; -using Richasy.Bili.App.Controls; using Richasy.Bili.Models.Enums; using Richasy.Bili.ViewModels.Uwp; using Windows.UI.Xaml; @@ -68,13 +67,11 @@ namespace Richasy.Bili.App.Pages.Overlay private void OnUnloaded(object sender, RoutedEventArgs e) { ViewModel.PropertyChanged -= OnViewModelPropertyChanged; - VideoView.NewItemAdded -= OnVideoViewNewItemAddedAsync; } private void OnLoaded(object sender, RoutedEventArgs e) { ViewModel.PropertyChanged += OnViewModelPropertyChanged; - VideoView.NewItemAdded += OnVideoViewNewItemAddedAsync; CheckCurrentSubPartition(); } @@ -97,15 +94,16 @@ namespace Richasy.Bili.App.Pages.Overlay var vm = ViewModel.CurrentSelectedSubPartition; if (vm != null) { - BannerView.Visibility = vm.BannerCollection != null && vm.BannerCollection.Count > 0 ? Visibility.Visible : Visibility.Collapsed; var isShowSort = vm.SortTypeCollection != null && vm.SortTypeCollection.Count > 0; if (isShowSort) { VideoSortComboBox.Visibility = Visibility.Visible; + RefreshButton.Visibility = Visibility.Collapsed; VideoSortComboBox.SelectedItem = vm.CurrentSortType; } else { + RefreshButton.Visibility = Visibility.Visible; VideoSortComboBox.Visibility = Visibility.Collapsed; } @@ -118,41 +116,12 @@ namespace Richasy.Bili.App.Pages.Overlay private async void OnVideoViewRequestLoadMoreAsync(object sender, System.EventArgs e) { - var currentSubPartition = ViewModel.CurrentSelectedSubPartition; - if (currentSubPartition != null && !currentSubPartition.IsDeltaLoading && !currentSubPartition.IsInitializeLoading) - { - await currentSubPartition.RequestDataAsync(); - } - } - - private async void OnVideoViewNewItemAddedAsync(object sender, Microsoft.UI.Xaml.Controls.ItemsRepeaterElementPreparedEventArgs e) - { - // 当视频条目列表加载完成之后计算这些视频条目是否足以填满整个显示区域, - // 如果不足,则再次请求,直到填满显示区域. - // 此法是滚动加载设计的前置条件,即先让显示区域能够滚动. var currentSubPartition = ViewModel.CurrentSelectedSubPartition; if (currentSubPartition != null && !currentSubPartition.IsDeltaLoading && - !currentSubPartition.IsInitializeLoading && - e.Index >= currentSubPartition.VideoCollection.Count - 1) + !currentSubPartition.IsInitializeLoading) { - var videoItem = e.Element as VideoItem; - var size = videoItem.GetHolderSize(); - var isNeedLoadMore = false; - if (double.IsInfinity(size.Width)) - { - isNeedLoadMore = (e.Index + 1) * size.Height <= ContentScrollView.ViewportHeight; - } - else - { - var rowCount = e.Index / (ContentScrollView.ViewportWidth / size.Width); - isNeedLoadMore = rowCount * size.Height <= ContentScrollView.ViewportHeight; - } - - if (isNeedLoadMore) - { - await ViewModel.CurrentSelectedSubPartition.RequestDataAsync(); - } + await currentSubPartition.RequestDataAsync(); } } @@ -164,5 +133,15 @@ namespace Richasy.Bili.App.Pages.Overlay ViewModel.CurrentSelectedSubPartition.CurrentSortType = item; } } + + private async void OnRefreshButtonClickAsync(object sender, RoutedEventArgs e) + { + if (ViewModel.CurrentSelectedSubPartition != null && + !ViewModel.CurrentSelectedSubPartition.IsInitializeLoading && + !ViewModel.CurrentSelectedSubPartition.IsDeltaLoading) + { + await ViewModel.CurrentSelectedSubPartition.InitializeRequestAsync(); + } + } } } diff --git a/src/App/Themes/Generic.xaml b/src/App/Themes/Generic.xaml index f109dee20d77fd2a39b7f6fa030bc45a9f867cb6..d430d78eb357f7415b49778c26e0e9623c4c3bff 100644 --- a/src/App/Themes/Generic.xaml +++ b/src/App/Themes/Generic.xaml @@ -2,7 +2,10 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Richasy.Bili.App.Controls" - xmlns:local="using:Richasy.Bili.App"> + xmlns:hn="using:HN.Controls" + xmlns:icons="using:Fluent.Icons" + xmlns:local="using:Richasy.Bili.App" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls">