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

Verified Commit 0a5ae52a authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: introduce PlayStoreSearchHelper to delegate search responsibilities...

refactor: introduce PlayStoreSearchHelper to delegate search responsibilities from PlayStoreRepository to the helper class
parent f06dbb27
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
package foundation.e.apps.data.playstore

import android.content.Context
import com.aurora.gplayapi.SearchSuggestEntry
import com.aurora.gplayapi.data.models.Category
import com.aurora.gplayapi.data.models.ContentRating
import com.aurora.gplayapi.data.models.File
@@ -29,9 +28,9 @@ import com.aurora.gplayapi.helpers.ContentRatingHelper
import com.aurora.gplayapi.helpers.PurchaseHelper
import com.aurora.gplayapi.helpers.contracts.TopChartsContract.Chart
import com.aurora.gplayapi.helpers.contracts.TopChartsContract.Type
import com.aurora.gplayapi.helpers.web.WebAppDetailsHelper
import com.aurora.gplayapi.helpers.web.WebCategoryHelper
import com.aurora.gplayapi.helpers.web.WebCategoryStreamHelper
import com.aurora.gplayapi.helpers.web.WebSearchHelper
import com.aurora.gplayapi.helpers.web.WebTopChartsHelper
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
@@ -43,6 +42,7 @@ import foundation.e.apps.data.application.search.SearchSuggestion
import foundation.e.apps.data.application.utils.CategoryType
import foundation.e.apps.data.application.utils.toApplication
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.login.AuthenticatorRepository
import foundation.e.apps.data.login.PlayStoreAuthenticator
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
@@ -58,7 +58,8 @@ class PlayStoreRepository @Inject constructor(
    @ApplicationContext private val context: Context,
    private val gPlayHttpClient: GPlayHttpClient,
    private val authenticatorRepository: AuthenticatorRepository,
    private val applicationDataManager: ApplicationDataManager
    private val applicationDataManager: ApplicationDataManager,
    private val playStoreSearchHelper: PlayStoreSearchHelper
) : StoreRepository {

    override suspend fun getHomeScreenData(list: MutableList<Home>): List<Home> {
@@ -98,20 +99,12 @@ class PlayStoreRepository @Inject constructor(
    )

    override suspend fun getSearchResults(pattern: String): List<Application> {
        val searchResult = WebSearchHelper().using(gPlayHttpClient).searchResults(pattern)
        return searchResult.appList.map {
            it.toApplication(context)
        }
        val searchResult = playStoreSearchHelper.getSearchResults(pattern)
        return searchResult.map { it.toApplication(context) }
    }

    suspend fun getSearchSuggestions(query: String): List<SearchSuggestion> {
        val searchData = mutableListOf<SearchSuggestEntry>()
        withContext(Dispatchers.IO) {
            val searchHelper = WebSearchHelper().using(gPlayHttpClient)
            searchData.addAll(searchHelper.searchSuggestions(query))
        }
        return searchData.filter { it.title.isNotBlank() }
            .map { SearchSuggestion(it.title, source = Source.PLAY_STORE) }
    override suspend fun getSearchSuggestions(pattern: String): List<SearchSuggestion> {
        return playStoreSearchHelper.getSearchSuggestions(pattern)
    }

    fun getAppsByCategory(category: String, pageUrl: String?): StreamCluster {
@@ -180,6 +173,18 @@ class PlayStoreRepository @Inject constructor(
        authenticatorRepository.fetchAuthObjects(listOf(PlayStoreAuthenticator::class.java.simpleName))
    }

    suspend fun getAppDetailsWeb(packageName: String): Application? {
        val webAppDetailsHelper = WebAppDetailsHelper().using(gPlayHttpClient)

        return withContext(Dispatchers.IO) {
            val result =
                handleNetworkResult { webAppDetailsHelper.getAppByPackageName(packageName) }
            val app = result.data ?: return@withContext null

            app.toApplication(context)
        }
    }

    private fun isEmulator(): Boolean {
        return SystemInfoProvider.getSystemProperty("ro.boot.qemu").equals("1")
    }
+48 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 e Foundation
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

package foundation.e.apps.data.playstore

import com.aurora.gplayapi.helpers.web.WebSearchHelper
import foundation.e.apps.data.application.search.SearchSuggestion
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.playstore.utils.GPlayHttpClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject

class PlayStoreSearchHelper @Inject constructor(
    private val gPlayHttpClient: GPlayHttpClient,
) {
    private val source = Source.PLAY_STORE

    suspend fun getSearchResults(keyword: String) = withContext(Dispatchers.IO) {
        WebSearchHelper()
            .using(gPlayHttpClient)
            .searchResults(keyword).appList
    }

    suspend fun getSearchSuggestions(keyword: String) = withContext(Dispatchers.IO) {
        WebSearchHelper()
            .using(gPlayHttpClient)
            .searchSuggestions(keyword)
            .filter { it.title.isNotBlank() }
            .map { SearchSuggestion(it.title, source) }
    }
}