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

Commit 384a1888 authored by Hasib Prince's avatar Hasib Prince
Browse files

added dependency container for app sources

parent efc577d1
Loading
Loading
Loading
Loading
Loading
+33 −0
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.CleanApkRepository
import foundation.e.apps.data.playstore.PlayStoreRepository
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

@Singleton
class AppSourcesContainer @Inject constructor(
    @Named("gplayRepository") val gplayRepository: PlayStoreRepository,
    @Named("cleanApkAppsRepository") val cleanApkAppsRepository: CleanApkRepository,
    @Named("cleanApkPWARepository") val cleanApkPWARepository: CleanApkRepository
)
+10 −9
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context
import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.cleanapk.data.app.Application as CleanApkApplication
@@ -44,8 +45,7 @@ import javax.inject.Named
class AppsApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    private val appLoungePreference: AppLoungePreference,
    @Named("gplayRepository") private val gplayRepository: PlayStoreRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: CleanApkRepository,
    private val appSourcesContainer: AppSourcesContainer,
    private val applicationDataManager: ApplicationDataManager
) : AppsApi {

@@ -56,15 +56,15 @@ class AppsApiImpl @Inject constructor(
    override suspend fun getCleanapkAppDetails(packageName: String): Pair<Application, ResultStatus> {
        var application = Application()
        val result = handleNetworkResult {
            val result = cleanApkAppsRepository.getSearchResult(
            val result = appSourcesContainer.cleanApkAppsRepository.getSearchResult(
                packageName,
                KEY_SEARCH_PACKAGE_NAME
            ).body()

            if (result?.hasSingleResult() == true) {
                application =
                    (cleanApkAppsRepository.getAppDetails(result.apps[0]._id) as Response<CleanApkApplication>)
                        .body()?.app ?: Application()
                    (appSourcesContainer.cleanApkAppsRepository.getAppDetails(result.apps[0]._id)
                            as Response<CleanApkApplication>).body()?.app ?: Application()
            }

            application.updateFilterLevel(null)
@@ -135,7 +135,7 @@ class AppsApiImpl @Inject constructor(
        val applicationList = mutableListOf<Application>()

        val result = handleNetworkResult {
            gplayRepository.getAppsDetails(packageNameList).forEach { app ->
            appSourcesContainer.gplayRepository.getAppsDetails(packageNameList).forEach { app ->
                handleFilteredApps(app, authData, applicationList)
            }
        }
@@ -168,7 +168,7 @@ class AppsApiImpl @Inject constructor(
        packageName: String,
        applicationList: MutableList<Application>
    ) = handleNetworkResult {
        cleanApkAppsRepository.getSearchResult(
        appSourcesContainer.cleanApkAppsRepository.getSearchResult(
            packageName,
            KEY_SEARCH_PACKAGE_NAME
        ).body()?.run {
@@ -201,9 +201,10 @@ class AppsApiImpl @Inject constructor(

        val result = handleNetworkResult {
            application = if (origin == Origin.CLEANAPK) {
                (cleanApkAppsRepository.getAppDetails(id) as Response<CleanApkApplication>).body()?.app
                (appSourcesContainer.cleanApkAppsRepository.getAppDetails(id)
                        as Response<CleanApkApplication>).body()?.app
            } else {
                val app = gplayRepository.getAppDetails(packageName) as App?
                val app = appSourcesContainer.gplayRepository.getAppDetails(packageName) as App?
                app?.toApplication(context)
            }

+8 −9
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.models.StreamCluster
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.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Application
@@ -47,9 +48,7 @@ import javax.inject.Named
class CategoryApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    private val appLoungePreference: AppLoungePreference,
    @Named("gplayRepository") private val gplayRepository: PlayStoreRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: CleanApkRepository,
    @Named("cleanApkPWARepository") private val cleanApkPWARepository: CleanApkRepository,
    private val appSourcesContainer: AppSourcesContainer,
    private val applicationDataManager: ApplicationDataManager
) : CategoryApi {

@@ -113,7 +112,7 @@ class CategoryApiImpl @Inject constructor(
    ): Pair<List<Category>, ResultStatus> {
        val categoryList = mutableListOf<Category>()
        val result = handleNetworkResult {
            val playResponse = gplayRepository.getCategories(type).map { gplayCategory ->
            val playResponse = appSourcesContainer.gplayRepository.getCategories(type).map { gplayCategory ->
                val category = gplayCategory.toCategory()
                category.drawable =
                    CategoryUtils.provideAppsCategoryIconResource(
@@ -140,12 +139,12 @@ class CategoryApiImpl @Inject constructor(
            val categories = when (source) {
                Source.OPEN -> {
                    tag = AppTag.OpenSource(context.getString(R.string.open_source))
                    cleanApkAppsRepository.getCategories().body()
                    appSourcesContainer.cleanApkAppsRepository.getCategories().body()
                }

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

                else -> null
@@ -185,7 +184,7 @@ class CategoryApiImpl @Inject constructor(

        return handleNetworkResult {
            val streamCluster =
                gplayRepository.getAppsByCategory(category, pageUrl) as StreamCluster
                appSourcesContainer.gplayRepository.getAppsByCategory(category, pageUrl) as StreamCluster

            val filteredAppList = filterRestrictedGPlayApps(authData, streamCluster.clusterAppList)
            filteredAppList.data?.let {
@@ -258,11 +257,11 @@ class CategoryApiImpl @Inject constructor(
        category: String
    ) = when (source) {
        Source.OPEN -> {
            cleanApkAppsRepository.getAppsByCategory(category).body()
            appSourcesContainer.cleanApkAppsRepository.getAppsByCategory(category).body()
        }

        Source.PWA -> {
            cleanApkPWARepository.getAppsByCategory(category).body()
            appSourcesContainer.cleanApkPWARepository.getAppsByCategory(category).body()
        }

        else -> null
+8 −8
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

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

import foundation.e.apps.data.AppSourcesContainer
import foundation.e.apps.data.cleanapk.CleanApkDownloadInfoFetcher
import foundation.e.apps.data.cleanapk.repositories.CleanApkRepository
import foundation.e.apps.data.enums.Origin
@@ -27,8 +28,7 @@ import javax.inject.Inject
import javax.inject.Named

class DownloadInfoApiImpl @Inject constructor(
    @Named("gplayRepository") private val gplayRepository: PlayStoreRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: CleanApkRepository
    private val appSourcesContainer: AppSourcesContainer
) : DownloadInfoApi {

    override suspend fun getOnDemandModule(
@@ -37,7 +37,7 @@ class DownloadInfoApiImpl @Inject constructor(
        versionCode: Int,
        offerType: Int
    ): String? {
        val list = gplayRepository.getOnDemandModule(
        val list = appSourcesContainer.gplayRepository.getOnDemandModule(
            packageName,
            moduleName,
            versionCode,
@@ -76,7 +76,7 @@ class DownloadInfoApiImpl @Inject constructor(
        list: MutableList<String>
    ) {
        val downloadList =
            gplayRepository.getDownloadInfo(
            appSourcesContainer.gplayRepository.getDownloadInfo(
                fusedDownload.packageName,
                fusedDownload.versionCode,
                fusedDownload.offerType
@@ -90,13 +90,13 @@ class DownloadInfoApiImpl @Inject constructor(
        list: MutableList<String>
    ) {
        val downloadInfo =
            (cleanApkAppsRepository as CleanApkDownloadInfoFetcher).getDownloadInfo(
                fusedDownload.id
            ).body()
            (appSourcesContainer.cleanApkAppsRepository as CleanApkDownloadInfoFetcher)
                .getDownloadInfo(fusedDownload.id).body()
        downloadInfo?.download_data?.download_link?.let { list.add(it) }
        fusedDownload.signature = downloadInfo?.download_data?.signature ?: ""
    }

    override suspend fun getOSSDownloadInfo(id: String, version: String?) =
        (cleanApkAppsRepository as CleanApkDownloadInfoFetcher).getDownloadInfo(id, version)
        (appSourcesContainer.cleanApkAppsRepository as CleanApkDownloadInfoFetcher)
            .getDownloadInfo(id, version)
}
+16 −8
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
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.application.ApplicationDataManager
import foundation.e.apps.data.application.data.Home
@@ -54,9 +55,7 @@ import foundation.e.apps.data.cleanapk.data.home.Home as CleanApkHome
class HomeApiImpl @Inject constructor(
    @ApplicationContext private val context: Context,
    private val appLoungePreference: AppLoungePreference,
    @Named("gplayRepository") private val gplayRepository: PlayStoreRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: CleanApkRepository,
    @Named("cleanApkPWARepository") private val cleanApkPWARepository: CleanApkRepository,
    private val appSourcesContainer: AppSourcesContainer,
    private val applicationDataManager: ApplicationDataManager
) : HomeApi {

@@ -143,9 +142,9 @@ class HomeApiImpl @Inject constructor(
        appType: String
    ): MutableList<Home> {
        val response = if (appType == SearchApi.APP_TYPE_OPEN) {
            (cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
            (appSourcesContainer.cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
        } else {
            (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
            (appSourcesContainer.cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
        }

        response?.home?.let {
@@ -182,11 +181,19 @@ class HomeApiImpl @Inject constructor(
                }

                "popular_apps_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(home.popular_apps_in_last_24_hours, list, value)
                    applicationDataManager.prepareApps(
                        home.popular_apps_in_last_24_hours,
                        list,
                        value
                    )
                }

                "popular_games_in_last_24_hours" -> {
                    applicationDataManager.prepareApps(home.popular_games_in_last_24_hours, list, value)
                    applicationDataManager.prepareApps(
                        home.popular_games_in_last_24_hours,
                        list,
                        value
                    )
                }

                "discover" -> {
@@ -230,7 +237,8 @@ class HomeApiImpl @Inject constructor(
        priorList: MutableList<Home>
    ): List<Home> {
        val list = mutableListOf<Home>()
        val gplayHomeData = gplayRepository.getHomeScreenData() as Map<String, List<App>>
        val gplayHomeData =
            appSourcesContainer.gplayRepository.getHomeScreenData() as Map<String, List<App>>
        gplayHomeData.map {
            val fusedApps = it.value.map { app ->
                app.toApplication(context).apply {
Loading