コード例 #1
0
        protected override async Task LoadPageData(bool isPaging = false)
        {
            Exception exception = null;

            try
            {
                IsRefreshing = true;

                if (isPaging)
                {
                    CurrentPage += 1;
                }

                var request = new MovieRequest()
                {
                    Page = CurrentPage, Query = SearchKey
                };

                var response = await MovieService.SearchMovies(request);

                if (response.TotalResults > 0)
                {
                    TotalCount = response.TotalResults;
                    foreach (var item in response.Data)
                    {
                        item.IsFavorite = AppData.Movies.Contains(item);
                    }
                    if (isPaging && CurrentPage > 1)
                    {
                        ItemsSource.AddRange(response.Data);
                    }
                    else
                    {
                        ItemsSource = new MvxObservableCollection <Movie>(response.Data);
                    }
                }
                else
                {
                    NoDataAvailable = true;
                }
            }
            catch (Exception exp)
            {
                exception = exp;
            }
            finally
            {
                if (IsRefreshing)
                {
                    IsRefreshing = false;
                }
            }
        }
コード例 #2
0
        protected override async Task LoadPageData(bool isPaging = false)
        {
            Exception exception = null;

            try
            {
                if (!IsRefreshing)
                {
                    IsLoading = true;
                }

                if (isPaging)
                {
                    CurrentPage += 1;
                }

                var request = new MovieRequest()
                {
                    Page = CurrentPage,
                };

                if (SelectedGenreId.HasValue)
                {
                    request.Genres = $"{SelectedGenreId.Value}";
                }

                var response = await MovieService.DiscoverMovies(request);

                if (response.TotalResults > 0)
                {
                    TotalCount = response.TotalResults;
                    foreach (var item in response.Data)
                    {
                        item.Genres     = AppData.Genres.Genre.Where(x => item.GenreIds.Contains(x.Id)).Select(x => x.Name).ToArray();
                        item.IsFavorite = AppData.Movies.Any(x => x.Id == item.Id);
                    }
                    if (isPaging && CurrentPage > 1)
                    {
                        ItemsSource.AddRange(response.Data);
                    }
                    else
                    {
                        ItemsSource = new MvxObservableCollection <Movie>(response.Data);
                    }
                }
                else
                {
                    NoDataAvailable = true;
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            finally
            {
                LogProvider.GetLogFor(typeof(DiscoverViewModel)).ErrorException("", exception);
                if (IsRefreshing)
                {
                    IsRefreshing = false;
                }
                if (IsLoading)
                {
                    IsLoading = false;
                }
            }
        }