Skip to content

Commit 5518580

Browse files
authored
支持PGC内容索引 (Richasy#29)
* 添加索引页面,增加条件 * 添加PGC索引页面
1 parent f4b2eca commit 5518580

35 files changed

Lines changed: 1030 additions & 39 deletions

src/App/App.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<DefaultLanguage>zh-CN</DefaultLanguage>
1515
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
1616
<Use64BitCompiler>true</Use64BitCompiler>
17+
<ShortcutGenericAnalysis>true</ShortcutGenericAnalysis>
1718
</PropertyGroup>
1819
<ItemGroup>
1920
<Compile Include="$(SolutionDir)\src\Shared\SharedAssemblyInfo.cs">
@@ -205,6 +206,9 @@
205206
<Compile Include="Pages\Overlay\SearchPage.xaml.cs">
206207
<DependentUpon>SearchPage.xaml</DependentUpon>
207208
</Compile>
209+
<Compile Include="Pages\Overlay\PgcIndexPage.xaml.cs">
210+
<DependentUpon>PgcIndexPage.xaml</DependentUpon>
211+
</Compile>
208212
<Compile Include="Pages\Reuse\AnimePage.xaml.cs">
209213
<DependentUpon>AnimePage.xaml</DependentUpon>
210214
</Compile>
@@ -637,6 +641,10 @@
637641
<SubType>Designer</SubType>
638642
<Generator>MSBuild:Compile</Generator>
639643
</Page>
644+
<Page Include="Pages\Overlay\PgcIndexPage.xaml">
645+
<SubType>Designer</SubType>
646+
<Generator>MSBuild:Compile</Generator>
647+
</Page>
640648
<Page Include="Pages\Reuse\AnimePage.xaml">
641649
<SubType>Designer</SubType>
642650
<Generator>MSBuild:Compile</Generator>

src/App/Controls/App/RootNavigationView.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ private void CheckOverlayContentNavigation(object param)
208208
case PageIds.Follows:
209209
pageType = typeof(FollowsPage);
210210
break;
211+
case PageIds.PgcIndex:
212+
pageType = typeof(PgcIndexPage);
213+
break;
211214
default:
212215
break;
213216
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<Page
2+
x:Class="Richasy.Bili.App.Pages.PgcIndexPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:controls="using:Richasy.Bili.App.Controls"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:loc="using:Richasy.Bili.Locator.Uwp"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
10+
xmlns:uwp="using:Richasy.Bili.ViewModels.Uwp"
11+
mc:Ignorable="d">
12+
13+
<Page.Resources>
14+
<DataTemplate x:Key="WideSeasonItemTemplate" x:DataType="uwp:SeasonViewModel">
15+
<controls:PgcItem ViewModel="{x:Bind}" />
16+
</DataTemplate>
17+
<DataTemplate x:Key="NarrowSeasonItemTemplate" x:DataType="uwp:SeasonViewModel">
18+
<controls:PgcItem
19+
CoverHeight="140"
20+
CoverWidth="100"
21+
TitleRowHeight="28"
22+
ViewModel="{x:Bind}">
23+
<controls:PgcItem.CardStyle>
24+
<Style TargetType="controls:CardPanel">
25+
<Setter Property="IsEnableHoverAnimation" Value="False" />
26+
<Setter Property="IsEnableShadow" Value="False" />
27+
</Style>
28+
</controls:PgcItem.CardStyle>
29+
</controls:PgcItem>
30+
</DataTemplate>
31+
</Page.Resources>
32+
33+
<Grid>
34+
<Grid.RowDefinitions>
35+
<RowDefinition Height="Auto" />
36+
<RowDefinition Height="Auto" />
37+
<RowDefinition Height="*" />
38+
</Grid.RowDefinitions>
39+
<VisualStateManager.VisualStateGroups>
40+
<VisualStateGroup x:Name="Common">
41+
<VisualState x:Name="WideState">
42+
<VisualState.StateTriggers>
43+
<AdaptiveTrigger MinWindowWidth="{StaticResource MediumWindowThresholdWidth}" />
44+
</VisualState.StateTriggers>
45+
</VisualState>
46+
<VisualState x:Name="NarrowState">
47+
<VisualState.StateTriggers>
48+
<AdaptiveTrigger MinWindowWidth="0" />
49+
</VisualState.StateTriggers>
50+
<VisualState.Setters>
51+
<Setter Target="ContentScrollViewer.Padding" Value="{StaticResource NarrowContainerPadding}" />
52+
<Setter Target="FilterContainer.Padding" Value="{StaticResource NarrowContainerPadding}" />
53+
<Setter Target="IndexView.ItemOrientation" Value="Horizontal" />
54+
<Setter Target="IndexView.ItemTemplate" Value="{StaticResource NarrowSeasonItemTemplate}" />
55+
</VisualState.Setters>
56+
</VisualState>
57+
</VisualStateGroup>
58+
</VisualStateManager.VisualStateGroups>
59+
<TextBlock
60+
Style="{StaticResource TitleTextBlockStyle}"
61+
Margin="0,0,0,12"
62+
HorizontalAlignment="Left"
63+
TextTrimming="CharacterEllipsis">
64+
<Run
65+
FontWeight="Bold"
66+
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
67+
Text="{x:Bind ViewModel.PgcName, Mode=OneWay}" />
68+
<Run Text="{loc:LocaleLocator Name=Index}" />
69+
</TextBlock>
70+
71+
<Grid
72+
x:Name="FilterContainer"
73+
Grid.Row="1"
74+
Padding="{StaticResource DefaultContainerPadding}">
75+
<muxc:ItemsRepeater ItemsSource="{x:Bind ViewModel.FilterCollection, Mode=OneWay}">
76+
<muxc:ItemsRepeater.Layout>
77+
<muxc:UniformGridLayout
78+
ItemsStretch="Fill"
79+
MinColumnSpacing="12"
80+
MinItemWidth="120"
81+
MinRowSpacing="12" />
82+
</muxc:ItemsRepeater.Layout>
83+
<muxc:ItemsRepeater.ItemTemplate>
84+
<DataTemplate x:DataType="uwp:PgcConditionViewModel">
85+
<ComboBox
86+
HorizontalAlignment="Stretch"
87+
Header="{x:Bind Name, Mode=OneWay}"
88+
ItemsSource="{x:Bind ConditionCollection, Mode=OneWay}"
89+
SelectedItem="{x:Bind SelectedItem, Mode=TwoWay}"
90+
SelectionChanged="OnConditionChangedAsync">
91+
<ComboBox.ItemTemplate>
92+
<DataTemplate x:DataType="uwp:PgcConditionItemViewModel">
93+
<TextBlock Text="{x:Bind Name, Mode=OneWay}" />
94+
</DataTemplate>
95+
</ComboBox.ItemTemplate>
96+
<ComboBox.HeaderTemplate>
97+
<DataTemplate>
98+
<TextBlock
99+
FontSize="12"
100+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
101+
Text="{Binding}" />
102+
</DataTemplate>
103+
</ComboBox.HeaderTemplate>
104+
</ComboBox>
105+
</DataTemplate>
106+
</muxc:ItemsRepeater.ItemTemplate>
107+
</muxc:ItemsRepeater>
108+
</Grid>
109+
110+
<Grid Grid.Row="2" Margin="0,12,0,0">
111+
<ScrollViewer
112+
x:Name="ContentScrollViewer"
113+
Padding="{StaticResource DefaultContainerPadding}"
114+
HorizontalScrollMode="Disabled"
115+
VerticalScrollBarVisibility="Auto"
116+
Visibility="{x:Bind ViewModel.IsIndexInitializeLoading, Converter={StaticResource BoolToVisibilityReverseConverter}}">
117+
<controls:VerticalRepeaterView
118+
x:Name="IndexView"
119+
Margin="0,0,0,12"
120+
HeaderVisibility="Collapsed"
121+
ItemTemplate="{StaticResource WideSeasonItemTemplate}"
122+
ItemsSource="{x:Bind ViewModel.ItemCollection, Mode=OneWay}"
123+
MinWideItemHeight="180"
124+
MinWideItemWidth="300"
125+
RequestLoadMore="OnViewRequestLoadMoreAsync" />
126+
</ScrollViewer>
127+
128+
<controls:OverlayLoadingPanel IsBarActive="{x:Bind ViewModel.IsIndexDeltaLoading, Mode=OneWay}" IsRingActive="{x:Bind ViewModel.IsIndexInitializeLoading, Mode=OneWay}" />
129+
<controls:ErrorPanel
130+
ActionButtonClick="OnIndexRefreshButtonClickAsync"
131+
ActionContent="{loc:LocaleLocator Name=Refresh}"
132+
Text="{x:Bind ViewModel.IndexErrorText, Mode=OneWay}"
133+
Visibility="{x:Bind ViewModel.IsIndexError, Mode=OneWay}" />
134+
</Grid>
135+
</Grid>
136+
</Page>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) Richasy. All rights reserved.
2+
3+
using System;
4+
using Richasy.Bili.ViewModels.Uwp;
5+
using Windows.UI.Xaml;
6+
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Navigation;
8+
9+
namespace Richasy.Bili.App.Pages
10+
{
11+
/// <summary>
12+
/// PGC索引页面.
13+
/// </summary>
14+
public sealed partial class PgcIndexPage : Page
15+
{
16+
/// <summary>
17+
/// <see cref="ViewModel"/>的依赖属性.
18+
/// </summary>
19+
public static readonly DependencyProperty ViewModelProperty =
20+
DependencyProperty.Register(nameof(ViewModel), typeof(PgcViewModelBase), typeof(PgcIndexPage), new PropertyMetadata(null));
21+
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="PgcIndexPage"/> class.
24+
/// </summary>
25+
public PgcIndexPage()
26+
{
27+
this.InitializeComponent();
28+
this.Loaded += OnLoadedAsync;
29+
}
30+
31+
/// <summary>
32+
/// 视图模型.
33+
/// </summary>
34+
public PgcViewModelBase ViewModel
35+
{
36+
get { return (PgcViewModelBase)GetValue(ViewModelProperty); }
37+
set { SetValue(ViewModelProperty, value); }
38+
}
39+
40+
/// <inheritdoc/>
41+
protected override void OnNavigatedTo(NavigationEventArgs e)
42+
{
43+
if (e.Parameter is PgcViewModelBase vm)
44+
{
45+
ViewModel = vm;
46+
}
47+
}
48+
49+
private async void OnLoadedAsync(object sender, RoutedEventArgs e)
50+
{
51+
if (ViewModel.FilterCollection.Count == 0)
52+
{
53+
await ViewModel.LoadIndexAsync();
54+
}
55+
}
56+
57+
private async void OnViewRequestLoadMoreAsync(object sender, EventArgs e)
58+
{
59+
await ViewModel.DeltaRequestIndexAsync();
60+
}
61+
62+
private async void OnIndexRefreshButtonClickAsync(object sender, RoutedEventArgs e)
63+
{
64+
await ViewModel.LoadIndexAsync();
65+
}
66+
67+
private async void OnConditionChangedAsync(object sender, SelectionChangedEventArgs e)
68+
{
69+
if (ViewModel.IsIndexRequested)
70+
{
71+
await ViewModel.LoadIndexAsync();
72+
}
73+
}
74+
}
75+
}

src/App/Pages/Reuse/AnimePage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
Padding="{StaticResource DefaultContainerPadding}"
6161
Orientation="Horizontal"
6262
Spacing="8">
63-
<Button x:Name="IndexButton">
63+
<Button x:Name="IndexButton" Click="OnIndexButtonClick">
6464
<controls:IconTextBlock Symbol="TextBulletListLtr16" Text="{loc:LocaleLocator Name=Index}" />
6565
</Button>
6666
<Button x:Name="TimeChartButton">

src/App/Pages/Reuse/AnimePage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,10 @@ private void OnRootNavViewItemInvoked(Microsoft.UI.Xaml.Controls.NavigationView
105105
private void OnShowMoreButtonClickAsync(object sender, RoutedEventArgs e)
106106
{
107107
}
108+
109+
private void OnIndexButtonClick(object sender, RoutedEventArgs e)
110+
{
111+
AppViewModel.Instance.SetOverlayContentId(PageIds.PgcIndex, ViewModel);
112+
}
108113
}
109114
}

src/App/Pages/Reuse/FeedPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
MinWideItemWidth="300"
8585
RequestLoadMore="OnFeedViewRequestLoadMoreAsync">
8686
<controls:VerticalRepeaterView.AdditionalContent>
87-
<Button x:Name="IndexButton">
87+
<Button x:Name="IndexButton" Click="OnIndexButtonClick">
8888
<controls:IconTextBlock Symbol="TextBulletListLtr16" Text="{loc:LocaleLocator Name=Index}" />
8989
</Button>
9090
</controls:VerticalRepeaterView.AdditionalContent>

src/App/Pages/Reuse/FeedPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,10 @@ private async void OnFeedViewRequestLoadMoreAsync(object sender, System.EventArg
8282
await ViewModel.DeltaRequestAsync();
8383
}
8484
}
85+
86+
private void OnIndexButtonClick(object sender, RoutedEventArgs e)
87+
{
88+
AppViewModel.Instance.SetOverlayContentId(PageIds.PgcIndex, ViewModel);
89+
}
8590
}
8691
}

src/App/Resources/Strings/zh-CN/Resources.resw

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,12 @@
540540
<data name="PreviousView" xml:space="preserve">
541541
<value>上次观看:</value>
542542
</data>
543+
<data name="PublishFinished" xml:space="preserve">
544+
<value>已完结</value>
545+
</data>
546+
<data name="PublishInInstalments" xml:space="preserve">
547+
<value>连载中</value>
548+
</data>
543549
<data name="QRCodeExpired" xml:space="preserve">
544550
<value>二维码已过期,请刷新</value>
545551
</data>
@@ -588,6 +594,12 @@
588594
<data name="RequestHistoryFailed" xml:space="preserve">
589595
<value>请求观看历史失败</value>
590596
</data>
597+
<data name="RequestIndexFilterFailed" xml:space="preserve">
598+
<value>获取索引过滤条件失败</value>
599+
</data>
600+
<data name="RequestIndexResultFailed" xml:space="preserve">
601+
<value>请求索引结果失败</value>
602+
</data>
591603
<data name="RequestLiveFailed" xml:space="preserve">
592604
<value>直播数据请求失败</value>
593605
</data>

src/Controller/Controller.Uwp/BiliController.Pgc.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,42 @@ public async Task<bool> FollowPgcSeasonAsync(int seasonId, bool isFollow)
190190
return false;
191191
}
192192
}
193+
194+
/// <summary>
195+
/// 获取PGC索引条件.
196+
/// </summary>
197+
/// <param name="type">PGC类型.</param>
198+
/// <returns>索引结果.</returns>
199+
public async Task<PgcIndexConditionResponse> GetPgcIndexConditionsAsync(PgcType type)
200+
{
201+
ThrowWhenNetworkUnavaliable();
202+
return await _pgcProvider.GetPgcIndexConditionsAsync(type);
203+
}
204+
205+
/// <summary>
206+
/// 请求PGC索引内容.
207+
/// </summary>
208+
/// <param name="type">类型.</param>
209+
/// <param name="pageNumber">页码.</param>
210+
/// <param name="conditions">条件集合.</param>
211+
/// <returns><see cref="Task"/>.</returns>
212+
public async Task RequestPgcIndexResultAsync(PgcType type, int pageNumber, Dictionary<string, string> conditions)
213+
{
214+
ThrowWhenNetworkUnavaliable();
215+
216+
try
217+
{
218+
var data = await _pgcProvider.GetPgcIndexResultAsync(type, pageNumber, conditions);
219+
var args = new PgcIndexResultIterationEventArgs(data, type);
220+
PgcIndexResultIteration?.Invoke(this, args);
221+
}
222+
catch (Exception)
223+
{
224+
if (pageNumber > 1)
225+
{
226+
throw;
227+
}
228+
}
229+
}
193230
}
194231
}

0 commit comments

Comments
 (0)