feat: 完善观看历史无限滚动功能

This commit is contained in:
Nlick47
2025-03-21 19:45:27 +08:00
parent 093c0ee781
commit 9d3a7b66a6
2 changed files with 22 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Xaml.Interactivity;
using ImTools;
namespace DownKyi.CustomAction;
@@ -51,6 +52,7 @@ public class IncrementalLoadingBehavior<T>: Behavior<ListBox>
isLoading = true;
var items = await LoadPageFunc(currentPage);
if(items == null || items.Length == 0) return;
foreach (var item in items)
{
AssociatedObject.Items.Add(item);

View File

@@ -259,19 +259,30 @@ public class ViewMyHistoryViewModel : ViewModelBase
int startIndex = (page - 1) * VideoNumberInPage;
return Task.Run<HistoryMedia[]>(() =>
{
var result = History.GetHistory(_nextMax, _nextViewAt, VideoNumberInPage);
foreach (var item in result.List)
App.PropertyChangeAsync(() =>
{
var history = Convert(item, EventAggregator);
if (history != null)
LoadingVisibility = true;
});
var result = History.GetHistory(_nextMax, _nextViewAt, VideoNumberInPage);
if (result?.List?.Count > 0)
{
foreach (var item in result.List)
{
Medias.Add(history);
var history = Convert(item, EventAggregator);
if (history != null)
{
Medias.Add(history);
}
}
App.PropertyChangeAsync(() =>
{
LoadingVisibility = false;
});
_nextMax = result.Cursor.Max;
_nextViewAt = result.Cursor.ViewAt;
return Medias.Skip(startIndex).Take(VideoNumberInPage).ToArray();
}
_nextMax = result.Cursor.Max;
_nextViewAt = result.Cursor.ViewAt;
return Medias.Skip(startIndex).Take(VideoNumberInPage).ToArray();
return Array.Empty<HistoryMedia>();
});
};