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

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

refactor: code cleanup

parent adfc07b3
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -90,8 +90,8 @@ android {

    buildTypes {
        debug {
//            versionNameSuffix ".debug"
//            applicationIdSuffix ".debug"
            versionNameSuffix ".debug"
            applicationIdSuffix ".debug"
            signingConfig signingConfigs.debugConfig
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
+1 −35
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ package foundation.e.apps.data.fused
import android.content.Context
import android.text.format.Formatter
import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData
import androidx.lifecycle.liveData
import androidx.lifecycle.map
import com.aurora.gplayapi.Constants
@@ -65,19 +64,15 @@ import foundation.e.apps.data.fused.utils.CategoryUtils
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.data.gplay.GplayStoreRepository
import foundation.e.apps.data.gplay.utils.GplayHttpRequestException
import foundation.e.apps.data.gplay.utils.runFlowWithTimeout
import foundation.e.apps.data.login.exceptions.GPlayException
import foundation.e.apps.data.login.exceptions.UnknownSourceException
import foundation.e.apps.data.preference.PreferenceManagerModule
import foundation.e.apps.install.pkg.PWAManagerModule
import foundation.e.apps.install.pkg.PkgManagerModule
import foundation.e.apps.ui.home.model.HomeChildFusedAppDiffUtil
import foundation.e.apps.ui.search.SearchViewModel
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withTimeout
import retrofit2.Response
@@ -290,15 +285,6 @@ class FusedApiImpl @Inject constructor(
            )
        }

//            if (preferenceManagerModule.isGplaySelected()) {
//                emitSource(
//                    fetchGplaySearchResults(
//                        query,
//                        searchResult,
//                        packageSpecificResults
//                    ).asLiveData()
//                )
//            }
        return finalSearchResult
    }

@@ -335,26 +321,6 @@ class FusedApiImpl @Inject constructor(
        )
    }

//    private suspend fun fetchGplaySearchResults(
//        query: String,
//        searchResult: MutableList<FusedApp>,
//        packageSpecificResults: ArrayList<FusedApp>
//    ): GplaySearchResultFlow = getGplaySearchResult(query).map {
//        if (it.first.isNotEmpty()) {
//            searchResult.addAll(it.first)
//        }
//        ResultSupreme.Success(
//            Pair(
//                filterWithKeywordSearch(
//                    searchResult,
//                    packageSpecificResults,
//                    query
//                ),
//                it.second
//            )
//        )
//    }

    private suspend fun fetchOpenSourceSearchResult(
        cleanApkResults: MutableList<FusedApp>,
        query: String,
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.aurora.gplayapi.data.models.File
import com.aurora.gplayapi.data.models.SearchBundle
import foundation.e.apps.data.BaseStoreRepository
import foundation.e.apps.data.fused.utils.CategoryType
import kotlinx.coroutines.flow.Flow

interface GplayStoreRepository : BaseStoreRepository {
    suspend fun getSearchResult(query: String, subBundle: MutableSet<SearchBundle.SubBundle>?): Pair<List<App>, MutableSet<SearchBundle.SubBundle>>
+13 −137
Original line number Diff line number Diff line
@@ -39,10 +39,6 @@ import foundation.e.apps.data.fused.utils.CategoryType
import foundation.e.apps.data.gplay.utils.GPlayHttpClient
import foundation.e.apps.data.login.LoginSourceRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.withContext
import timber.log.Timber
import javax.inject.Inject
@@ -77,54 +73,6 @@ class GplayStoreRepositoryImpl @Inject constructor(
        context.getString(R.string.movers_shakers_games) to mapOf(Chart.MOVERS_SHAKERS to TopChartsHelper.Type.GAME),
    )

//    override suspend fun getSearchResult(
//        query: String,
//    ): Flow<Pair<List<App>, Boolean>> {
//        return flow {
//
//            /*
//             * Variable names and logic made same as that of Aurora store.
//             * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5171
//             */
//            var authData = loginSourceRepository.gplayAuth ?: return@flow
//
//            val searchHelper =
//                SearchHelper(authData).using(gPlayHttpClient)
//            val searchBundle = searchHelper.searchResults(query)
//
//            val initialReplacedList = mutableListOf<App>()
//            val INITIAL_LIMIT = 4
//
//            emitReplacedList(
//                this@flow,
//                initialReplacedList,
//                INITIAL_LIMIT,
//                searchBundle,
//                true,
//            )
//
//            var nextSubBundleSet: MutableSet<SearchBundle.SubBundle>
//            do {
//                nextSubBundleSet = fetchNextSubBundle(
//                    searchBundle,
//                    searchHelper,
//                    this@flow,
//                    initialReplacedList,
//                    INITIAL_LIMIT
//                )
//            } while (nextSubBundleSet.isNotEmpty())
//
//            /*
//             * If initialReplacedList size is less than INITIAL_LIMIT,
//             * it means the results were very less and nothing has been emitted so far.
//             * Hence emit the list.
//             */
//            if (initialReplacedList.size < INITIAL_LIMIT) {
//                emitInMain(this@flow, initialReplacedList, false)
//            }
//        }.flowOn(Dispatchers.IO)
//    }

    override suspend fun getSearchResult(
        query: String,
        subBundle: MutableSet<SearchBundle.SubBundle>?
@@ -137,15 +85,14 @@ class GplayStoreRepositoryImpl @Inject constructor(
        subBundle?.let {
            val searchResult = searchHelper.next(it)
            Timber.d("fetching next page search data...")
                return emitSearchResult(searchResult)
            return getSearchResultPair(searchResult)
        }

        val searchResult = searchHelper.searchResults(query)
            return emitSearchResult(searchResult)

        return getSearchResultPair(searchResult)
    }

    private fun emitSearchResult(
    private fun getSearchResultPair(
        searchBundle: SearchBundle
    ): Pair<MutableList<App>, MutableSet<SearchBundle.SubBundle>> {
        val apps = searchBundle.appList
@@ -153,31 +100,6 @@ class GplayStoreRepositoryImpl @Inject constructor(
        return Pair(apps, searchBundle.subBundles)
    }

    private suspend fun fetchNextSubBundle(
        searchBundle: SearchBundle,
        searchHelper: SearchHelper,
        scope: FlowCollector<Pair<List<App>, Boolean>>,
        accumulationList: MutableList<App>,
        accumulationLimit: Int,
    ): MutableSet<SearchBundle.SubBundle> {
        val nextSubBundleSet = searchBundle.subBundles
        val newSearchBundle = searchHelper.next(nextSubBundleSet)
        if (newSearchBundle.appList.isNotEmpty()) {
            searchBundle.apply {
                subBundles.clear()
                subBundles.addAll(newSearchBundle.subBundles)
                emitReplacedList(
                    scope,
                    accumulationList,
                    accumulationLimit,
                    newSearchBundle,
                    nextSubBundleSet.isNotEmpty(),
                )
            }
        }
        return nextSubBundleSet
    }

    override suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry> {
        val authData = loginSourceRepository.gplayAuth ?: return listOf()

@@ -243,52 +165,6 @@ class GplayStoreRepositoryImpl @Inject constructor(
        return if (type == CategoryType.APPLICATION) Category.Type.APPLICATION else Category.Type.GAME
    }

    private suspend fun emitReplacedList(
        scope: FlowCollector<Pair<List<App>, Boolean>>,
        accumulationList: MutableList<App>,
        accumulationLimit: Int,
        searchBundle: SearchBundle,
        moreToEmit: Boolean,
    ) {
        searchBundle.appList.forEach {
            when {
                accumulationList.size < accumulationLimit - 1 -> {
                    /*
                     * If initial limit is 4, add apps to list (without emitting)
                     * till 2 apps.
                     */
                    accumulationList.add(it)
                }

                accumulationList.size == accumulationLimit - 1 -> {
                    /*
                     * If initial limit is 4, and we have reached till 3 apps,
                     * add the 4th app and emit the list.
                     */
                    accumulationList.add(it)
                    scope.emit(Pair(accumulationList, moreToEmit))
                    emitInMain(scope, accumulationList, moreToEmit)
                }

                accumulationList.size == accumulationLimit -> {
                    /*
                     * If initial limit is 4, and we have emitted 4 apps,
                     * for all rest of the apps, emit each app one by one.
                     */
                    emitInMain(scope, listOf(it), moreToEmit)
                }
            }
        }
    }

    private suspend fun emitInMain(
        scope: FlowCollector<Pair<List<App>, Boolean>>,
        it: List<App>,
        moreToEmit: Boolean
    ) {
        scope.emit(Pair(it, moreToEmit))
    }

    private suspend fun getTopApps(
        type: TopChartsHelper.Type,
        chart: Chart,
+0 −2
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@
package foundation.e.apps.install.workmanager

import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Environment
import android.os.StatFs
import com.aurora.gplayapi.exceptions.ApiException
Loading