// method to load PokemonList from the internet over API private async Task LoadFromApi() { // MAX limit currently: 807 int maxPokemons = 807; NamedApiResourceList <Pokemon> allPokemons = await pokeClient.GetNamedResourcePageAsync <Pokemon>(maxPokemons, 0); for (int i = 1; i <= allPokemons.Results.Count; i++) { PokemonSpecies pokemonNameLang = await pokeClient.GetResourceAsync <PokemonSpecies>(i); for (int j = 0; j < pokemonNameLang.Names.Count; j++) { if (pokemonNameLang.Names[j].Language.Name == Language) { PokeList.Add(new PokemonModel { Id = i, PokeNameOriginal = allPokemons.Results[i - 1].Name, PokeName = pokemonNameLang.Names[j].Name, PokeUrl = allPokemons.Results[i - 1].Url }); SearchPokeList.Add(new PokemonModel { Id = i, PokeNameOriginal = allPokemons.Results[i - 1].Name, PokeName = pokemonNameLang.Names[j].Name, PokeUrl = allPokemons.Results[i - 1].Url }); } } // Brings loading status to front-end in ProgressBar await _events.PublishOnUIThreadAsync(new LoadingBarEvent { LoadingCount = i }, CancellationToken.None); } }
private async void LoadItems(string uri = "https://pokeapi.co/api/v2/pokemon/") { PokeBus = await DependencyService.Get <IPokemonService>().GetAllAsync(uri); CanButton(); this.PokeList.Clear(); foreach (Pokemon pk in PokeBus.Results) { PokeList.Add(pk); } }
// Method to load PokemonList from local disk private async Task LoadFromDisk(BindableCollection <PokemonModel> loadPokemonsCsv) { foreach (var pokemon in loadPokemonsCsv) { PokeList.Add(new PokemonModel { Id = pokemon.Id, PokeNameOriginal = pokemon.PokeNameOriginal, PokeName = pokemon.PokeName, PokeUrl = pokemon.PokeUrl }); SearchPokeList.Add(new PokemonModel { Id = pokemon.Id, PokeNameOriginal = pokemon.PokeNameOriginal, PokeName = pokemon.PokeName, PokeUrl = pokemon.PokeUrl }); } await _events.PublishOnUIThreadAsync(new LoadingBarEvent { LoadingCount = loadPokemonsCsv.Count }, CancellationToken.None); }