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

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

DowloadInfoApi & searchapi are introduced

parent 3748e5a8
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -38,10 +38,11 @@ import javax.inject.Singleton

@Singleton
class ApplicationRepository @Inject constructor(
    private val applicationAPIImpl: ApplicationApi,
    private val searchAPIImpl: SearchApi,
    private val homeApi: HomeApi,
    private val categoryApi: CategoryApi,
    private val appsApi: AppsApi,
    private val downloadInfoApi: DownloadInfoApi
) {

    suspend fun getHomeScreenData(authData: AuthData): LiveData<ResultSupreme<List<Home>>> {
@@ -49,7 +50,7 @@ class ApplicationRepository @Inject constructor(
    }

    fun getApplicationCategoryPreference(): List<String> {
        return applicationAPIImpl.getApplicationCategoryPreference()
        return searchAPIImpl.getApplicationCategoryPreference()
    }

    suspend fun getApplicationDetails(
@@ -81,14 +82,14 @@ class ApplicationRepository @Inject constructor(
        origin: Origin,
        fusedDownload: FusedDownload
    ) {
        applicationAPIImpl.updateFusedDownloadWithDownloadingInfo(
        downloadInfoApi.updateFusedDownloadWithDownloadingInfo(
            origin,
            fusedDownload
        )
    }

    suspend fun getOSSDownloadInfo(id: String, version: String? = null) =
        applicationAPIImpl.getOSSDownloadInfo(id, version)
        downloadInfoApi.getOSSDownloadInfo(id, version)

    suspend fun getOnDemandModule(
        packageName: String,
@@ -96,7 +97,7 @@ class ApplicationRepository @Inject constructor(
        versionCode: Int,
        offerType: Int
    ): String? {
        return applicationAPIImpl.getOnDemandModule(packageName, moduleName, versionCode, offerType)
        return downloadInfoApi.getOnDemandModule(packageName, moduleName, versionCode, offerType)
    }

    suspend fun getCategoriesList(
@@ -106,21 +107,21 @@ class ApplicationRepository @Inject constructor(
    }

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

    suspend fun getCleanApkSearchResults(
        query: String,
        authData: AuthData
    ): ResultSupreme<Pair<List<Application>, Boolean>> {
        return applicationAPIImpl.getCleanApkSearchResults(query, authData)
        return searchAPIImpl.getCleanApkSearchResults(query, authData)
    }

    suspend fun getGplaySearchResults(
        query: String,
        nextPageSubBundle: Set<SearchBundle.SubBundle>?
    ): GplaySearchResult {
        return applicationAPIImpl.getGplaySearchResult(query, nextPageSubBundle)
        return searchAPIImpl.getGplaySearchResult(query, nextPageSubBundle)
    }

    suspend fun getAppsListBasedOnCategory(
+23 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.application

import foundation.e.apps.data.cleanapk.data.download.Download
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import retrofit2.Response

interface DownloadInfoApi {

    suspend fun getOnDemandModule(
        packageName: String,
        moduleName: String,
        versionCode: Int,
        offerType: Int
    ): String?

    suspend fun updateFusedDownloadWithDownloadingInfo(
        origin: Origin,
        fusedDownload: FusedDownload
    )

    suspend fun getOSSDownloadInfo(id: String, version: String?): Response<Download>
}
+68 −0
Original line number Diff line number Diff line
package foundation.e.apps.data.application

import foundation.e.apps.data.cleanapk.CleanApkDownloadInfoFetcher
import foundation.e.apps.data.cleanapk.repositories.CleanApkRepository
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import foundation.e.apps.data.playstore.PlayStoreRepository
import javax.inject.Inject
import javax.inject.Named

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

    override suspend fun getOnDemandModule(
        packageName: String,
        moduleName: String,
        versionCode: Int,
        offerType: Int
    ): String? {
        val list = gplayRepository.getOnDemandModule(
            packageName,
            moduleName,
            versionCode,
            offerType,
        )
        for (element in list) {
            if (element.name == "$moduleName.apk") {
                return element.url
            }
        }
        return null
    }

    override suspend fun updateFusedDownloadWithDownloadingInfo(
        origin: Origin,
        fusedDownload: FusedDownload
    ) {
        val list = mutableListOf<String>()
        when (origin) {
            Origin.CLEANAPK -> {
                val downloadInfo =
                    (cleanApkAppsRepository as CleanApkDownloadInfoFetcher).getDownloadInfo(
                        fusedDownload.id
                    )
                        .body()
                downloadInfo?.download_data?.download_link?.let { list.add(it) }
                fusedDownload.signature = downloadInfo?.download_data?.signature ?: ""
            }

            Origin.GPLAY -> {
                val downloadList =
                    gplayRepository.getDownloadInfo(
                        fusedDownload.packageName,
                        fusedDownload.versionCode,
                        fusedDownload.offerType
                    )
                fusedDownload.files = downloadList
                list.addAll(downloadList.map { it.url })
            }
        }
        fusedDownload.downloadURLList = list
    }

    override suspend fun getOSSDownloadInfo(id: String, version: String?) =
        (cleanApkAppsRepository as CleanApkDownloadInfoFetcher).getDownloadInfo(id, version)
}
 No newline at end of file
+6 −6
Original line number Diff line number Diff line
@@ -115,19 +115,19 @@ class HomeApiImpl @Inject constructor(
            }

            Source.OPEN -> handleNetworkResult {
                handleCleanApkHomes(priorList, ApplicationApi.APP_TYPE_OPEN)
                handleCleanApkHomes(priorList, SearchApi.APP_TYPE_OPEN)
            }

            Source.PWA -> handleNetworkResult {
                handleCleanApkHomes(priorList, ApplicationApi.APP_TYPE_PWA)
                handleCleanApkHomes(priorList, SearchApi.APP_TYPE_PWA)
            }
        }

        setHomeErrorMessage(result.getResultStatus(), source)
        priorList.sortBy {
            when (it.source) {
                ApplicationApi.APP_TYPE_OPEN -> AppSourceWeight.OPEN_SOURCE.ordinal
                ApplicationApi.APP_TYPE_PWA -> AppSourceWeight.PWA.ordinal
                SearchApi.APP_TYPE_OPEN -> AppSourceWeight.OPEN_SOURCE.ordinal
                SearchApi.APP_TYPE_PWA -> AppSourceWeight.PWA.ordinal
                else -> AppSourceWeight.GPLAY.ordinal
            }
        }
@@ -139,7 +139,7 @@ class HomeApiImpl @Inject constructor(
        priorList: MutableList<Home>,
        appType: String
    ): MutableList<Home> {
        val response = if (appType == ApplicationApi.APP_TYPE_OPEN) {
        val response = if (appType == SearchApi.APP_TYPE_OPEN) {
            (cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
        } else {
            (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
@@ -154,7 +154,7 @@ class HomeApiImpl @Inject constructor(

    private suspend fun generateCleanAPKHome(home: CleanApkHome, appType: String): List<Home> {
        val list = mutableListOf<Home>()
        val headings = if (appType == ApplicationApi.APP_TYPE_OPEN) {
        val headings = if (appType == SearchApi.APP_TYPE_OPEN) {
            getOpenSourceHomeCategories()
        } else {
            getPWAHomeCategories()
+1 −28
Original line number Diff line number Diff line
package foundation.e.apps.data.application

import androidx.lifecycle.LiveData
import com.aurora.gplayapi.SearchSuggestEntry
import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.models.SearchBundle
import foundation.e.apps.data.ResultSupreme
import foundation.e.apps.data.cleanapk.data.download.Download
import foundation.e.apps.data.enums.FilterLevel
import foundation.e.apps.data.enums.Origin
import foundation.e.apps.data.enums.ResultStatus
import foundation.e.apps.data.enums.Status
import foundation.e.apps.data.application.data.Application
import foundation.e.apps.data.application.data.Category
import foundation.e.apps.data.application.data.Home
import foundation.e.apps.data.application.utils.CategoryType
import foundation.e.apps.data.fusedDownload.models.FusedDownload
import retrofit2.Response

typealias GplaySearchResult = ResultSupreme<Pair<List<Application>, Set<SearchBundle.SubBundle>>>

interface ApplicationApi {
interface SearchApi {
    companion object {
        const val APP_TYPE_ANY = "any"
        const val APP_TYPE_OPEN = "open"
@@ -47,19 +35,4 @@ interface ApplicationApi {
    ): GplaySearchResult

    suspend fun getSearchSuggestions(query: String): List<SearchSuggestEntry>

    suspend fun getOnDemandModule(
        packageName: String,
        moduleName: String,
        versionCode: Int,
        offerType: Int
    ): String?

    suspend fun updateFusedDownloadWithDownloadingInfo(
        origin: Origin,
        fusedDownload: FusedDownload
    )

    suspend fun getOSSDownloadInfo(id: String, version: String?): Response<Download>

}
Loading