Instaid of searching is a string contains, start from the beginning... makes more sense
This commit is contained in:
parent
3085f958bd
commit
0ebf26c457
@ -36,18 +36,13 @@ class PokeSearchViewModel(private val favouritesRepository: FavouritesRepository
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun search(query: String) {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val filteredList = _initialPokemonList.value?.filter { it.name.contains(query, ignoreCase = true) }
|
||||
val filteredList = _initialPokemonList.value?.filter { it.name.startsWith(query, ignoreCase = true) }
|
||||
val detailsList = mutableListOf<PokemonDetails>()
|
||||
if (filteredList != null) {
|
||||
for (pokemonSpecies in filteredList) {
|
||||
if (detailsList.size >= SHOW_LIMIT) {
|
||||
break
|
||||
}
|
||||
for (pokemonSpecies in filteredList.take(SHOW_LIMIT)) {
|
||||
val details = service.getPokemonDetails(extractPokemonId(pokemonSpecies.url))
|
||||
val isFavorite = favouritesRepository.isFavourite(details.id)
|
||||
detailsList.add(details.copy(isFavorite = isFavorite))
|
||||
|
Loading…
x
Reference in New Issue
Block a user