// 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); } }
// 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); }
// Dynamic search in UI ListView private void SearchInCollection() { SearchPokeList.Clear(); var tempSearchString = PokeList.Where(x => x.PokeName.ToLower().Contains(SearchBox.ToLower())); var tempSearchId = PokeList.Where(x => x.Id.ToString().Contains(SearchBox)); // Try to search for numbers if Searchbox contains digits try { cSearch = SearchBox.ToCharArray()[0]; } catch { // } if (cSearch >= '0' && cSearch <= '9') { foreach (var pokemon in tempSearchId) { SearchPokeList.Add(new PokemonModel { Id = pokemon.Id, PokeName = pokemon.PokeName, PokeNameOriginal = pokemon.PokeNameOriginal, PokeUrl = pokemon.PokeUrl }); } } else // Search for string { foreach (var pokemon in tempSearchString) { SearchPokeList.Add(new PokemonModel { Id = pokemon.Id, PokeName = pokemon.PokeName, PokeNameOriginal = pokemon.PokeNameOriginal, PokeUrl = pokemon.PokeUrl }); } } NotifyOfPropertyChange(() => SearchPokeList); }