Instaid of searching is a string contains, start from the beginning... makes more sense
This commit is contained in:
		@@ -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))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user