Loading app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt +13 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import foundation.e.apps.api.cleanapk.data.app.Application import foundation.e.apps.api.ecloud.EcloudApiInterface import foundation.e.apps.api.exodus.ExodusTrackerApi import foundation.e.apps.api.fdroid.FdroidApiInterface import foundation.e.apps.api.fdroid.FdroidWebInterface import okhttp3.Cache import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaTypeOrNull Loading Loading @@ -117,6 +118,18 @@ object RetrofitModule { .create(FdroidApiInterface::class.java) } @Singleton @Provides fun provideFdroidWebApi( okHttpClient: OkHttpClient, ): FdroidWebInterface { return Retrofit.Builder() .baseUrl(FdroidWebInterface.BASE_URL) .client(okHttpClient) .build() .create(FdroidWebInterface::class.java) } @Singleton @Provides fun provideEcloudApi(okHttpClient: OkHttpClient, moshi: Moshi): EcloudApiInterface { Loading app/src/main/java/foundation/e/apps/api/fdroid/FdroidWebInterface.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 MURENA SAS * * 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.fdroid import okhttp3.ResponseBody import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Path interface FdroidWebInterface { companion object { const val BASE_URL = "https://f-droid.org/fr/packages/" } @GET("{packageName}") suspend fun getFdroidApp(@Path("packageName") packageName: String): Response<ResponseBody> } app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +24 −2 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ 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.search.Search import foundation.e.apps.api.fdroid.FdroidWebInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.api.fused.data.FusedCategory import foundation.e.apps.api.fused.data.FusedHome Loading Loading @@ -74,6 +75,7 @@ class FusedAPIImpl @Inject constructor( private val pkgManagerModule: PkgManagerModule, private val pwaManagerModule: PWAManagerModule, private val preferenceManagerModule: PreferenceManagerModule, private val fdroidWebInterface: FdroidWebInterface, @ApplicationContext private val context: Context ) { Loading Loading @@ -1197,15 +1199,33 @@ class FusedAPIImpl @Inject constructor( query: String, authData: AuthData ): LiveData<Pair<List<FusedApp>, Boolean>> { val searchResults = gPlayAPIRepository.getSearchResults(query, authData) val searchResults = gPlayAPIRepository.getSearchResults(query, authData, ::replaceWithFDroid) return searchResults.map { Pair( it.first.map { app -> app.transformToFusedApp() }, it.first, it.second ) } } /* * This function will replace a GPlay app with F-Droid app if exists, * else will show the GPlay app itself. */ private suspend fun replaceWithFDroid(gPlayApp: App): FusedApp { val gPlayFusedApp = gPlayApp.transformToFusedApp() val response = fdroidWebInterface.getFdroidApp(gPlayFusedApp.package_name) if (response.isSuccessful) { val fdroidApp = getCleanApkPackageResult(gPlayFusedApp.package_name)?.apply { updateSource() isGplayReplaced = true } return fdroidApp ?: gPlayFusedApp } return gPlayFusedApp } /* * Home screen-related internal functions */ Loading Loading @@ -1482,4 +1502,6 @@ class FusedAPIImpl @Inject constructor( } return false } fun isOpenSourceSelected() = preferenceManagerModule.isOpenSourceSelected() } app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -480,4 +480,6 @@ class FusedAPIRepository @Inject constructor(private val fusedAPIImpl: FusedAPII hasNextStreamCluster = false clusterPointer = 0 } fun isOpenSourceSelected() = fusedAPIImpl.isOpenSourceSelected() } app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt +2 −1 Original line number Diff line number Diff line Loading @@ -90,5 +90,6 @@ data class FusedApp( * * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5720 */ var filterLevel: FilterLevel = FilterLevel.UNKNOWN var filterLevel: FilterLevel = FilterLevel.UNKNOWN, var isGplayReplaced: Boolean = false ) Loading
app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt +13 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ import foundation.e.apps.api.cleanapk.data.app.Application import foundation.e.apps.api.ecloud.EcloudApiInterface import foundation.e.apps.api.exodus.ExodusTrackerApi import foundation.e.apps.api.fdroid.FdroidApiInterface import foundation.e.apps.api.fdroid.FdroidWebInterface import okhttp3.Cache import okhttp3.Interceptor import okhttp3.MediaType.Companion.toMediaTypeOrNull Loading Loading @@ -117,6 +118,18 @@ object RetrofitModule { .create(FdroidApiInterface::class.java) } @Singleton @Provides fun provideFdroidWebApi( okHttpClient: OkHttpClient, ): FdroidWebInterface { return Retrofit.Builder() .baseUrl(FdroidWebInterface.BASE_URL) .client(okHttpClient) .build() .create(FdroidWebInterface::class.java) } @Singleton @Provides fun provideEcloudApi(okHttpClient: OkHttpClient, moshi: Moshi): EcloudApiInterface { Loading
app/src/main/java/foundation/e/apps/api/fdroid/FdroidWebInterface.kt 0 → 100644 +32 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019-2022 MURENA SAS * * 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.fdroid import okhttp3.ResponseBody import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Path interface FdroidWebInterface { companion object { const val BASE_URL = "https://f-droid.org/fr/packages/" } @GET("{packageName}") suspend fun getFdroidApp(@Path("packageName") packageName: String): Response<ResponseBody> }
app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +24 −2 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ 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.search.Search import foundation.e.apps.api.fdroid.FdroidWebInterface import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.api.fused.data.FusedCategory import foundation.e.apps.api.fused.data.FusedHome Loading Loading @@ -74,6 +75,7 @@ class FusedAPIImpl @Inject constructor( private val pkgManagerModule: PkgManagerModule, private val pwaManagerModule: PWAManagerModule, private val preferenceManagerModule: PreferenceManagerModule, private val fdroidWebInterface: FdroidWebInterface, @ApplicationContext private val context: Context ) { Loading Loading @@ -1197,15 +1199,33 @@ class FusedAPIImpl @Inject constructor( query: String, authData: AuthData ): LiveData<Pair<List<FusedApp>, Boolean>> { val searchResults = gPlayAPIRepository.getSearchResults(query, authData) val searchResults = gPlayAPIRepository.getSearchResults(query, authData, ::replaceWithFDroid) return searchResults.map { Pair( it.first.map { app -> app.transformToFusedApp() }, it.first, it.second ) } } /* * This function will replace a GPlay app with F-Droid app if exists, * else will show the GPlay app itself. */ private suspend fun replaceWithFDroid(gPlayApp: App): FusedApp { val gPlayFusedApp = gPlayApp.transformToFusedApp() val response = fdroidWebInterface.getFdroidApp(gPlayFusedApp.package_name) if (response.isSuccessful) { val fdroidApp = getCleanApkPackageResult(gPlayFusedApp.package_name)?.apply { updateSource() isGplayReplaced = true } return fdroidApp ?: gPlayFusedApp } return gPlayFusedApp } /* * Home screen-related internal functions */ Loading Loading @@ -1482,4 +1502,6 @@ class FusedAPIImpl @Inject constructor( } return false } fun isOpenSourceSelected() = preferenceManagerModule.isOpenSourceSelected() }
app/src/main/java/foundation/e/apps/api/fused/FusedAPIRepository.kt +2 −0 Original line number Diff line number Diff line Loading @@ -480,4 +480,6 @@ class FusedAPIRepository @Inject constructor(private val fusedAPIImpl: FusedAPII hasNextStreamCluster = false clusterPointer = 0 } fun isOpenSourceSelected() = fusedAPIImpl.isOpenSourceSelected() }
app/src/main/java/foundation/e/apps/api/fused/data/FusedApp.kt +2 −1 Original line number Diff line number Diff line Loading @@ -90,5 +90,6 @@ data class FusedApp( * * Issue: https://gitlab.e.foundation/e/backlog/-/issues/5720 */ var filterLevel: FilterLevel = FilterLevel.UNKNOWN var filterLevel: FilterLevel = FilterLevel.UNKNOWN, var isGplayReplaced: Boolean = false )