public async Task ItemsTresholdReached() { if (IsBusy) { return; } IsBusy = true; try { CountPages++; var moviesList = await HubService.GetMoviesAsync(CountPages); var previousLastItem = moviesList.Last(); foreach (var itemMovie in moviesList) { itemMovie.poster_path = PathMoviesImage.PathConverter(itemMovie.id.ToString(), itemMovie.poster_path); ItemsMovie.Add(itemMovie); } Debug.WriteLine($"{ItemsMovie.Count()} {ItemsMovie.Count} "); } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public override async Task LoadAsync() { SearchInit = true; SearchText = null; IsBusy = true; ItemsMovie.Clear(); if (!await StatusConnections.VerifyConnect()) { ItemsMovie.Add(new MoviesModel() { title = "Sem conexão..." }); IsBusy = false; return; } CountPages = 1; var moviesList = await HubService.GetMoviesAsync(CountPages); foreach (var itemMovie in moviesList) { itemMovie.poster_path = PathMoviesImage.PathConverter(itemMovie.id.ToString(), itemMovie.poster_path); ItemsMovie.Add(itemMovie); } OnPropertyChanged(nameof(ItemsMovie)); IsBusy = false; }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } if (!await StatusConnections.VerifyConnect()) { ItemsMovie.Add(new MoviesModel() { title = "Sem conexão ativa com a internet..." }); IsBusy = false; return; } IsBusy = true; try { CountPages = 1; ItemsMovie.Clear(); var moviesList = await HubService.GetMoviesAsync(CountPages); foreach (var item in moviesList) { ItemsMovie.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
private async void ExecuteSearchCommand() { if (!await StatusConnections.VerifyConnect()) { ItemsMovie.Add(new MoviesModel() { title = "Sem conexão ativa com a internet..." }); IsBusy = false; return; } var itemsInfiniteSearch = new InfiniteScrollCollection <MoviesModel> { OnLoadMore = async() => { IsBusy = true; CountPages++; if (CountPages == 1) { ItemsMovie.Clear(); } var moviesList = await HubService.GetSearchMovieAsync(SearchText, CountPages.ToString()); if (moviesList == null) { return(new InfiniteScrollCollection <MoviesModel>()); } foreach (var itemMovie in moviesList.results) { itemMovie.poster_path = PathMoviesImage.PathConverter(itemMovie.id.ToString(), itemMovie.poster_path); ItemsMovie.Add(itemMovie); } IsBusy = false; return(moviesList.results); } }; if (string.IsNullOrEmpty(SearchText)) { await LoadAsync(); return; } IsBusy = true; CountPages = 1; MovieSearchModel movies = await HubService.GetSearchMovieAsync(SearchText, CountPages.ToString()); IsBusy = false; if (movies == null) { return; } if (CountPages == 1) { ItemsMovie.Clear(); } foreach (var item in movies.results) { item.poster_path = PathMoviesImage.PathConverter(item.id.ToString(), item.poster_path); ItemsMovie.Add(item); } OnPropertyChanged(nameof(ItemsMovie)); IsBusy = false; }