From dd0a6f1cf5e7070982ce49b5600372be2199cfb5 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Mon, 23 May 2022 13:00:24 +0530 Subject: [PATCH 1/8] App lounge: (issue_2629) Add package name search results --- .../e/apps/api/fused/FusedAPIImpl.kt | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 8130bf9ae..4a9e18502 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -179,7 +179,30 @@ class FusedAPIImpl @Inject constructor( * @return A list of nullable [FusedApp] */ suspend fun getSearchResults(query: String, authData: AuthData): List { - val fusedResponse = mutableListOf() + val fusedResponse = ArrayList() + + /* + * Search cleanapk and GPlay if the search term is a package name. + * Issue: https://gitlab.e.foundation/e/backlog/-/issues/2629 + */ + try { + getApplicationDetails(query, query, authData, Origin.CLEANAPK).let { + /* Cleanapk always returns something, it is never null. + * If nothing is found, it returns a blank FusedApp() object. + * Blank result to be filtered out. + */ + if (it.package_name.isNotBlank()) fusedResponse.add(it) + } + } catch (_: Exception) {} + if (preferenceManagerModule.preferredApplicationType() == APP_TYPE_ANY) { + try { + /* + * Surrounding with try-catch because if query is not a package name, + * then GPlay throws an error. + */ + fusedResponse.add(getApplicationDetails(query, query, authData, Origin.GPLAY)) + } catch (_: Exception) {} + } when (preferenceManagerModule.preferredApplicationType()) { APP_TYPE_ANY -> { -- GitLab From 0efed985d041d89d57b78014a1dff613c730017a Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 17:41:50 +0530 Subject: [PATCH 2/8] issue_2629: update code for new timeout related changes --- .../java/foundation/e/apps/api/fused/FusedAPIImpl.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 0999fad5e..9bf58eddb 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -215,7 +215,9 @@ class FusedAPIImpl @Inject constructor( * If nothing is found, it returns a blank FusedApp() object. * Blank result to be filtered out. */ - if (it.package_name.isNotBlank()) fusedResponse.add(it) + if (it.second == ResultStatus.OK && it.first.package_name.isNotBlank()) { + fusedResponse.add(it.first) + } } } catch (_: Exception) {} if (preferenceManagerModule.preferredApplicationType() == APP_TYPE_ANY) { @@ -224,7 +226,11 @@ class FusedAPIImpl @Inject constructor( * Surrounding with try-catch because if query is not a package name, * then GPlay throws an error. */ - fusedResponse.add(getApplicationDetails(query, query, authData, Origin.GPLAY)) + getApplicationDetails(query, query, authData, Origin.GPLAY).let { + if (it.second == ResultStatus.OK) { + fusedResponse.add(it.first) + } + } } catch (_: Exception) {} } -- GitLab From dce236638c240d7c1ae413cbc858a6a6b9150abe Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 18:10:18 +0530 Subject: [PATCH 3/8] issue_2629: create method findCleanapkSearchResultByPackageName() for searching via package name in cleanapk, to be only used for search results list. --- .../e/apps/api/fused/FusedAPIImpl.kt | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 9bf58eddb..1382754ad 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -30,6 +30,7 @@ import com.aurora.gplayapi.data.models.Category import com.aurora.gplayapi.helpers.TopChartsHelper import dagger.hilt.android.qualifiers.ApplicationContext import foundation.e.apps.R +import foundation.e.apps.api.ResultSupreme import foundation.e.apps.api.cleanapk.CleanAPKInterface import foundation.e.apps.api.cleanapk.CleanAPKRepository import foundation.e.apps.api.cleanapk.data.categories.Categories @@ -376,6 +377,28 @@ class FusedAPIImpl @Inject constructor( return Triple(appsList, nextUrl, status) } + /* + * Method to search cleanapk based on package name. + * This is to be only used for showing an entry in search results list. + * DO NOT use this to show info on ApplicationFragment as it will not have all the required + * information to show for an app. + * + * Issue: https://gitlab.e.foundation/e/backlog/-/issues/2629 + */ + private suspend fun findCleanapkSearchResultByPackageName(packageName: String): ResultSupreme { + var fusedApp = FusedApp() + val status = runCodeBlockWithTimeout({ + val result = cleanAPKRepository.searchApps( + keyword = packageName, + by = "package_name" + ).body() + if (result?.apps?.isNotEmpty() == true && result.numberOfResults == 1) { + fusedApp = result.apps[0] + } + }) + return ResultSupreme.create(status, fusedApp) + } + suspend fun getApplicationDetails( packageNameList: List, authData: AuthData, -- GitLab From e5ad87b8331e32d1776d6d2c0cd51835b42404f9 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 18:16:17 +0530 Subject: [PATCH 4/8] issue_2629: use findCleanapkSearchResultByPackageName() and show package search results from GPlay and F-droid both. --- .../java/foundation/e/apps/api/fused/FusedAPIImpl.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 1382754ad..d9ce284ed 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -207,17 +207,18 @@ class FusedAPIImpl @Inject constructor( */ suspend fun getSearchResults(query: String, authData: AuthData): Pair, ResultStatus> { val fusedResponse = ArrayList() + val packageSpecificResults = ArrayList() val status = runCodeBlockWithTimeout({ try { - getApplicationDetails(query, query, authData, Origin.CLEANAPK).let { + findCleanapkSearchResultByPackageName(query).let { /* Cleanapk always returns something, it is never null. * If nothing is found, it returns a blank FusedApp() object. * Blank result to be filtered out. */ - if (it.second == ResultStatus.OK && it.first.package_name.isNotBlank()) { - fusedResponse.add(it.first) + if (it.isSuccess() && it.data!!.package_name.isNotBlank()) { + packageSpecificResults.add(it.data!!) } } } catch (_: Exception) {} @@ -229,7 +230,7 @@ class FusedAPIImpl @Inject constructor( */ getApplicationDetails(query, query, authData, Origin.GPLAY).let { if (it.second == ResultStatus.OK) { - fusedResponse.add(it.first) + packageSpecificResults.add(it.first) } } } catch (_: Exception) {} @@ -254,7 +255,8 @@ class FusedAPIImpl @Inject constructor( } } }) - return Pair(fusedResponse.distinctBy { it.package_name }, status) + + return Pair(packageSpecificResults + fusedResponse.distinctBy { it.package_name }, status) } suspend fun getSearchSuggestions(query: String, authData: AuthData): List { -- GitLab From 7f1b02578d84b57024ddc3555ad63c4798e412be Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 18:17:58 +0530 Subject: [PATCH 5/8] issue_2629: filter out package name results from keyword search --- .../foundation/e/apps/api/fused/FusedAPIImpl.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index d9ce284ed..6a4cf1642 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -256,7 +256,18 @@ class FusedAPIImpl @Inject constructor( } }) - return Pair(packageSpecificResults + fusedResponse.distinctBy { it.package_name }, status) + /* + * The list packageSpecificResults may contain apps with duplicate package names. + * Example, "org.telegram.messenger" will result in "Telegram" app from Play Store + * and "Telegram FOSS" from F-droid. We show both of them at the top. + * + * But for the other keyword related search results, we do not allow duplicate package names. + * We also filter out apps which are already present in packageSpecificResults list. + */ + val filteredResults = fusedResponse.distinctBy { it.package_name } + .filter { packageSpecificResults.isEmpty() || it.package_name != query } + + return Pair(packageSpecificResults + filteredResults, status) } suspend fun getSearchSuggestions(query: String, authData: AuthData): List { -- GitLab From fe8bc4cdb346a1bfab5f1ed3386f3f60b6e6d054 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 18:22:51 +0530 Subject: [PATCH 6/8] issue_2629: for package name results, if user preference shows gplay apps, then show gplay item before cleanapk item. --- .../e/apps/api/fused/FusedAPIImpl.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 6a4cf1642..8880830d0 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -212,6 +212,19 @@ class FusedAPIImpl @Inject constructor( val status = runCodeBlockWithTimeout({ try { + if (preferenceManagerModule.preferredApplicationType() == APP_TYPE_ANY) { + try { + /* + * Surrounding with try-catch because if query is not a package name, + * then GPlay throws an error. + */ + getApplicationDetails(query, query, authData, Origin.GPLAY).let { + if (it.second == ResultStatus.OK) { + packageSpecificResults.add(it.first) + } + } + } catch (_: Exception) {} + } findCleanapkSearchResultByPackageName(query).let { /* Cleanapk always returns something, it is never null. * If nothing is found, it returns a blank FusedApp() object. @@ -222,19 +235,6 @@ class FusedAPIImpl @Inject constructor( } } } catch (_: Exception) {} - if (preferenceManagerModule.preferredApplicationType() == APP_TYPE_ANY) { - try { - /* - * Surrounding with try-catch because if query is not a package name, - * then GPlay throws an error. - */ - getApplicationDetails(query, query, authData, Origin.GPLAY).let { - if (it.second == ResultStatus.OK) { - packageSpecificResults.add(it.first) - } - } - } catch (_: Exception) {} - } when (preferenceManagerModule.preferredApplicationType()) { APP_TYPE_ANY -> { -- GitLab From 66004751c68e5dfa5dd0e78708179261901a9f5a Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 18:37:09 +0530 Subject: [PATCH 7/8] issue_2629: rename findCleanapkSearchResultByPackageName to getCleanapkSearchResult --- app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 8880830d0..3d17222e3 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -225,7 +225,7 @@ class FusedAPIImpl @Inject constructor( } } catch (_: Exception) {} } - findCleanapkSearchResultByPackageName(query).let { + getCleanapkSearchResult(query).let { /* Cleanapk always returns something, it is never null. * If nothing is found, it returns a blank FusedApp() object. * Blank result to be filtered out. @@ -398,7 +398,7 @@ class FusedAPIImpl @Inject constructor( * * Issue: https://gitlab.e.foundation/e/backlog/-/issues/2629 */ - private suspend fun findCleanapkSearchResultByPackageName(packageName: String): ResultSupreme { + private suspend fun getCleanapkSearchResult(packageName: String): ResultSupreme { var fusedApp = FusedApp() val status = runCodeBlockWithTimeout({ val result = cleanAPKRepository.searchApps( -- GitLab From 4a393b9cc157fbf205a744474a06a7c390bacc04 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Thu, 9 Jun 2022 19:07:04 +0530 Subject: [PATCH 8/8] issue_2629: move location of getCleanapkSearchResult() to avoid potential merge conflicts --- .../e/apps/api/fused/FusedAPIImpl.kt | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index 3d17222e3..cf6d4ac27 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -270,6 +270,28 @@ class FusedAPIImpl @Inject constructor( return Pair(packageSpecificResults + filteredResults, status) } + /* + * Method to search cleanapk based on package name. + * This is to be only used for showing an entry in search results list. + * DO NOT use this to show info on ApplicationFragment as it will not have all the required + * information to show for an app. + * + * Issue: https://gitlab.e.foundation/e/backlog/-/issues/2629 + */ + private suspend fun getCleanapkSearchResult(packageName: String): ResultSupreme { + var fusedApp = FusedApp() + val status = runCodeBlockWithTimeout({ + val result = cleanAPKRepository.searchApps( + keyword = packageName, + by = "package_name" + ).body() + if (result?.apps?.isNotEmpty() == true && result.numberOfResults == 1) { + fusedApp = result.apps[0] + } + }) + return ResultSupreme.create(status, fusedApp) + } + suspend fun getSearchSuggestions(query: String, authData: AuthData): List { return gPlayAPIRepository.getSearchSuggestions(query, authData) } @@ -390,28 +412,6 @@ class FusedAPIImpl @Inject constructor( return Triple(appsList, nextUrl, status) } - /* - * Method to search cleanapk based on package name. - * This is to be only used for showing an entry in search results list. - * DO NOT use this to show info on ApplicationFragment as it will not have all the required - * information to show for an app. - * - * Issue: https://gitlab.e.foundation/e/backlog/-/issues/2629 - */ - private suspend fun getCleanapkSearchResult(packageName: String): ResultSupreme { - var fusedApp = FusedApp() - val status = runCodeBlockWithTimeout({ - val result = cleanAPKRepository.searchApps( - keyword = packageName, - by = "package_name" - ).body() - if (result?.apps?.isNotEmpty() == true && result.numberOfResults == 1) { - fusedApp = result.apps[0] - } - }) - return ResultSupreme.create(status, fusedApp) - } - suspend fun getApplicationDetails( packageNameList: List, authData: AuthData, -- GitLab