diff --git a/app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt b/app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt index 510337d264aba619df6053aa39179ed3cb233630..c2de36bce71c747761ac021cd5a2d9a523aa447b 100644 --- a/app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt +++ b/app/src/main/java/foundation/e/apps/data/fused/FusedApiImpl.kt @@ -337,30 +337,36 @@ class FusedApiImpl @Inject constructor( packageSpecificResults: ArrayList ): GplaySearchResultLiveData { return runFlowWithTimeout( - { - getGplaySearchResult(query) - }, { - it.second - }, { - Pair(listOf(), false) // empty data for timeout - } + { getGplaySearchResult(query) }, + { it.second }, // End condition of flow - provided by Gplay lib. + { Pair(listOf(), false) } // empty data for timeout ).map { - if (it.isSuccess()) { - searchResult.addAll(it.data!!.first) - ResultSupreme.Success( - Pair( - filterWithKeywordSearch( - searchResult, - packageSpecificResults, - query - ), - it.data!!.second - ) - ) - } else { - it - } + filterAndAccumulateSearch(it, searchResult, packageSpecificResults, query) + } + } + + private fun filterAndAccumulateSearch( + result: ResultSupreme, Boolean>>, + searchResult: MutableList, + packageSpecificResults: List, + query: String, + ): ResultSupreme, Boolean>> { + if (!result.isSuccess()) { + return result } + + val searchResultList = result.data!!.first + val moreLoading = result.data!!.second + + searchResult.addAll(searchResultList) + + val filteredApps = filterWithKeywordSearch( + searchResult, + packageSpecificResults, + query + ) + + return ResultSupreme.Success(Pair(filteredApps, moreLoading)) } private suspend fun fetchOpenSourceSearchResult(