private async Task <IEnumerable <ShowDto> > OnLoadMore() { _pageNr--; await LoadNextPageCommand.Execute(_pageNr).ToTask(); return(new List <ShowDto>()); }
private async void LoadData(int postId, int pageIndex, bool isNeeedClear = true) { BusyCount++; _isLoadingNow = true; IsResultEmpty = false; LoadNextPageCommand.RaiseCanExecuteChanged(); LoadPreviousPageCommand.RaiseCanExecuteChanged(); RefreshCommand.RaiseCanExecuteChanged(); var commentsResponse = await _commentsProvider.LoadCommentsAsync(postId, pageIndex, commentType); if (commentsResponse != null) { CurrentIndex = commentsResponse.PagerCurrent; if (commentsResponse.PageComments != null) { LastIndex = commentsResponse.TotalCount / 25; Comments = commentsResponse.PageComments; } } _isLoadingNow = false; IsResultEmpty = Comments.Count == 0; LoadNextPageCommand.RaiseCanExecuteChanged(); LoadPreviousPageCommand.RaiseCanExecuteChanged(); RefreshCommand.RaiseCanExecuteChanged(); BusyCount--; }
public MainViewModel() { _movieService = new MovieService(); LoadNextPageCommand = ReactiveCommand.CreateFromTask <int, List <ShowDto> >(async _ => { var items = await _movieService.LoadPage(_pageNr); await Task.Delay(1000); return(items); }); LoadNextPageCommand.IsExecuting.BindTo(this, vm => vm.IsBusy); LoadNextPageCommand.Subscribe(shows => { _showsList.AddRange(shows); }); LoadNextPageCommand.Execute(_pageNr).Subscribe(); LoadNextPageCommand.IsExecuting .ToProperty(this, vm => vm.IsLoadingItems, out _isLoadingItems); _showsList .Connect() .ObserveOn(RxApp.MainThreadScheduler) .Sort(SortExpressionComparer <ShowDto> .Ascending(a => a.Id)) .Bind(Shows) .Subscribe(); Shows.ShouldLoadMoreThreshold = 100; Shows.OnLoadMore += OnLoadMore; Shows.OnCanLoadMore += OnCanLoadMore; }