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) {
|
fun search(query: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
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>()
|
val detailsList = mutableListOf<PokemonDetails>()
|
||||||
if (filteredList != null) {
|
if (filteredList != null) {
|
||||||
for (pokemonSpecies in filteredList) {
|
for (pokemonSpecies in filteredList.take(SHOW_LIMIT)) {
|
||||||
if (detailsList.size >= SHOW_LIMIT) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
val details = service.getPokemonDetails(extractPokemonId(pokemonSpecies.url))
|
val details = service.getPokemonDetails(extractPokemonId(pokemonSpecies.url))
|
||||||
val isFavorite = favouritesRepository.isFavourite(details.id)
|
val isFavorite = favouritesRepository.isFavourite(details.id)
|
||||||
detailsList.add(details.copy(isFavorite = isFavorite))
|
detailsList.add(details.copy(isFavorite = isFavorite))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user