Skip to content

Commit

Permalink
修复影视索引排序问题 (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Jan 6, 2024
1 parent ef3ce93 commit 093915c
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/App/Controls/Modules/FilmNavListModule.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
<base:LoadingOverlapper IsOpen="{x:Bind _tvRecommendDetailViewModel.IsReloading, Mode=OneWay}" Text="{ext:Locale Name=LoadingAndWait}" />
</Grid>

<!-- 电视剧索引 -->
<!-- 纪录片索引 -->
<Grid Grid.Row="1" Visibility="{x:Bind ViewModel.IsDocumentaryShown, Mode=OneWay}">
<ScrollViewer Padding="12,0" Style="{StaticResource PageScrollViewerStyle}">
<ItemsRepeater Margin="0,0,0,12" ItemsSource="{x:Bind _documentaryRecommendDetailViewModel.Filters}">
Expand Down
12 changes: 7 additions & 5 deletions src/App/Controls/Modules/LivePartitionDetailModule.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ public LivePartitionDetailModule()
}

private void OnUnloaded(object sender, RoutedEventArgs e)
=> ViewModel.RequestScrollToTop -= OnRequestScrollToTop;
=> ViewModel.RequestScrollToTop -= OnRequestScrollToTopAsync;

private void OnLoaded(object sender, RoutedEventArgs e)
=> ViewModel.RequestScrollToTop += OnRequestScrollToTop;
=> ViewModel.RequestScrollToTop += OnRequestScrollToTopAsync;

private void OnRequestScrollToTop(object sender, EventArgs e)
=> ContentScrollViewer.ChangeView(default, 0, default, true);
private async void OnRequestScrollToTopAsync(object sender, EventArgs e)
{
await Task.Delay(200);
ContentScrollViewer.ChangeView(default, 0, default);
}

private void OnDetailNavigationViewItemInvoked(NavigationView sender, NavigationViewItemInvokedEventArgs args)
{
var data = args.InvokedItem as LiveTag;
_ = ContentScrollViewer.ChangeView(default, 0, default, true);
ViewModel.SelectTagCommand.Execute(data);
}

Expand Down
19 changes: 19 additions & 0 deletions src/App/Controls/Modules/PgcRecommendModule.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public PgcRecommendModule()
{
InitializeComponent();
Loaded += OnLoaded;
Unloaded += OnUnloaded;
}

/// <summary>
Expand All @@ -46,6 +47,24 @@ private void OnLoaded(object sender, RoutedEventArgs e)
PgcType.Documentary => DocumentaryRecommendDetailViewModel.Instance,
_ => throw new ArgumentOutOfRangeException(nameof(PgcType))
};

ViewModel.RequestScrollToTop += OnRequestScrollToTopAsync;
}

private void OnUnloaded(object sender, RoutedEventArgs e)
{
if (ViewModel == null)
{
return;
}

ViewModel.RequestScrollToTop -= OnRequestScrollToTopAsync;
}

private async void OnRequestScrollToTopAsync(object sender, EventArgs e)
{
await Task.Delay(200);
ContentScrollViewer.ChangeView(0, 0, default);
}

private void OnSeasonViewIncrementalTriggered(object sender, EventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected override async Task GetDataAsync()

_totalCount = data.TotalCount;

var canScrollToTop = Items.Count == 0;

if (data.Lives?.Count() > 0)
{
foreach (var live in data.Lives)
Expand All @@ -83,6 +85,10 @@ protected override async Task GetDataAsync()
}

IsEmpty = Items.Count == 0;
if (canScrollToTop && !IsEmpty)
{
RequestScrollToTop?.Invoke(this, EventArgs.Empty);
}
}

[RelayCommand]
Expand Down Expand Up @@ -113,14 +119,12 @@ private async Task SelectTagAsync(LiveTag tag)
var liveVM = new LiveItemViewModel(live);
Items.Add(liveVM);
}

RequestScrollToTop?.Invoke(this, EventArgs.Empty);
}
else
{
_ = ReloadCommand.ExecuteAsync(null);
}
}

[RelayCommand]
private void ScrollToTop()
=> RequestScrollToTop?.Invoke(this, EventArgs.Empty);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Bili Copilot. All rights reserved.

using System;
using System.Collections.ObjectModel;
using Bili.Copilot.Models.Constants.Bili;
using Bili.Copilot.ViewModels.Items;
Expand All @@ -21,6 +22,11 @@ public partial class PgcRecommendDetailViewModel
[ObservableProperty]
private string _title;

/// <summary>
/// 请求滚动到顶部.
/// </summary>
public event EventHandler RequestScrollToTop;

/// <summary>
/// 筛选条件.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,8 @@ protected override void BeforeReload()
{
_isEnd = false;
IsEmpty = false;
if (_type is PgcType.Bangumi or PgcType.Domestic)
{
PgcProvider.Instance.ResetIndexStatus(_type);
}
else
{
PgcProvider.Instance.ResetPageStatus(_type);
}
PgcProvider.Instance.ResetIndexStatus(_type);
PgcProvider.Instance.ResetPageStatus(_type);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -81,34 +75,30 @@ protected override async Task GetDataAsync()
}

var seasons = new List<SeasonInformation>();
if (_type is PgcType.Bangumi or PgcType.Domestic)
{
var (isFinished, items) = await PgcProvider.Instance.GetPgcIndexResultAsync(_type, GetAnimeParameters());
seasons = items?.ToList();
_isEnd = isFinished;
}
else
{
var view = await PgcProvider.Instance.GetPageDetailAsync(_type);
if (view.Seasons?.Any() ?? false)
{
seasons = view.Seasons.ToList();
}
}
var (isFinished, items) = await PgcProvider.Instance.GetPgcIndexResultAsync(_type, GetIndexParameters());
seasons = items?.ToList();
_isEnd = isFinished;

var canScrollToTop = Items.Count == 0;

seasons.ForEach(p =>
{
Items.Add(new SeasonItemViewModel(p));
});

IsEmpty = Items.Count == 0;

if (canScrollToTop && !IsEmpty)
{
RequestScrollToTop?.Invoke(this, EventArgs.Empty);
}
}

/// <inheritdoc/>
protected override string FormatException(string errorMsg)
=> $"{ResourceToolkit.GetLocalizedString(StringNames.RequestFeedDetailFailed)}\n{errorMsg}";

private Dictionary<string, string> GetAnimeParameters()
private Dictionary<string, string> GetIndexParameters()
{
var queryPrameters = new Dictionary<string, string>();
foreach (var item in Filters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ public sealed partial class VideoPartitionDetailViewModel
/// </summary>
public ObservableCollection<Partition> SubPartitions { get; }

/// <summary>
/// 推荐分区集合.
/// </summary>
public ObservableCollection<Partition> RecommendPartitions { get; }

/// <summary>
/// 排序方式集合.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ private VideoPartitionDetailViewModel()

Banners = new ObservableCollection<BannerViewModel>();
SubPartitions = new ObservableCollection<Partition>();
RecommendPartitions = new ObservableCollection<Partition>();
SortTypes = new ObservableCollection<VideoSortType>()
{
VideoSortType.Default,
Expand Down Expand Up @@ -57,31 +56,22 @@ protected override async Task GetDataAsync()
var partition = IsSubPartitionShown ? CurrentSubPartition : CurrentRecommendPartition;

IEnumerable<VideoInformation> videos = default;
if (partition.Id == "-1")
var isRecommend = partition.Id == OriginPartition.Id;
var data = await HomeProvider.Instance.GetVideoSubPartitionDataAsync(partition.Id, isRecommend, SortType);
if (data.Banners?.Count() > 0)
{
// 排行榜数据.
TryClear(Items);
videos = await HomeProvider.GetRankDetailAsync(partition.ParentId);
}
else
{
var isRecommend = partition.Id == OriginPartition.Id;
var data = await HomeProvider.Instance.GetVideoSubPartitionDataAsync(partition.Id, isRecommend, SortType);
if (data.Banners?.Count() > 0)
foreach (var item in data.Banners)
{
foreach (var item in data.Banners)
if (!Banners.Any(p => p.Uri == item.Uri))
{
if (!Banners.Any(p => p.Uri == item.Uri))
{
var vm = new BannerViewModel(item);
Banners.Add(vm);
}
var vm = new BannerViewModel(item);
Banners.Add(vm);
}
}

videos = data.Videos;
}

videos = data.Videos;

CheckBannerState();
if (videos?.Count() > 0)
{
Expand Down Expand Up @@ -112,19 +102,15 @@ private void LoadPartition(Partition partition)
_caches.Clear();
HomeProvider.Instance.ClearPartitionState();
TryClear(SubPartitions);
TryClear(RecommendPartitions);
TryClear(Banners);

// 子分区中不包含推荐分区.
partition.Children.Where(p => p.Id != p.ParentId).ToList().ForEach(SubPartitions.Add);

// 合并推荐分区及排行榜分区.
var rcmdPartition = partition.Children.First(p => p.Id == p.ParentId);
var rankPartition = new Partition("-1", ResourceToolkit.GetLocalizedString(StringNames.PartitionRank), parentId: rcmdPartition.ParentId);
RecommendPartitions.Add(rcmdPartition);
RecommendPartitions.Add(rankPartition);

SelectSubPartition(IsSubPartitionShown ? SubPartitions[0] : RecommendPartitions[0]);
CurrentRecommendPartition = rcmdPartition;
SelectSubPartition(IsSubPartitionShown ? SubPartitions[0] : CurrentRecommendPartition);
}

[RelayCommand]
Expand Down Expand Up @@ -185,7 +171,7 @@ partial void OnDetailTypeChanged(VideoPartitionDetailType value)

if (IsRecommendShown)
{
SelectSubPartitionCommand.Execute(CurrentRecommendPartition ?? RecommendPartitions.First());
SelectSubPartitionCommand.Execute(CurrentRecommendPartition ?? OriginPartition.Children.First());
}
else if (IsSubPartitionShown)
{
Expand Down

0 comments on commit 093915c

Please sign in to comment.