Loading app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt +21 −24 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class SearchRepositoryImpl @Inject constructor( override suspend fun getOpenSourceSearchResults(query: String): SearchResult { val searchResultsByPackageName = if (isPackageName(query)) { fetchPackageSpecificResult(query).data?.first.orEmpty() searchAppsByPackageName(query).data?.first.orEmpty() } else { emptyList() } Loading Loading @@ -135,42 +135,39 @@ class SearchRepositoryImpl @Inject constructor( } } private suspend fun fetchPackageSpecificResult( query: String, ): SearchResult { val packageSpecificResults: MutableList<Application> = mutableListOf() var gplayPackageResult: Application? = null var cleanApkPackageResult: Application? = null private suspend fun searchAppsByPackageName(query: String): SearchResult { val apps = mutableListOf<Application?>() var playStoreApp: Application? = null var cleanApkApp: Application? = null val result = handleNetworkResult { if (stores.isStoreEnabled(Source.PLAY_STORE)) { gplayPackageResult = getGplayPackageResult(query) playStoreApp = getPlayStoreApp(query) } if (stores.isStoreEnabled(Source.OPEN_SOURCE)) { cleanApkPackageResult = getCleanApkPackageResult(query) cleanApkApp = getCleanApkApp(query) } } /* * Currently only show open source package result if exists in both fdroid and gplay. */ cleanApkPackageResult?.let { packageSpecificResults.add(it) } ?: run { gplayPackageResult?.let { packageSpecificResults.add(it) } val resultStatus = result.getResultStatus() if (resultStatus != ResultStatus.OK) { return ResultSupreme.create(resultStatus, Pair(emptyList(), false)) } if (stores.isStoreEnabled(Source.PLAY_STORE)) { packageSpecificResults.add(Application(isPlaceHolder = true)) // Choose only open source app if it exists both in F-Droid and Play Store. // Example: com.fsck.k9 when { cleanApkApp != null -> apps.add(cleanApkApp) playStoreApp != null -> apps.add(playStoreApp) } if (result.getResultStatus() != ResultStatus.OK) { return ResultSupreme.create( result.getResultStatus(), Pair(packageSpecificResults, false) ) if (stores.isStoreEnabled(Source.PLAY_STORE)) { apps.add(Application(isPlaceHolder = true)) } return ResultSupreme.create(result.getResultStatus(), Pair(packageSpecificResults, true)) return ResultSupreme.create(resultStatus, Pair(apps.mapNotNull { it }, true)) } /* Loading Loading @@ -198,7 +195,7 @@ class SearchRepositoryImpl @Inject constructor( return finalList } private suspend fun getCleanApkPackageResult(query: String): Application? { private suspend fun getCleanApkApp(query: String): Application? { getCleanApkSearchResult(query).let { if (it.isSuccess() && it.data!!.package_name.isNotBlank()) { return it.data!! Loading @@ -208,7 +205,7 @@ class SearchRepositoryImpl @Inject constructor( return null } private suspend fun getGplayPackageResult(query: String): Application? { private suspend fun getPlayStoreApp(query: String): Application? { val storeRepository = stores.getStore(Source.PLAY_STORE) as? PlayStoreRepository return storeRepository?.getAppDetailsWeb(query) } Loading Loading
app/src/main/java/foundation/e/apps/data/application/search/SearchRepositoryImpl.kt +21 −24 Original line number Diff line number Diff line Loading @@ -48,7 +48,7 @@ class SearchRepositoryImpl @Inject constructor( override suspend fun getOpenSourceSearchResults(query: String): SearchResult { val searchResultsByPackageName = if (isPackageName(query)) { fetchPackageSpecificResult(query).data?.first.orEmpty() searchAppsByPackageName(query).data?.first.orEmpty() } else { emptyList() } Loading Loading @@ -135,42 +135,39 @@ class SearchRepositoryImpl @Inject constructor( } } private suspend fun fetchPackageSpecificResult( query: String, ): SearchResult { val packageSpecificResults: MutableList<Application> = mutableListOf() var gplayPackageResult: Application? = null var cleanApkPackageResult: Application? = null private suspend fun searchAppsByPackageName(query: String): SearchResult { val apps = mutableListOf<Application?>() var playStoreApp: Application? = null var cleanApkApp: Application? = null val result = handleNetworkResult { if (stores.isStoreEnabled(Source.PLAY_STORE)) { gplayPackageResult = getGplayPackageResult(query) playStoreApp = getPlayStoreApp(query) } if (stores.isStoreEnabled(Source.OPEN_SOURCE)) { cleanApkPackageResult = getCleanApkPackageResult(query) cleanApkApp = getCleanApkApp(query) } } /* * Currently only show open source package result if exists in both fdroid and gplay. */ cleanApkPackageResult?.let { packageSpecificResults.add(it) } ?: run { gplayPackageResult?.let { packageSpecificResults.add(it) } val resultStatus = result.getResultStatus() if (resultStatus != ResultStatus.OK) { return ResultSupreme.create(resultStatus, Pair(emptyList(), false)) } if (stores.isStoreEnabled(Source.PLAY_STORE)) { packageSpecificResults.add(Application(isPlaceHolder = true)) // Choose only open source app if it exists both in F-Droid and Play Store. // Example: com.fsck.k9 when { cleanApkApp != null -> apps.add(cleanApkApp) playStoreApp != null -> apps.add(playStoreApp) } if (result.getResultStatus() != ResultStatus.OK) { return ResultSupreme.create( result.getResultStatus(), Pair(packageSpecificResults, false) ) if (stores.isStoreEnabled(Source.PLAY_STORE)) { apps.add(Application(isPlaceHolder = true)) } return ResultSupreme.create(result.getResultStatus(), Pair(packageSpecificResults, true)) return ResultSupreme.create(resultStatus, Pair(apps.mapNotNull { it }, true)) } /* Loading Loading @@ -198,7 +195,7 @@ class SearchRepositoryImpl @Inject constructor( return finalList } private suspend fun getCleanApkPackageResult(query: String): Application? { private suspend fun getCleanApkApp(query: String): Application? { getCleanApkSearchResult(query).let { if (it.isSuccess() && it.data!!.package_name.isNotBlank()) { return it.data!! Loading @@ -208,7 +205,7 @@ class SearchRepositoryImpl @Inject constructor( return null } private suspend fun getGplayPackageResult(query: String): Application? { private suspend fun getPlayStoreApp(query: String): Application? { val storeRepository = stores.getStore(Source.PLAY_STORE) as? PlayStoreRepository return storeRepository?.getAppDetailsWeb(query) } Loading