diff --git a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImplKt.kt b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImplKt.kt index dc1a1470c7..bee7a918e3 100644 --- a/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImplKt.kt +++ b/app/src/main/java/org/dhis2/usescases/searchTrackEntity/SearchRepositoryImplKt.kt @@ -44,30 +44,27 @@ class SearchRepositoryImplKt( searchParametersModel: SearchParametersModel, isOnline: Boolean, ): TrackedEntitySearchCollectionRepository { - var allowCache = false - - if (searchParametersModel != searchRepositoryJava.savedSearchParameters || !FilterManager.getInstance() - .sameFilters(searchRepositoryJava.savedFilters) - ) { - trackedEntityInstanceQuery = - searchRepositoryJava.getFilteredRepository(searchParametersModel) - } else { + trackedEntityInstanceQuery = searchRepositoryJava.getFilteredRepository(searchParametersModel) - allowCache = true - } - if (searchRepositoryJava.fetchedTeiUIDs.isNotEmpty() && searchParametersModel.selectedProgram == null) { - trackedEntityInstanceQuery = - trackedEntityInstanceQuery.excludeUids().`in`(searchRepositoryJava.fetchedTeiUIDs.toList()) + val allowCache = !( + searchParametersModel != searchRepositoryJava.savedSearchParameters || + !FilterManager.getInstance().sameFilters(searchRepositoryJava.savedFilters) + ) + + if ( + searchRepositoryJava.fetchedTeiUIDs.isNotEmpty() && + searchParametersModel.selectedProgram == null + ) { + trackedEntityInstanceQuery = trackedEntityInstanceQuery.excludeUids() + .`in`(searchRepositoryJava.fetchedTeiUIDs.toList()) } - val pagerFlow = if (isOnline && FilterManager.getInstance().stateFilters.isEmpty()) { + return if (isOnline && FilterManager.getInstance().stateFilters.isEmpty()) { trackedEntityInstanceQuery.allowOnlineCache().eq(allowCache).offlineFirst() } else { trackedEntityInstanceQuery.allowOnlineCache().eq(allowCache).offlineOnly() } - - return pagerFlow } override suspend fun searchParameters(