From c29fd23fb9c3c55d409b4e4397c4389488effc29 Mon Sep 17 00:00:00 2001 From: Kyle Corry Date: Sun, 15 May 2022 16:00:20 -0400 Subject: [PATCH] Add path search support (not user visible) --- .../paths/infrastructure/PathGroupLoader.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/infrastructure/PathGroupLoader.kt b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/infrastructure/PathGroupLoader.kt index f18065866..ef36d4172 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/infrastructure/PathGroupLoader.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/navigation/paths/infrastructure/PathGroupLoader.kt @@ -2,11 +2,16 @@ package com.kylecorry.trail_sense.navigation.paths.infrastructure import com.kylecorry.trail_sense.navigation.paths.domain.IPath import com.kylecorry.trail_sense.navigation.paths.domain.IPathService +import com.kylecorry.trail_sense.navigation.paths.domain.Path import com.kylecorry.trail_sense.shared.extensions.onIO +import com.kylecorry.trail_sense.shared.grouping.filter.GroupFilter import com.kylecorry.trail_sense.shared.grouping.persistence.ISearchableGroupLoader class PathGroupLoader(private val pathService: IPathService) : ISearchableGroupLoader { + private val loader = pathService.loader() + private val filter = GroupFilter(loader) + override suspend fun load(search: String?, group: Long?): List = onIO { if (search.isNullOrBlank()) { getPathsByGroup(group) @@ -16,15 +21,16 @@ class PathGroupLoader(private val pathService: IPathService) : ISearchableGroupL } private suspend fun getPathsBySearch(search: String, groupFilter: Long?) = onIO { - // TODO: Implement this - emptyList() + filter.filter(groupFilter) { + (it as Path).name?.contains(search, ignoreCase = true) == true + } } private suspend fun getPathsByGroup(group: Long?) = onIO { - pathService.getPaths(group, includeGroups = true) + loader.getChildren(group, 1) } override suspend fun getGroup(id: Long): IPath? { - return pathService.getGroup(id) + return loader.getGroup(id) } } \ No newline at end of file