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

Verified Commit 35410b90 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: introduce SearchSuggestion data class independent of GPlay API

parent a94daa85
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import foundation.e.apps.data.application.search.SearchRepository
import foundation.e.apps.data.application.utils.CategoryType
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.application.search.SearchResult
import foundation.e.apps.data.application.search.SearchSuggestion
import javax.inject.Inject
import javax.inject.Singleton

@@ -105,8 +106,8 @@ class ApplicationRepository @Inject constructor(
        return categoryApi.getCategoriesList(type)
    }

    suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry> {
        return searchAPIImpl.getSearchSuggestions(query)
    suspend fun getSearchSuggestions(query: String): List<SearchSuggestion> {
        return searchRepositoryImpl.getSearchSuggestions(query)
    }

    suspend fun getCleanApkSearchResults(
+1 −1
Original line number Diff line number Diff line
@@ -51,5 +51,5 @@ interface SearchRepository {
        query: String,
    ): SearchResult

    suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry>
    suspend fun getSearchSuggestions(query: String): List<SearchSuggestion>
}
+4 −4
Original line number Diff line number Diff line
@@ -279,13 +279,13 @@ class SearchRepositoryImpl @Inject constructor(
        return ResultSupreme.create(result.getResultStatus(), application)
    }

    override suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry> {
        var searchSuggesions = listOf<SearchSuggestEntry>()
    override suspend fun getSearchSuggestions(query: String): List<SearchSuggestion> {
        var searchSuggestions = listOf<SearchSuggestion>()
        handleNetworkResult {
            searchSuggesions = appSources.gplayRepo.getSearchSuggestions(query)
            searchSuggestions = appSources.gplayRepo.getSearchSuggestions(query)
        }

        return searchSuggesions
        return searchSuggestions
    }

    private suspend fun getCleanAPKSearchResults(
+26 −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.application.search

import foundation.e.apps.data.enums.Source

data class SearchSuggestion(
    val suggestion: String,
    val source: Source
)
+3 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import foundation.e.apps.data.StoreRepository
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Home
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
@@ -106,13 +107,14 @@ class PlayStoreRepository @Inject constructor(
        }
    }

    suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry> {
    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) }
    }

    fun getAppsByCategory(category: String, pageUrl: String?): StreamCluster {
Loading