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

Commit ae359801 authored by Hasib Prince's avatar Hasib Prince
Browse files

refactor: applied coding conventions

parent 1980f59f
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -108,11 +108,11 @@ class FusedAPIRepository @Inject constructor(private val fusedAPIImpl: FusedApi)
        return fusedAPIImpl.getSearchSuggestions(query)
    }

    suspend fun getSearchResults(
    suspend fun getCleanApkSearchResults(
        query: String,
        authData: AuthData
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>> {
        return fusedAPIImpl.getSearchResults(query, authData)
        return fusedAPIImpl.getCleanApkSearchResults(query, authData)
    }

    suspend fun getGplaySearchResults(
+3 −4
Original line number Diff line number Diff line
@@ -58,11 +58,10 @@ interface FusedApi {
     * Fetches search results from cleanAPK and GPlay servers and returns them
     * @param query Query
     * @param authData [AuthData]
     * @return A livedata Pair of list of non-nullable [FusedApp] and
     * a Boolean signifying if more search results are being loaded.
     * Observe this livedata to display new apps as they are fetched from the network.
     * @return ResultSupreme which contains a Pair<List<FusedApp>, Boolean> where List<FusedApp>
     *     is the app list and [Boolean] indicates more data to load or not.
     */
    suspend fun getSearchResults(
    suspend fun getCleanApkSearchResults(
        query: String,
        authData: AuthData
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>>
+11 −4
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ class FusedApiImpl @Inject constructor(
        private const val CATEGORY_TITLE_REPLACEABLE_CONJUNCTION = "&"
        private const val CATEGORY_OPEN_GAMES_ID = "game_open_games"
        private const val CATEGORY_OPEN_GAMES_TITLE = "Open games"
        private const val ERROR_GPLAY_SEARCH = "Gplay search is failed!"
        private const val ERROR_GPLAY_SEARCH = "Gplay search has failed!"
        private const val ERROR_GPLAY_SOURCE_NOT_SELECTED = "Gplay apps are not selected!"
    }

@@ -247,7 +247,7 @@ class FusedApiImpl @Inject constructor(
     * a Boolean signifying if more search results are being loaded.
     * Observe this livedata to display new apps as they are fetched from the network.
     */
    override suspend fun getSearchResults(
    override suspend fun getCleanApkSearchResults(
        query: String,
        authData: AuthData
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>> {
@@ -1086,19 +1086,25 @@ class FusedApiImpl @Inject constructor(

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

            if (searchResults.second.isNotEmpty()) {
                fusedAppList.add(FusedApp(isPlaceHolder = true))
            }

            return ResultSupreme.Success(Pair(fusedAppList.toList(), searchResults.second.toSet()))
        } catch (e: GplayHttpRequestException) {
            val message = e.localizedMessage?.ifBlank { ERROR_GPLAY_SEARCH } ?: ERROR_GPLAY_SEARCH
            val message = (
                e.localizedMessage?.ifBlank { ERROR_GPLAY_SEARCH }
                    ?: ERROR_GPLAY_SEARCH
                ) + "Status: ${e.status}"

            val exception = GPlayException(e.status == 408, message)
            return ResultSupreme.Error(message, exception)
        } catch (e: Exception) {
            val exception =
                GPlayException(e is SocketTimeoutException, e.localizedMessage)
            return ResultSupreme.Error(e.localizedMessage, exception)

            return ResultSupreme.Error(e.localizedMessage ?: "", exception)
        }
    }

@@ -1407,6 +1413,7 @@ class FusedApiImpl @Inject constructor(
        val status = runCodeWithTimeout({
            val streamCluster =
                gplayRepository.getAppsByCategory(category, pageUrl) as StreamCluster

            val filteredAppList = filterRestrictedGPlayApps(authData, streamCluster.clusterAppList)
            filteredAppList.data?.let {
                fusedAppList = it.toMutableList()
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ class GplayStoreRepositoryImpl @Inject constructor(
        var authData = loginSourceRepository.gplayAuth ?: return Pair(emptyList(), mutableSetOf())
        val searchHelper =
            SearchHelper(authData).using(gPlayHttpClient)

        Timber.d("Fetching search result for $query, subBundle: $subBundle")

        subBundle?.let {
+3 −2
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class GPlayHttpClient @Inject constructor(
    companion object {
        private const val TAG = "GPlayHttpClient"
        private const val HTTP_TIMEOUT_IN_SECOND = 10L
        private const val SEARCH = "search"
    }

    private val okHttpClient = OkHttpClient().newBuilder()
@@ -161,7 +162,7 @@ class GPlayHttpClient @Inject constructor(
            // TODO: exception will be thrown for all apis when all gplay api implementation
            // will handle the exceptions. this will be done in following issue.
            // Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1483
            if (request.url.toString().contains("search")) {
            if (request.url.toString().contains(SEARCH)) {
                throw e
            }

@@ -198,7 +199,7 @@ class GPlayHttpClient @Inject constructor(
            // TODO: exception will be thrown for all apis when all gplay api implementation
            // will handle the exceptions. this will be done in following issue.
            // Issue: https://gitlab.e.foundation/e/os/backlog/-/issues/1483
            if (response.request.url.toString().contains("search") && code != 200) {
            if (response.request.url.toString().contains(SEARCH) && code != 200) {
                throw GplayHttpRequestException(code, response.message)
            }

Loading