diff --git a/DownKyi/CustomAction/IncrementalLoadingBehavior.cs b/DownKyi/CustomAction/IncrementalLoadingBehavior.cs index 2dfc80b..0f55c2b 100644 --- a/DownKyi/CustomAction/IncrementalLoadingBehavior.cs +++ b/DownKyi/CustomAction/IncrementalLoadingBehavior.cs @@ -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: Behavior isLoading = true; var items = await LoadPageFunc(currentPage); + if(items == null || items.Length == 0) return; foreach (var item in items) { AssociatedObject.Items.Add(item); diff --git a/DownKyi/ViewModels/ViewMyHistoryViewModel.cs b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs index ccf560b..b2145cf 100644 --- a/DownKyi/ViewModels/ViewMyHistoryViewModel.cs +++ b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs @@ -259,19 +259,30 @@ public class ViewMyHistoryViewModel : ViewModelBase int startIndex = (page - 1) * VideoNumberInPage; return Task.Run(() => { - 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(); }); };