diff --git a/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/OverviewRepository.kt b/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/OverviewRepository.kt index fe27bab..260c7cf 100644 --- a/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/OverviewRepository.kt +++ b/app/src/main/java/nl/ovfietsbeschikbaarheid/repository/OverviewRepository.kt @@ -28,4 +28,8 @@ class OverviewRepository(private val context: Context) { } return allLocations } + + fun getLocations(searchTerm: String): List { + return getAllLocations().filter { it.title.contains(searchTerm, ignoreCase = true) } + } } diff --git a/app/src/main/java/nl/ovfietsbeschikbaarheid/viewmodel/HomeViewModel.kt b/app/src/main/java/nl/ovfietsbeschikbaarheid/viewmodel/HomeViewModel.kt index 490e209..dc5a356 100644 --- a/app/src/main/java/nl/ovfietsbeschikbaarheid/viewmodel/HomeViewModel.kt +++ b/app/src/main/java/nl/ovfietsbeschikbaarheid/viewmodel/HomeViewModel.kt @@ -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