Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9674d4a0 authored by Sayantan Roychowdhury's avatar Sayantan Roychowdhury
Browse files

Issue 6787: Improve search loading time

parent e07ba4be
Loading
Loading
Loading
Loading
+14 −13
Original line number Diff line number Diff line
@@ -337,8 +337,7 @@ class SearchApiImpl @Inject constructor(
                )
            }

            val fusedAppList =
                searchResults.first.map { app -> replaceWithFDroid(app) }.toMutableList()
            val fusedAppList = replaceWithFDroid(searchResults.first).toMutableList()

            handleLimitedResult(fusedAppList)

@@ -366,19 +365,21 @@ class SearchApiImpl @Inject constructor(
     * This function will replace a GPlay app with F-Droid app if exists,
     * else will show the GPlay app itself.
     */
    private suspend fun replaceWithFDroid(gPlayApp: App): Application {
        val gPlayFusedApp = gPlayApp.toApplication(context)
        val response = appSources.cleanApkAppsRepo.getAppDetails(gPlayApp.packageName)
        if (response != null) {
            val fdroidApp = getCleanApkPackageResult(gPlayFusedApp.package_name)?.apply {
                this.updateSource(context)
                isGplayReplaced = true
            }
    private suspend fun replaceWithFDroid(gPlayApps: List<App>): List<Application> {

            return fdroidApp ?: gPlayFusedApp
        }
        if (gPlayApps.isEmpty()) return emptyList()

        val packageNames = gPlayApps.map { it.packageName }
        val response = appSources.cleanApkAppsRepo.checkAvailablePackages(packageNames)

        return gPlayFusedApp
        val availableApps = response.body()?.apps ?: emptyList()

        return gPlayApps.map { gPlayApp ->
            availableApps.find { it.package_name == gPlayApp.packageName }?.apply {
                isGplayReplaced = true
                updateSource(context)
            } ?: gPlayApp.toApplication(context)
        }
    }

    private fun refreshToken() {
+6 −0
Original line number Diff line number Diff line
@@ -77,6 +77,12 @@ interface CleanApkRetrofit {
        @Query("page") page: Int = 1,
    ): Response<Search>

    @GET("apps?action=list_apps")
    suspend fun checkAvailablePackages(
        @Query("package_names[]") packages: List<String>,
        @Query("source") source: String = "open",
    ): Response<Search>

    @GET("apps?action=download")
    suspend fun getDownloadInfo(
        @Query("app_id") id: String,
+0 −1
Original line number Diff line number Diff line
@@ -23,6 +23,5 @@ import foundation.e.apps.data.application.data.Application
data class Search(
    val apps: List<Application> = emptyList(),
    val numberOfResults: Int = -1,
    val pages: Int = -1,
    val success: Boolean = false
)
+4 −0
Original line number Diff line number Diff line
@@ -71,6 +71,10 @@ class CleanApkAppsRepositoryImpl(
        )
    }

    override suspend fun checkAvailablePackages(packageNames: List<String>): Response<Search> {
        return cleanApkRetrofit.checkAvailablePackages(packageNames)
    }

    override suspend fun getAppDetails(packageNameOrId: String): Response<Application> {
        return cleanApkAppDetailsRetrofit.getAppOrPWADetailsByID(packageNameOrId, null, null)
    }
+4 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ class CleanApkPWARepository(
        )
    }

    override suspend fun checkAvailablePackages(packageNames: List<String>): Response<Search> {
        return cleanAPKRetrofit.checkAvailablePackages(packageNames)
    }

    override suspend fun getAppDetails(packageNameOrId: String): Response<Application> {
        return cleanApkAppDetailsRetrofit.getAppOrPWADetailsByID(packageNameOrId, null, null)
    }
Loading