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

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

Merge branch 'epic59-refactoring_store_api' into 'main'

Epic59 refactoring store api

See merge request !301
parents 38c18ce0 37550ab8
Loading
Loading
Loading
Loading
Loading
+24 −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 BaseStoreRepository {
    suspend fun getHomeScreenData(): Any
    suspend fun getAppDetails(packageNameOrId: String): Any?
}
+16 −16
Original line number Diff line number Diff line
@@ -29,15 +29,15 @@ import javax.inject.Inject

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

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

    suspend fun getAppOrPWADetailsByID(
@@ -45,28 +45,28 @@ class CleanAPKRepository @Inject constructor(
        architectures: List<String>? = null,
        type: String? = null
    ): Response<Application> {
        return cleanApkAppDetailApi.getAppOrPWADetailsByID(id, architectures, type)
        return cleanApkAppDetailsRetrofit.getAppOrPWADetailsByID(id, architectures, type)
    }

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

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

    suspend fun getDownloadInfo(
@@ -74,13 +74,13 @@ class CleanAPKRepository @Inject constructor(
        version: String? = null,
        architecture: String? = null
    ): Response<Download> {
        return cleanAPKInterface.getDownloadInfo(id, version, architecture)
        return cleanAPKRetrofit.getDownloadInfo(id, version, architecture)
    }

    suspend fun getCategoriesList(
        type: String = CleanAPKInterface.APP_TYPE_ANY,
        source: String = CleanAPKInterface.APP_SOURCE_ANY
        type: String = CleanApkRetrofit.APP_TYPE_ANY,
        source: String = CleanApkRetrofit.APP_SOURCE_ANY
    ): Response<Categories> {
        return cleanAPKInterface.getCategoriesList(type, source)
        return cleanAPKRetrofit.getCategoriesList(type, source)
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query

interface CleanApkAppDetailApi {
interface CleanApkAppDetailsRetrofit {

    companion object {
        // API endpoints
+79 −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.cleanapk

import foundation.e.apps.api.cleanapk.data.app.Application
import foundation.e.apps.api.cleanapk.data.categories.Categories
import foundation.e.apps.api.cleanapk.data.download.Download
import foundation.e.apps.api.cleanapk.data.home.HomeScreen
import foundation.e.apps.api.cleanapk.data.search.Search
import retrofit2.Response

class CleanApkAppsRepositoryImpl(
    private val cleanApkRetrofit: CleanApkRetrofit,
    private val cleanApkAppDetailsRetrofit: CleanApkAppDetailsRetrofit
) : CleanApkRepository, CleanApkDownloadInfoFetcher {

    override suspend fun getHomeScreenData(): Response<HomeScreen> {
        return cleanApkRetrofit.getHomeScreenData(
            CleanApkRetrofit.APP_TYPE_ANY,
            CleanApkRetrofit.APP_SOURCE_FOSS
        )
    }

    override suspend fun getSearchResult(query: String, searchBy: String?): Response<Search> {
        return cleanApkRetrofit.searchApps(
            query,
            CleanApkRetrofit.APP_SOURCE_FOSS,
            CleanApkRetrofit.APP_TYPE_ANY,
            NUMBER_OF_ITEMS,
            NUMBER_OF_PAGES,
            searchBy
        )
    }

    override suspend fun getAppsByCategory(
        category: String,
        paginationParameter: Any?
    ): Response<Search> {
        return cleanApkRetrofit.listApps(
            category,
            CleanApkRetrofit.APP_SOURCE_FOSS,
            CleanApkRetrofit.APP_TYPE_ANY,
            NUMBER_OF_ITEMS,
            NUMBER_OF_PAGES
        )
    }

    override suspend fun getCategories(): Response<Categories> {
        return cleanApkRetrofit.getCategoriesList(
            CleanApkRetrofit.APP_TYPE_ANY,
            CleanApkRetrofit.APP_SOURCE_FOSS
        )
    }

    override suspend fun getAppDetails(packageNameOrId: String): Response<Application> {
        return cleanApkAppDetailsRetrofit.getAppOrPWADetailsByID(packageNameOrId, null, null)
    }

    override suspend fun getDownloadInfo(idOrPackageName: String, versionCode: Any?): Response<Download> {
        val version = versionCode?.let { it as String }
        return cleanApkRetrofit.getDownloadInfo(idOrPackageName, version, null)
    }
}
+26 −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.cleanapk

import foundation.e.apps.api.cleanapk.data.download.Download
import retrofit2.Response

interface CleanApkDownloadInfoFetcher {
    suspend fun getDownloadInfo(idOrPackageName: String, versionCode: Any? = null): Response<Download>
}
Loading