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

Commit 9fa3bdaa authored by Hasib Prince's avatar Hasib Prince
Browse files

CleanApk repository is introduced

parent ec95bfe0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2,5 +2,5 @@ package foundation.e.apps.api

interface StoreApiRepository {
    suspend fun getHomeScreenData(): Any
    fun getSearchResult(query: String): Any
    suspend fun getSearchResult(query: String): Any
}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
package foundation.e.apps.api.cleanapk

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

class CleanApkAppsRepository(
    private val cleanAPKInterface: CleanAPKInterface,
    private val cleanApkAppDetailApi: CleanApkAppDetailApi
) : StoreApiRepository {
    override suspend fun getHomeScreenData(): Response<HomeScreen> {
        return cleanAPKInterface.getHomeScreenData(
            CleanAPKInterface.APP_TYPE_ANY,
            CleanAPKInterface.APP_SOURCE_FOSS
        )
    }

    override suspend fun getSearchResult(query: String): Any {
        return cleanAPKInterface.searchApps(
            query,
            CleanAPKInterface.APP_TYPE_ANY,
            CleanAPKInterface.APP_SOURCE_FOSS,
            20,
            1,
            null
        )
    }
}
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
package foundation.e.apps.api.cleanapk

import foundation.e.apps.api.StoreApiRepository

class CleanApkPWARepository(
    private val cleanAPKInterface: CleanAPKInterface,
    private val cleanApkAppDetailApi: CleanApkAppDetailApi
) : StoreApiRepository {
    override suspend fun getHomeScreenData(): Any {
        return cleanAPKInterface.getHomeScreenData(
            CleanAPKInterface.APP_TYPE_PWA,
            CleanAPKInterface.APP_SOURCE_ANY
        )
    }

    override suspend fun getSearchResult(query: String): Any {
        TODO("Not yet implemented")
    }
}
 No newline at end of file
+8 −10
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import foundation.e.apps.api.cleanapk.CleanAPKInterface
import foundation.e.apps.api.cleanapk.CleanAPKRepository
import foundation.e.apps.api.cleanapk.data.categories.Categories
import foundation.e.apps.api.cleanapk.data.home.Home
import foundation.e.apps.api.cleanapk.data.home.HomeScreen
import foundation.e.apps.api.cleanapk.data.search.Search
import foundation.e.apps.api.fdroid.FdroidWebInterface
import foundation.e.apps.api.fused.data.FusedApp
@@ -66,6 +67,7 @@ import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.withTimeout
import retrofit2.Response
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Named
@@ -80,6 +82,8 @@ class FusedAPIImpl @Inject constructor(
    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,
    @ApplicationContext private val context: Context
) {

@@ -156,20 +160,14 @@ class FusedAPIImpl @Inject constructor(
            })

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

            Source.PWA -> runCodeBlockWithTimeout({
                val response = cleanAPKRepository.getHomeScreenData(
                    CleanAPKInterface.APP_TYPE_PWA,
                    CleanAPKInterface.APP_SOURCE_ANY
                ).body()
                val response = (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
                response?.home?.let {
                    priorList.addAll(generateCleanAPKHome(it, APP_TYPE_PWA))
                }
@@ -318,7 +316,7 @@ class FusedAPIImpl @Inject constructor(
        )
    }

    private fun fetchGplaySearchResults(
    private suspend fun fetchGplaySearchResults(
        query: String,
        authData: AuthData,
        searchResult: MutableList<FusedApp>,
@@ -1203,7 +1201,7 @@ class FusedAPIImpl @Inject constructor(
        }
    }

    private fun getGplaySearchResult(
    private suspend fun getGplaySearchResult(
        query: String,
        authData: AuthData
    ): LiveData<Pair<List<FusedApp>, Boolean>> {
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ class GplayRepository @Inject constructor(
        return homeScreenData
    }

    override fun getSearchResult(query: String): LiveData<Pair<List<App>, Boolean>> {
    override suspend fun getSearchResult(query: String): LiveData<Pair<List<App>, Boolean>> {
        return liveData {
            withContext(Dispatchers.IO) {
                /*
Loading