Skip to content

Commit

Permalink
Make the repository responsible for filtering on search term
Browse files Browse the repository at this point in the history
  • Loading branch information
cristan committed Sep 24, 2024
1 parent b896ac2 commit e5e22e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ class OverviewRepository(private val context: Context) {
}
return allLocations
}

fun getLocations(searchTerm: String): List<LocationOverviewModel> {
return getAllLocations().filter { it.title.contains(searchTerm, ignoreCase = true) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class HomeViewModel(
if (searchTerm.isBlank()) {
loadLocation()
} else {
val allLocations = overviewRepository.getAllLocations()
val filteredLocations = allLocations.filter { it.title.contains(searchTerm, ignoreCase = true) }
val filteredLocations = overviewRepository.getLocations(searchTerm)
val currentContent = _content.value
if (currentContent is HomeContent.SearchTermContent) {
// Update the search results right away, but keep the nearby locations and update them in another thread to avoid flicker
Expand Down

0 comments on commit e5e22e7

Please sign in to comment.