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

Commit 85d7b68a authored by Hasib Prince's avatar Hasib Prince
Browse files

Merge branch '1390-code_cleanup' into 'main'

1390 code cleanup

See merge request !326
parents 42c77888 9fb0dc81
Loading
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -35,12 +35,4 @@ data class Result<T>(val status: Status, val data: T?, val message: String?) {
    }

    fun isSuccess() = status == Status.SUCCESS

    fun handleResult(handler: () -> Unit, defaultErrorData: T?): T? {
        if (isSuccess()) {
            handler()
            return data ?: defaultErrorData
        }
        return defaultErrorData
    }
}
+0 −5
Original line number Diff line number Diff line
@@ -27,11 +27,6 @@ import retrofit2.http.Query

interface CleanApkAppDetailsRetrofit {

    companion object {
        // API endpoints
        const val BASE_URL = "https://api.cleanapk.org/v2/"
    }

    @GET("apps?action=app_detail")
    suspend fun getAppOrPWADetailsByID(
        @Query("id") id: String,
+0 −88
Original line number Diff line number Diff line
/*
 * Apps  Quickly and easily install Android apps onto your device!
 * Copyright (C) 2021  E FOUNDATION
 *
 * 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.cleanapk.repositories

import foundation.e.apps.OpenForTesting
import foundation.e.apps.data.cleanapk.CleanApkAppDetailsRetrofit
import foundation.e.apps.data.cleanapk.CleanApkRetrofit
import foundation.e.apps.data.cleanapk.data.app.Application
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.data.download.Download
import foundation.e.apps.data.cleanapk.data.home.HomeScreen
import foundation.e.apps.data.cleanapk.data.search.Search
import retrofit2.Response
import javax.inject.Inject

@OpenForTesting
class CleanAPKRepository @Inject constructor(
    private val cleanAPKRetrofit: CleanApkRetrofit,
    private val cleanApkAppDetailsRetrofit: CleanApkAppDetailsRetrofit
) {

    suspend fun getHomeScreenData(
        type: String = CleanApkRetrofit.APP_TYPE_ANY,
        source: String = CleanApkRetrofit.APP_SOURCE_ANY
    ): Response<HomeScreen> {
        return cleanAPKRetrofit.getHomeScreenData(type, source)
    }

    suspend fun getAppOrPWADetailsByID(
        id: String,
        architectures: List<String>? = null,
        type: String? = null
    ): Response<Application> {
        return cleanApkAppDetailsRetrofit.getAppOrPWADetailsByID(id, architectures, type)
    }

    suspend fun searchApps(
        keyword: String,
        source: String = CleanApkRetrofit.APP_SOURCE_FOSS,
        type: String = CleanApkRetrofit.APP_TYPE_ANY,
        nres: Int = 20,
        page: Int = 1,
        by: String? = null
    ): Response<Search> {
        return cleanAPKRetrofit.searchApps(keyword, source, type, nres, page, by)
    }

    suspend fun listApps(
        category: String,
        source: String = CleanApkRetrofit.APP_SOURCE_FOSS,
        type: String = CleanApkRetrofit.APP_TYPE_ANY,
        nres: Int = 20,
        page: Int = 1,
    ): Response<Search> {
        return cleanAPKRetrofit.listApps(category, source, type, nres, page)
    }

    suspend fun getDownloadInfo(
        id: String,
        version: String? = null,
        architecture: String? = null
    ): Response<Download> {
        return cleanAPKRetrofit.getDownloadInfo(id, version, architecture)
    }

    suspend fun getCategoriesList(
        type: String = CleanApkRetrofit.APP_TYPE_ANY,
        source: String = CleanApkRetrofit.APP_SOURCE_ANY
    ): Response<Categories> {
        return cleanAPKRetrofit.getCategoriesList(type, source)
    }
}
+0 −6
Original line number Diff line number Diff line
@@ -2,12 +2,6 @@ package foundation.e.apps.data.exodus

import com.squareup.moshi.Json

data class TrackerInfo(
    val name: String,
    val creator: String,
    val reports: List<Report>
)

data class Report(
    val report: Long = -1L,
    @Json(name = "updated") val updatedAt: String,
+19 −19
Original line number Diff line number Diff line
@@ -164,11 +164,11 @@ class FusedApiImpl @Inject constructor(
    ): ResultSupreme<List<FusedHome>> {

        val apiStatus = when (source) {
            Source.GPLAY -> runCodeBlockWithTimeout({
            Source.GPLAY -> runCodeWithTimeout({
                priorList.addAll(fetchGPlayHome(authData))
            })

            Source.OPEN -> runCodeBlockWithTimeout({
            Source.OPEN -> runCodeWithTimeout({
                val response =
                    (cleanApkAppsRepository.getHomeScreenData() as Response<HomeScreen>).body()
                response?.home?.let {
@@ -176,7 +176,7 @@ class FusedApiImpl @Inject constructor(
                }
            })

            Source.PWA -> runCodeBlockWithTimeout({
            Source.PWA -> runCodeWithTimeout({
                val response =
                    (cleanApkPWARepository.getHomeScreenData() as Response<HomeScreen>).body()
                response?.home?.let {
@@ -302,7 +302,7 @@ class FusedApiImpl @Inject constructor(
        packageSpecificResults: ArrayList<FusedApp>
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>> {
        val pwaApps: MutableList<FusedApp> = mutableListOf()
        val status = fusedAPIImpl.runCodeBlockWithTimeout({
        val status = fusedAPIImpl.runCodeWithTimeout({
            val apps =
                cleanApkPWARepository.getSearchResult(query).body()?.apps
            apps?.apply {
@@ -356,7 +356,7 @@ class FusedApiImpl @Inject constructor(
        searchResult: MutableList<FusedApp>,
        packageSpecificResults: ArrayList<FusedApp>
    ): ResultSupreme<Pair<List<FusedApp>, Boolean>> {
        val status = fusedAPIImpl.runCodeBlockWithTimeout({
        val status = fusedAPIImpl.runCodeWithTimeout({
            cleanApkResults.addAll(getCleanAPKSearchResults(query))
        })

@@ -385,7 +385,7 @@ class FusedApiImpl @Inject constructor(
        var gplayPackageResult: FusedApp? = null
        var cleanapkPackageResult: FusedApp? = null

        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            if (preferenceManagerModule.isGplaySelected()) {
                gplayPackageResult = getGplayPackagResult(query, authData)
            }
@@ -469,7 +469,7 @@ class FusedApiImpl @Inject constructor(
     */
    private suspend fun getCleanapkSearchResult(packageName: String): ResultSupreme<FusedApp> {
        var fusedApp = FusedApp()
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            val result = cleanApkAppsRepository.getSearchResult(
                packageName,
                "package_name"
@@ -544,7 +544,7 @@ class FusedApiImpl @Inject constructor(

    override suspend fun getPWAApps(category: String): ResultSupreme<Pair<List<FusedApp>, String>> {
        val list = mutableListOf<FusedApp>()
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            val response = getPWAAppsResponse(category)
            response?.apps?.forEach {
                it.updateStatus()
@@ -558,7 +558,7 @@ class FusedApiImpl @Inject constructor(

    override suspend fun getOpenSourceApps(category: String): ResultSupreme<Pair<List<FusedApp>, String>> {
        val list = mutableListOf<FusedApp>()
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            val response = getOpenSourceAppsResponse(category)
            response?.apps?.forEach {
                it.updateStatus()
@@ -578,7 +578,7 @@ class FusedApiImpl @Inject constructor(
     */
    override suspend fun getCleanapkAppDetails(packageName: String): Pair<FusedApp, ResultStatus> {
        var fusedApp = FusedApp()
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            val result = cleanApkAppsRepository.getSearchResult(
                packageName,
                "package_name"
@@ -635,7 +635,7 @@ class FusedApiImpl @Inject constructor(
         * i.e. check timeout for individual package query.
         */
        for (packageName in packageNameList) {
            status = runCodeBlockWithTimeout({
            status = runCodeWithTimeout({
                cleanApkAppsRepository.getSearchResult(
                    packageName,
                    "package_name"
@@ -674,7 +674,7 @@ class FusedApiImpl @Inject constructor(
        /*
         * Old code moved from getApplicationDetails()
         */
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            gplayRepository.getAppsDetails(packageNameList).forEach { app ->
                /*
                 * Some apps are restricted to locations. Example "com.skype.m2".
@@ -712,7 +712,7 @@ class FusedApiImpl @Inject constructor(
        appList: List<App>,
    ): ResultSupreme<List<FusedApp>> {
        val filteredFusedApps = mutableListOf<FusedApp>()
        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            appList.forEach {
                val filter = getAppFilterLevel(it, authData)
                if (filter.isUnFiltered()) {
@@ -804,7 +804,7 @@ class FusedApiImpl @Inject constructor(

        var response: FusedApp? = null

        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            response = if (origin == Origin.CLEANAPK) {
                (cleanApkAppsRepository.getAppDetails(id) as Response<Application>).body()?.app
            } else {
@@ -871,7 +871,7 @@ class FusedApiImpl @Inject constructor(
        var errorApplicationCategory = ""
        var apiStatus = ResultStatus.OK
        val categoryList = mutableListOf<FusedCategory>()
        runCodeBlockWithTimeout({
        runCodeWithTimeout({
            val playResponse = gplayRepository.getCategories(type).map { app ->
                val category = app.transformToFusedCategory()
                updateCategoryDrawable(category)
@@ -894,7 +894,7 @@ class FusedApiImpl @Inject constructor(
        var errorApplicationCategory = ""
        var apiStatus: ResultStatus = ResultStatus.OK
        val fusedCategoriesList = mutableListOf<FusedCategory>()
        runCodeBlockWithTimeout({
        runCodeWithTimeout({
            getPWAsCategories()?.let {
                fusedCategoriesList.addAll(
                    getFusedCategoryBasedOnCategoryType(
@@ -918,7 +918,7 @@ class FusedApiImpl @Inject constructor(
        var errorApplicationCategory = ""
        var apiStatus: ResultStatus = ResultStatus.OK
        val fusedCategoryList = mutableListOf<FusedCategory>()
        runCodeBlockWithTimeout({
        runCodeWithTimeout({
            getOpenSourceCategories()?.let {
                fusedCategoryList.addAll(
                    getFusedCategoryBasedOnCategoryType(
@@ -947,7 +947,7 @@ class FusedApiImpl @Inject constructor(
     *
     * @return Instance of [ResultStatus] based on whether [block] was executed within timeout limit.
     */
    private suspend fun runCodeBlockWithTimeout(
    private suspend fun runCodeWithTimeout(
        block: suspend () -> Unit,
        timeoutBlock: (() -> Unit)? = null,
        exceptionBlock: ((e: Exception) -> Unit)? = null,
@@ -1414,7 +1414,7 @@ class FusedApiImpl @Inject constructor(
        var fusedAppList: MutableList<FusedApp> = mutableListOf()
        var nextPageUrl = ""

        val status = runCodeBlockWithTimeout({
        val status = runCodeWithTimeout({
            val streamCluster = gplayRepository.getAppsByCategory(category, pageUrl) as StreamCluster
            val filteredAppList = filterRestrictedGPlayApps(authData, streamCluster.clusterAppList)
            filteredAppList.data?.let {
Loading