When nothing is entered display so
This commit is contained in:
		@@ -50,7 +50,7 @@ class PokeSearchViewModel : ViewModel() {
 | 
				
			|||||||
            try {
 | 
					            try {
 | 
				
			||||||
                val response = service.getPokemonSpecies()
 | 
					                val response = service.getPokemonSpecies()
 | 
				
			||||||
                _initialPokemonList.value = response.results
 | 
					                _initialPokemonList.value = response.results
 | 
				
			||||||
                _filteredPokemonList.value = response.results.take(SHOW_LIMIT)
 | 
					                _filteredPokemonList.value = listOf(PokemonSpecies("Please enter a search term", ""));
 | 
				
			||||||
            } catch (e: IOException) {
 | 
					            } catch (e: IOException) {
 | 
				
			||||||
                /*TODO*/
 | 
					                /*TODO*/
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -63,7 +63,7 @@ class PokeSearchViewModel : ViewModel() {
 | 
				
			|||||||
            val filteredList = initialPokemonList.filter { it.name.contains(query, ignoreCase = true) }
 | 
					            val filteredList = initialPokemonList.filter { it.name.contains(query, ignoreCase = true) }
 | 
				
			||||||
            _filteredPokemonList.value = filteredList.take(SHOW_LIMIT);
 | 
					            _filteredPokemonList.value = filteredList.take(SHOW_LIMIT);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            _filteredPokemonList.value = initialPokemonList?.take(SHOW_LIMIT);
 | 
					            _filteredPokemonList.value = listOf(PokemonSpecies("Please enter a search term", ""));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -42,14 +42,16 @@ fun PokeSearch(pokeSearchViewModel: PokeSearchViewModel) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        Spacer(modifier = Modifier.height(16.dp))
 | 
					        Spacer(modifier = Modifier.height(16.dp))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        searchResults?.let { results ->
 | 
					        if (searchResults != null) {
 | 
				
			||||||
            if (results.isNotEmpty()) {
 | 
					            if (searchResults!!.isNotEmpty()) {
 | 
				
			||||||
                results.forEach { pokemon ->
 | 
					                searchResults!!.forEach { pokemon ->
 | 
				
			||||||
                    Text(text = pokemon.name)
 | 
					                    Text(text = pokemon.name)
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                Text("No results found")
 | 
					                Text("No results found")
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            Text("Enter a pokemon name to search")
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user