When nothing is entered display so

This commit is contained in:
Joren 2024-04-29 16:15:09 +02:00
parent 32662281b3
commit a77acd56c7
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 7 additions and 5 deletions

View File

@ -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", ""));
} }
} }
} }

View File

@ -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")
} }
} }
} }