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 {
val response = service.getPokemonSpecies()
_initialPokemonList.value = response.results
_filteredPokemonList.value = response.results.take(SHOW_LIMIT)
_filteredPokemonList.value = listOf(PokemonSpecies("Please enter a search term", ""));
} catch (e: IOException) {
/*TODO*/
}
@ -63,7 +63,7 @@ class PokeSearchViewModel : ViewModel() {
val filteredList = initialPokemonList.filter { it.name.contains(query, ignoreCase = true) }
_filteredPokemonList.value = filteredList.take(SHOW_LIMIT);
} 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))
searchResults?.let { results ->
if (results.isNotEmpty()) {
results.forEach { pokemon ->
if (searchResults != null) {
if (searchResults!!.isNotEmpty()) {
searchResults!!.forEach { pokemon ->
Text(text = pokemon.name)
}
} else {
Text("No results found")
}
} else {
Text("Enter a pokemon name to search")
}
}
}