Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
支持显示及播放合集内容 (#1060)
Browse files Browse the repository at this point in the history
* 支持合集的显示与播放

* 清理代码
  • Loading branch information
Richasy authored Apr 17, 2022
1 parent 7de2316 commit a1ab1e1
Show file tree
Hide file tree
Showing 21 changed files with 3,690 additions and 1,061 deletions.
8 changes: 8 additions & 0 deletions src/App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
<DependentUpon>LiveAreaView.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Player\PlayerTip\PlayerTip.cs" />
<Compile Include="Controls\Player\Related\UgcEpisodeView.xaml.cs">
<DependentUpon>UgcEpisodeView.xaml</DependentUpon>
</Compile>
<Compile Include="Controls\Player\Related\ViewLaterView.xaml.cs">
<DependentUpon>ViewLaterView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -435,6 +438,7 @@
<Compile Include="Resources\Converter\ObjectToVisibilityConverter.cs" />
<Compile Include="Resources\Converter\ThemeStringConverter.cs" />
<Compile Include="Resources\Converter\ToolboxItemIconConverter.cs" />
<Compile Include="Resources\Converter\UgcEpisodeConverter.cs" />
<Compile Include="Resources\Converter\UserLevelConverter.cs" />
<Compile Include="Resources\Extension\BasicExtension.cs" />
<Compile Include="Resources\Extension\ConnectedAnimationExtension.cs" />
Expand Down Expand Up @@ -590,6 +594,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\Player\Related\UgcEpisodeView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Controls\Player\Related\ViewLaterView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ public VerticalRepeaterView()
Unloaded += OnUnloaded;
}

/// <summary>
/// 滚动到条目.
/// </summary>
/// <param name="index">条目索引值.</param>
public void ScrollToItem(int index)
{
if (_itemsRepeater != null)
{
var element = _itemsRepeater.GetOrCreateElement(index);
var options = new BringIntoViewOptions
{
VerticalAlignmentRatio = 0f,
};
element.StartBringIntoView(options);
}
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,22 @@ private async void OnNextEpisodeButtonClickAsync(object sender, RoutedEventArgs
await ViewModel.ChangePgcEpisodeAsync(next.Data.Id);
}
}
else
else if (ViewModel.IsShowUgcSection)
{
var next = ViewModel.VideoPartCollection.Where(p => p.Data.Page.Page_ == ViewModel.CurrentVideoPart.Page.Page_ + 1).FirstOrDefault();
if (next != null)
var index = ViewModel.CurrentUgcSection.Episodes.IndexOf(ViewModel.CurrentUgcEpisode);
if (index > -1 && index < ViewModel.CurrentUgcSection.Episodes.Count - 1)
{
var next = ViewModel.CurrentUgcSection.Episodes[index + 1];
await ViewModel.LoadAsync(new VideoViewModel(next));
}
}
else if (ViewModel.IsShowParts)
{
var part = ViewModel.VideoPartCollection.FirstOrDefault(p => p.Data.Page.Page_ == ViewModel.CurrentVideoPart.Page.Page_ + 1);
if (part != null)
{
await ViewModel.ChangeVideoPartAsync(next.Data.Page.Cid);
var id = part.Data.Page.Cid;
await ViewModel.ChangeVideoPartAsync(id);
}
}
}
Expand All @@ -402,12 +412,22 @@ private async void OnPreviousEpisodeButtonClickAsync(object sender, RoutedEventA
await ViewModel.ChangePgcEpisodeAsync(prev.Data.Id);
}
}
else
else if (ViewModel.IsShowUgcSection)
{
var prev = ViewModel.VideoPartCollection.Where(p => p.Data.Page.Page_ == ViewModel.CurrentVideoPart.Page.Page_ - 1).FirstOrDefault();
if (prev != null)
var index = ViewModel.CurrentUgcSection.Episodes.IndexOf(ViewModel.CurrentUgcEpisode);
if (index > 0)
{
var prev = ViewModel.CurrentUgcSection.Episodes[index - 1];
await ViewModel.LoadAsync(new VideoViewModel(prev));
}
}
else if (ViewModel.IsShowParts)
{
var part = ViewModel.VideoPartCollection.FirstOrDefault(p => p.Data.Page.Page_ == ViewModel.CurrentVideoPart.Page.Page_ - 1);
if (part != null)
{
await ViewModel.ChangeVideoPartAsync(prev.Data.Page.Cid);
var id = part.Data.Page.Cid;
await ViewModel.ChangeVideoPartAsync(id);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/App/Controls/Player/PlayerRelatedView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
<VisualState.Setters>
<Setter Target="DetailGrid.Width" Value="Auto" />
<Setter Target="DetailGrid.MaxWidth" Value="999" />
<Setter Target="ViewLaterVideoView.VerticalScrollMode" Value="Disabled" />
<Setter Target="RelatedVideoView.VerticalScrollMode" Value="Disabled" />
<Setter Target="VideoPartView.VerticalScrollMode" Value="Disabled" />
<Setter Target="EpisodeView.VerticalScrollMode" Value="Disabled" />
<Setter Target="SeasonView.VerticalScrollMode" Value="Disabled" />
<Setter Target="SectionView.VerticalScrollMode" Value="Disabled" />
<Setter Target="UgcEpisodeView.VerticalScrollMode" Value="Disabled" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
Expand All @@ -59,6 +61,10 @@
x:Name="ViewLaterItem"
Content="{loc:LocaleLocator Name=ViewLater}"
Visibility="{x:Bind ViewModel.IsShowViewLater, Mode=OneWay}" />
<muxc:NavigationViewItem
x:Name="UgcEpisodeItem"
Content="{loc:LocaleLocator Name=UgcEpisode}"
Visibility="{x:Bind ViewModel.IsShowUgcSection, Mode=OneWay}" />
<muxc:NavigationViewItem
x:Name="PartsItem"
Content="{loc:LocaleLocator Name=Parts}"
Expand Down Expand Up @@ -94,6 +100,10 @@
x:Name="ViewLaterVideoView"
x:Load="{x:Bind ViewModel.IsShowViewLater, Mode=OneWay}"
Visibility="Collapsed" />
<related:UgcEpisodeView
x:Name="UgcEpisodeView"
x:Load="{x:Bind ViewModel.IsShowUgcSection, Mode=OneWay}"
Visibility="Collapsed" />
<related:RelatedVideoView
x:Name="RelatedVideoView"
x:Load="{x:Bind ViewModel.IsShowRelatedVideos, Mode=OneWay}"
Expand Down
10 changes: 10 additions & 0 deletions src/App/Controls/Player/PlayerRelatedView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ private void OnViewModelPropertyChanged(object sender, PropertyChangedEventArgs
{
Nav.SelectedItem = PartsItem;
}
else if (ViewModel.IsShowUgcSection)
{
Nav.SelectedItem = UgcEpisodeItem;
}
else if (ViewModel.IsShowEpisode)
{
Nav.SelectedItem = EpisodeItem;
Expand Down Expand Up @@ -125,6 +129,12 @@ private async void InitializeLayoutAsync()
Visibility.Visible : Visibility.Collapsed;
}

if (ViewModel.IsShowUgcSection && UgcEpisodeView != null)
{
UgcEpisodeView.Visibility = Nav.SelectedItem == UgcEpisodeItem ?
Visibility.Visible : Visibility.Collapsed;
}

if (ViewModel.IsShowParts && VideoPartView != null)
{
VideoPartView.Visibility = Nav.SelectedItem == PartsItem ?
Expand Down
68 changes: 68 additions & 0 deletions src/App/Controls/Player/Related/UgcEpisodeView.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<controls:PlayerComponent
x:Class="Richasy.Bili.App.Controls.Player.Related.UgcEpisodeView"
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:converter="using:Richasy.Bili.App.Resources.Converter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:loc="using:Richasy.Bili.Locator.Uwp"
xmlns:local="using:Richasy.Bili.App.Controls.Player.Related"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:uwp="using:Richasy.Bili.ViewModels.Uwp"
xmlns:v1="using:Bilibili.App.View.V1"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">

<controls:PlayerComponent.Resources>
<converter:UgcEpisodeConverter x:Key="EpisodeConverter" />
</controls:PlayerComponent.Resources>

<Grid RowSpacing="8">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid ColumnSpacing="8">
<ComboBox
x:Name="SectionComboBox"
HorizontalAlignment="Stretch"
ItemsSource="{x:Bind ViewModel.UgcSectionCollection}"
SelectedItem="{x:Bind ViewModel.CurrentUgcSection, Mode=OneWay}"
SelectionChanged="OnSectionComboBoxSelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="v1:Section">
<TextBlock Text="{x:Bind Title}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<ScrollViewer
Grid.Row="1"
HorizontalScrollMode="Disabled"
VerticalScrollBarVisibility="Hidden"
VerticalScrollMode="{x:Bind VerticalScrollMode, Mode=OneWay}">
<Grid>
<controls:VerticalRepeaterView
EnableDetectParentScrollViewer="False"
HeaderVisibility="Collapsed"
ItemOrientation="Horizontal"
ItemsSource="{x:Bind ViewModel.UgcEpisodeCollection}"
Loaded="OnLoadedAsync">
<controls:VerticalRepeaterView.ItemTemplate>
<DataTemplate x:DataType="uwp:VideoViewModel">
<controls:VideoCard
MaxHeight="120"
HorizontalCoverWidth="120"
IsShowAvatar="False"
IsShowDanmakuCount="True"
IsShowPlayCount="True"
ViewModel="{x:Bind}" />
</DataTemplate>
</controls:VerticalRepeaterView.ItemTemplate>
</controls:VerticalRepeaterView>
</Grid>
</ScrollViewer>
</Grid>
</controls:PlayerComponent>
41 changes: 41 additions & 0 deletions src/App/Controls/Player/Related/UgcEpisodeView.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Richasy. All rights reserved.

using Bilibili.App.View.V1;

namespace Richasy.Bili.App.Controls.Player.Related
{
/// <summary>
/// 合集视图.
/// </summary>
public sealed partial class UgcEpisodeView : PlayerComponent
{
/// <summary>
/// Initializes a new instance of the <see cref="UgcEpisodeView"/> class.
/// </summary>
public UgcEpisodeView()
{
this.InitializeComponent();
}

private void OnSectionComboBoxSelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)
{
if (SectionComboBox.SelectedItem is Section item && item != ViewModel.CurrentUgcSection)
{
ViewModel.ChangeUgcSection(item);
}
}

private async void OnLoadedAsync(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
await System.Threading.Tasks.Task.Delay(200);
if (ViewModel.IsShowUgcSection)
{
var index = ViewModel.CurrentUgcSection.Episodes.IndexOf(ViewModel.CurrentUgcEpisode);
if (index > 0)
{
(sender as VerticalRepeaterView).ScrollToItem(index);
}
}
}
}
}
24 changes: 24 additions & 0 deletions src/App/Resources/Converter/UgcEpisodeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Richasy. All rights reserved.

using System;
using Bilibili.App.View.V1;
using Richasy.Bili.ViewModels.Uwp;
using Windows.UI.Xaml.Data;

namespace Richasy.Bili.App.Resources.Converter
{
internal sealed class UgcEpisodeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is Episode ugcEpisode)
{
return new VideoViewModel(ugcEpisode);
}

return null;
}

public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
}
}
3 changes: 3 additions & 0 deletions src/App/Resources/Strings/zh-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,9 @@ BV号以 BV 开头,是一串英文数字混合的编号, 如 BV1JL4y1875w</v
<data name="TVApp" xml:space="preserve">
<value>电视</value>
</data>
<data name="UgcEpisode" xml:space="preserve">
<value>视频合集</value>
</data>
<data name="UnFavorite" xml:space="preserve">
<value>取消收藏</value>
</data>
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Models.App/Constants/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public static class Video
/// <summary>
/// 视频详情.
/// </summary>
public const string Detail = _appBase + "/bilibili.app.view.v1.View/View";
public const string Detail = _grpcBase + "/bilibili.app.view.v1.View/View";

/// <summary>
/// 在线观看人数.
Expand Down
1 change: 1 addition & 0 deletions src/Models/Models.Enums/App/LanguageNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public enum LanguageNames
DanmakuMerge,
UseCloudShieldSettings,
Episodes,
UgcEpisode,
Seasons,
Sections,
Detail,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

�
preload.proto"bilibili.app.archive.middleware.v1"g

PlayerArgs
qn (Rqn
fnver (Rfnver
fnval (Rfnval

force_host (R forceHostbproto3
Expand Down
Loading

0 comments on commit a1ab1e1

Please sign in to comment.