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

Commit 9796ce3c authored by Hasib Prince's avatar Hasib Prince
Browse files

some refactoring

parent fa0ab8ae
Loading
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
package foundation.e.apps.api

interface StoreApiRepository {
    suspend fun getHomeScreenData(): Any
    suspend fun getSearchResult(query: String): Any
    suspend fun getSearchSuggestions(query: String): Any
}
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * 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.api

interface StoreRepository {
    suspend fun getHomeScreenData(): Any
    suspend fun getSearchResult(query: String): Any
    suspend fun getSearchSuggestions(query: String): Any
}
+21 −3
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * 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.api.cleanapk

import foundation.e.apps.api.StoreApiRepository
import foundation.e.apps.api.StoreRepository
import foundation.e.apps.api.cleanapk.data.home.HomeScreen
import foundation.e.apps.api.cleanapk.data.search.Search
import retrofit2.Response

class CleanApkAppsRepository(
    private val cleanAPKInterface: CleanAPKInterface,
    private val cleanApkAppDetailApi: CleanApkAppDetailApi
) : StoreApiRepository {
) : StoreRepository {

    override suspend fun getHomeScreenData(): Response<HomeScreen> {
        return cleanAPKInterface.getHomeScreenData(
            CleanAPKInterface.APP_TYPE_ANY,
+21 −3
Original line number Diff line number Diff line
/*
 * Copyright MURENA SAS 2023
 * 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.api.cleanapk

import foundation.e.apps.api.StoreApiRepository
import foundation.e.apps.api.StoreRepository
import foundation.e.apps.api.cleanapk.data.search.Search
import retrofit2.Response

class CleanApkPWARepository(
    private val cleanAPKInterface: CleanAPKInterface,
    private val cleanApkAppDetailApi: CleanApkAppDetailApi
) : StoreApiRepository {
) : StoreRepository {

    override suspend fun getHomeScreenData(): Any {
        return cleanAPKInterface.getHomeScreenData(
            CleanAPKInterface.APP_TYPE_PWA,
+32 −26
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ import com.aurora.gplayapi.data.models.StreamCluster
import dagger.hilt.android.qualifiers.ApplicationContext
import foundation.e.apps.R
import foundation.e.apps.api.ResultSupreme
import foundation.e.apps.api.StoreApiRepository
import foundation.e.apps.api.StoreRepository
import foundation.e.apps.api.cleanapk.CleanAPKInterface
import foundation.e.apps.api.cleanapk.CleanAPKRepository
import foundation.e.apps.api.cleanapk.data.categories.Categories
@@ -74,6 +74,8 @@ import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

typealias GplaySearchResultFlow = Flow<ResultSupreme<Pair<List<FusedApp>, Boolean>>>

@Singleton
class FusedAPIImpl @Inject constructor(
    private val cleanAPKRepository: CleanAPKRepository,
@@ -82,9 +84,9 @@ class FusedAPIImpl @Inject constructor(
    private val pwaManagerModule: PWAManagerModule,
    private val preferenceManagerModule: PreferenceManagerModule,
    private val fdroidWebInterface: FdroidWebInterface,
    @Named("gplayRepository") private val gplayRepository: StoreApiRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: StoreApiRepository,
    @Named("cleanApkPWARepository") private val cleanApkPWARepository: StoreApiRepository,
    @Named("gplayRepository") private val gplayRepository: StoreRepository,
    @Named("cleanApkAppsRepository") private val cleanApkAppsRepository: StoreRepository,
    @Named("cleanApkPWARepository") private val cleanApkPWARepository: StoreRepository,
    @ApplicationContext private val context: Context
) {

@@ -161,14 +163,16 @@ class FusedAPIImpl @Inject constructor(
            })

            Source.OPEN -> runCodeBlockWithTimeout({
                val response = (cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
                val response =
                    (cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
                response?.home?.let {
                    priorList.addAll(generateCleanAPKHome(it, APP_TYPE_OPEN))
                }
            })

            Source.PWA -> runCodeBlockWithTimeout({
                val response = (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
                val response =
                    (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
                response?.home?.let {
                    priorList.addAll(generateCleanAPKHome(it, APP_TYPE_PWA))
                }
@@ -289,7 +293,8 @@ class FusedAPIImpl @Inject constructor(
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>> {
        val pwaApps: MutableList<FusedApp> = mutableListOf()
        val status = fusedAPIImpl.runCodeBlockWithTimeout({
            val apps = (cleanApkPWARepository.getSearchResult(query,) as Response<Search>).body()?.apps
            val apps =
                (cleanApkPWARepository.getSearchResult(query) as Response<Search>).body()?.apps
            apps?.apply {
                if (this.isNotEmpty()) {
                    pwaApps.addAll(this)
@@ -319,8 +324,7 @@ class FusedAPIImpl @Inject constructor(
        authData: AuthData,
        searchResult: MutableList<FusedApp>,
        packageSpecificResults: ArrayList<FusedApp>
    ): Flow<ResultSupreme<Pair<List<FusedApp>, Boolean>>> =
        getGplaySearchResult(query, authData).map {
    ): GplaySearchResultFlow = getGplaySearchResult(query, authData).map {
        if (it.first.isNotEmpty()) {
            searchResult.addAll(it.first)
        }
@@ -1173,8 +1177,8 @@ class FusedAPIImpl @Inject constructor(
        by: String? = null
    ): List<FusedApp> {
        val list = mutableListOf<FusedApp>()
        val response = (cleanApkAppsRepository.getSearchResult(keyword) as Response<Search>).body()?.apps
//        val response = cleanAPKRepository.searchApps(keyword, source, type, nres,page, by).body()?.apps
        val response =
            (cleanApkAppsRepository.getSearchResult(keyword) as Response<Search>).body()?.apps

        response?.forEach {
            it.updateStatus()
@@ -1190,7 +1194,8 @@ class FusedAPIImpl @Inject constructor(
        query: String,
        authData: AuthData
    ): LiveData<Pair<List<FusedApp>, Boolean>> {
        val searchResults = gPlayAPIRepository.getSearchResults(query, authData, ::replaceWithFDroid)
        val searchResults =
            gPlayAPIRepository.getSearchResults(query, authData, ::replaceWithFDroid)
        return searchResults.map {
            Pair(
                it.first,
@@ -1212,6 +1217,7 @@ class FusedAPIImpl @Inject constructor(
            )
        }
    }

    /*
         * This function will replace a GPlay app with F-Droid app if exists,
         * else will show the GPlay app itself.
Loading