From e5e22e73aa463f1f2a9b97917c649390647ec5c9 Mon Sep 17 00:00:00 2001 From: Cristan Meijer Date: Tue, 24 Sep 2024 14:14:30 +0200 Subject: [PATCH] Make the repository responsible for filtering on search term --- .../ovfietsbeschikbaarheid/repository/OverviewRepository.kt | 4 ++++ .../java/nl/ovfietsbeschikbaarheid/viewmodel/HomeViewModel.kt | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) 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