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

Commit 29a8167b authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Remove AppSourcesContainer class

parent 898970e0
Loading
Loading
Loading
Loading
Loading
+0 −33
Original line number Diff line number Diff line
/*
 *  Copyright MURENA SAS 2024
 *  Apps  Quickly and easily install Android apps onto your device!
 *
 *  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

import foundation.e.apps.data.cleanapk.repositories.CleanApkAppsRepository
import foundation.e.apps.data.cleanapk.repositories.CleanApkPwaRepository
import foundation.e.apps.data.playstore.PlayStoreRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class AppSourcesContainer @Inject constructor(
    val gplayRepo: PlayStoreRepository,
    val cleanApkAppsRepo: CleanApkAppsRepository,
    val cleanApkPWARepo: CleanApkPwaRepository
)
+34 −32
Original line number Diff line number Diff line
@@ -22,8 +22,8 @@ import android.content.Context
import com.aurora.gplayapi.data.models.App
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.StoreRepository
import foundation.e.apps.data.Stores
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
@@ -33,16 +33,17 @@ import foundation.e.apps.data.application.utils.CategoryUtils
import foundation.e.apps.data.application.utils.toApplication
import foundation.e.apps.data.application.utils.toCategory
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.repositories.CleanApkRepository
import foundation.e.apps.data.enums.AppTag
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.enums.isUnFiltered
import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.playstore.PlayStoreRepository
import javax.inject.Inject

class CategoryApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    private val appSources: AppSourcesContainer,
    private val stores: Stores,
    private val applicationDataManager: ApplicationDataManager
) : CategoryApi {
@@ -50,9 +51,9 @@ class CategoryApiImpl @Inject constructor(
    override suspend fun getCategoriesList(type: CategoryType) : List<CategoriesResponse> {
        val categoryResponses = mutableListOf<CategoriesResponse>()

        for ((source, _) in stores.getStores()) {
        for ((source, repository) in stores.getStores()) {
            val categories = mutableListOf<Category>()
            val status = fetchCategoryResult(categories, type, source)
            val status = fetchCategoryResult(categories, type, source, repository)
            categoryResponses.add(CategoriesResponse(categories, type, source, status))
        }
        return categoryResponses
@@ -61,20 +62,27 @@ class CategoryApiImpl @Inject constructor(
    private suspend fun fetchCategoryResult(
        categoriesList: MutableList<Category>,
        type: CategoryType,
        source: Source
        source: Source,
        repository: StoreRepository
    ): ResultStatus {
        val categoryResult = when (source) {
            Source.OPEN_SOURCE -> {
                fetchCleanApkCategories(type, Source.OPEN_SOURCE)
        val categoryResult: Pair<List<Category>, ResultStatus> = when (source) {
            Source.OPEN_SOURCE, Source.PWA -> {
                val cleanApkRepository = repository as? CleanApkRepository
                if (cleanApkRepository != null) {
                    fetchCleanApkCategories(type, source, cleanApkRepository)
                } else {
                    Pair(emptyList(), ResultStatus.UNKNOWN)
                }

            Source.PWA -> {
                fetchCleanApkCategories(type, Source.PWA)
            }

            else -> {
                fetchGplayCategories(type)
            Source.PLAY_STORE -> {
                val playStoreRepository = repository as? PlayStoreRepository
                if (playStoreRepository != null) {
                    fetchGplayCategories(type, playStoreRepository)
                } else {
                    Pair(emptyList(), ResultStatus.UNKNOWN)
                }
            }
            else -> Pair(emptyList(), ResultStatus.OK)
        }

        categoryResult.let {
@@ -86,10 +94,11 @@ class CategoryApiImpl @Inject constructor(

    private suspend fun fetchGplayCategories(
        type: CategoryType,
        playStoreRepository: PlayStoreRepository,
    ): Pair<List<Category>, ResultStatus> {
        val categoryList = mutableListOf<Category>()
        val result = handleNetworkResult {
            val playResponse = appSources.gplayRepo.getCategories(type).map { gplayCategory ->
            val playResponse = playStoreRepository.getCategories(type).map { gplayCategory ->
                val category = gplayCategory.toCategory()
                category.drawable =
                    CategoryUtils.provideAppsCategoryIconResource(
@@ -107,28 +116,21 @@ class CategoryApiImpl @Inject constructor(

    private suspend fun fetchCleanApkCategories(
        type: CategoryType,
        source: Source
        source: Source,
        repository: CleanApkRepository
    ): Pair<List<Category>, ResultStatus> {
        val categoryList = mutableListOf<Category>()
        var tag: AppTag? = null

        val result = handleNetworkResult {
            val categories = when (source) {
                Source.OPEN_SOURCE -> {
                    tag = AppTag.OpenSource(context.getString(R.string.open_source))
                    appSources.cleanApkAppsRepo.getCategories().body()
                }

                Source.PWA -> {
                    tag = AppTag.PWA(context.getString(R.string.pwa))
                    appSources.cleanApkPWARepo.getCategories().body()
                }

            val tag = when (source) {
                Source.OPEN_SOURCE -> AppTag.OpenSource(context.getString(R.string.open_source))
                Source.PWA -> AppTag.PWA(context.getString(R.string.pwa))
                else -> null
            }

            categories?.let {
                categoryList.addAll(getFusedCategoryBasedOnCategoryType(it, type, tag!!))
            val categories = repository.getCategories().body()

            if (categories != null && tag != null) {
                categoryList.addAll(getFusedCategoryBasedOnCategoryType(categories, type, tag))
            }
        }

+32 −19
Original line number Diff line number Diff line
@@ -18,15 +18,16 @@

package foundation.e.apps.data.application.downloadInfo

import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.Stores
import foundation.e.apps.data.cleanapk.CleanApkDownloadInfoFetcher
import foundation.e.apps.data.enums.Source
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.handleNetworkResult
import foundation.e.apps.data.install.models.AppInstall
import foundation.e.apps.data.playstore.PlayStoreRepository
import javax.inject.Inject

class DownloadInfoApiImpl @Inject constructor(
    private val appSources: AppSourcesContainer
    private val stores: Stores
) : DownloadInfoApi {

    override suspend fun getOnDemandModule(
@@ -35,8 +36,11 @@ class DownloadInfoApiImpl @Inject constructor(
        versionCode: Long,
        offerType: Int
    ): String? {
        val playStoreRepository = stores.getStore(Source.PLAY_STORE) as? PlayStoreRepository
            ?: return null

        val result = handleNetworkResult {
            appSources.gplayRepo.getOnDemandModule(
            playStoreRepository.getOnDemandModule(
                packageName,
                moduleName,
                versionCode,
@@ -44,15 +48,8 @@ class DownloadInfoApiImpl @Inject constructor(
            )
        }

        if (result.isSuccess()) {
            for (element in result.data!!) { // isSuccess() checks ensures null safety of data
                if (element.name == "$moduleName.apk") {
                    return element.url
                }
            }
        }

        return null
        val moduleFile = result.data?.firstOrNull { it.name == "$moduleName.apk" }
        return moduleFile?.url
    }

    override suspend fun updateFusedDownloadWithDownloadingInfo(
@@ -86,7 +83,7 @@ class DownloadInfoApiImpl @Inject constructor(
        list: MutableList<String>
    ) {
        val downloadList =
            appSources.gplayRepo.getDownloadInfo(
            getPlayStoreRepositoryOrThrow().getDownloadInfo(
                appInstall.packageName,
                appInstall.versionCode,
                appInstall.offerType
@@ -99,14 +96,30 @@ class DownloadInfoApiImpl @Inject constructor(
        appInstall: AppInstall,
        list: MutableList<String>
    ) {
        val downloadInfo =
            (appSources.cleanApkAppsRepo as CleanApkDownloadInfoFetcher)
                .getDownloadInfo(appInstall.id).body()
        val downloadInfoFetcher = getCleanApkDownloadInfoFetcherOrNull() ?: return
        val downloadInfo = downloadInfoFetcher.getDownloadInfo(appInstall.id).body()
        downloadInfo?.download_data?.download_link?.let { list.add(it) }
        appInstall.signature = downloadInfo?.download_data?.signature ?: ""
    }

    override suspend fun getOSSDownloadInfo(id: String, version: String?) =
        (appSources.cleanApkAppsRepo as CleanApkDownloadInfoFetcher)
        getCleanApkDownloadInfoFetcherOrThrow()
            .getDownloadInfo(id, version)

    private fun getPlayStoreRepositoryOrThrow(): PlayStoreRepository =
        stores.getStore(Source.PLAY_STORE) as? PlayStoreRepository
            ?: error("Play Store repository is not available.")

    private fun getCleanApkDownloadInfoFetcherOrNull(): CleanApkDownloadInfoFetcher? {
        val openSourceFetcher =
            stores.getStore(Source.OPEN_SOURCE) as? CleanApkDownloadInfoFetcher
        if (openSourceFetcher != null) {
            return openSourceFetcher
        }
        return stores.getStore(Source.PWA) as? CleanApkDownloadInfoFetcher
    }

    private fun getCleanApkDownloadInfoFetcherOrThrow(): CleanApkDownloadInfoFetcher =
        getCleanApkDownloadInfoFetcherOrNull()
            ?: error("CleanApk download repository is not available.")
}
+0 −4
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.content.Context
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.aurora.gplayapi.data.models.Category
import foundation.e.apps.R
import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.StoreDescriptor
import foundation.e.apps.data.StoreRepository
import foundation.e.apps.data.Stores
@@ -109,11 +108,8 @@ class CategoryApiTest {
            )
        )

        val appSourcesContainer =
            AppSourcesContainer(playStoreRepository, cleanApkAppsRepository, cleanApkPWARepository)
        categoryApi = CategoryApiImpl(
            context,
            appSourcesContainer,
            fakeStores,
            applicationDataManager
        )
+0 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.text.format.Formatter
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.aurora.gplayapi.data.models.App
import foundation.e.apps.FakeAppLoungePreference
import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.Stores
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.apps.AppsApi
@@ -113,8 +112,6 @@ class SearchRepositoryImplTest {
        preferenceManagerModule = FakeAppLoungePreference(context, appLoungeDataStore)
        applicationDataManager =
            ApplicationDataManager(appLoungePackageManager, pwaManager, visibilityFetcher)
        val appSourcesContainer =
            AppSourcesContainer(playStoreRepository, cleanApkAppsRepository, cleanApkPWARepository)
        appsApi = AppsApiImpl(
            stores,
            applicationDataManager,