diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 910550453d0a5a2dfafa37278f42f93249395b4c..82d0ebd57ec45d98234f06603327b9702e7d5319 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -42,6 +42,7 @@ import com.aurora.gplayapi.exceptions.ApiException import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.api.cleanapk.blockedApps.BlockedAppRepository +import foundation.e.apps.api.ecloud.EcloudRepository import foundation.e.apps.api.fused.FusedAPIImpl import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp @@ -69,7 +70,8 @@ class MainActivityViewModel @Inject constructor( private val fusedAPIRepository: FusedAPIRepository, private val fusedManagerRepository: FusedManagerRepository, private val pkgManagerModule: PkgManagerModule, - private val blockedAppRepository: BlockedAppRepository + private val ecloudRepository: EcloudRepository, + private val blockedAppRepository: BlockedAppRepository, ) : ViewModel() { val authDataJson: LiveData = dataStoreModule.authData.asLiveData() @@ -231,6 +233,18 @@ class MainActivityViewModel @Inject constructor( authValidity.postValue(false) } + fun uploadFaultyTokenToEcloud(description: String){ + viewModelScope.launch { + authData.value?.let { authData -> + val email: String = authData.run { + if (email != "null") email + else userProfile?.email ?: "null" + } + ecloudRepository.uploadFaultyEmail(email, description) + } + } + } + fun getAuthData() { if (!authRequestRunning) { authRequestRunning = true diff --git a/app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt b/app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt index cd2594dacb41a975713b98f7e3c73b2e200b977e..2672b48f080db54d5c561824fb0259b23ca90906 100644 --- a/app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt +++ b/app/src/main/java/foundation/e/apps/api/cleanapk/RetrofitModule.kt @@ -28,6 +28,7 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import foundation.e.apps.api.ecloud.EcloudApiInterface import foundation.e.apps.api.exodus.ExodusTrackerApi import foundation.e.apps.api.fdroid.FdroidApiInterface import okhttp3.Cache @@ -94,6 +95,17 @@ object RetrofitModule { .create(FdroidApiInterface::class.java) } + @Singleton + @Provides + fun provideEcloudApi(okHttpClient: OkHttpClient, moshi: Moshi): EcloudApiInterface { + return Retrofit.Builder() + .baseUrl(EcloudApiInterface.BASE_URL) + .client(okHttpClient) + .addConverterFactory(MoshiConverterFactory.create(moshi)) + .build() + .create(EcloudApiInterface::class.java) + } + @Singleton @Provides fun getMoshi(): Moshi { diff --git a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt new file mode 100644 index 0000000000000000000000000000000000000000..9b02ef35c07fa562987b446f23144ba9a88457b0 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 ECORP + * + * 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 . + */ + +package foundation.e.apps.api.ecloud + +import foundation.e.apps.api.ecloud.modules.FaultyToken +import retrofit2.http.Body +import retrofit2.http.Header +import retrofit2.http.POST + +interface EcloudApiInterface { + + companion object { + val BASE_URL = "https://eu.gtoken.ecloud.global/" + } + + @POST("report") + suspend fun uploadFaultyEmail( + @Body faultyToken: FaultyToken, + @Header("Content-Type") contentType: String = "application/json", + ) + +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt new file mode 100644 index 0000000000000000000000000000000000000000..a0dbd939e450edf1c630b7fef6a9075bc89b52e1 --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 ECORP + * + * 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 . + */ + +package foundation.e.apps.api.ecloud + +import foundation.e.apps.api.ecloud.modules.FaultyToken +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class EcloudRepository @Inject constructor( + private val ecloudApi: EcloudApiInterface, +) { + suspend fun uploadFaultyEmail(email: String, description: String) { + try { + ecloudApi.uploadFaultyEmail( + FaultyToken(email, description) + ) + } catch (e: Exception) { + e.printStackTrace() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/api/ecloud/modules/FaultyToken.kt b/app/src/main/java/foundation/e/apps/api/ecloud/modules/FaultyToken.kt new file mode 100644 index 0000000000000000000000000000000000000000..9e1efa0ec965bbc1415f7d97755e62acbd6b220b --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/modules/FaultyToken.kt @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2022 ECORP + * + * 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 . + */ + +package foundation.e.apps.api.ecloud.modules + +data class FaultyToken(val email: String, val description: String) \ No newline at end of file diff --git a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt index 4ece61ddec66563faf211dc6b63f1f462f355bad..0516c34693eaae23507cfd3362cb9ef2ab43b310 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -114,6 +114,7 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { if (!homeViewModel.isFusedHomesEmpty(it.first)) { homeParentRVAdapter.setData(it.first) } else if (!mainActivityViewModel.isTimeoutDialogDisplayed()) { + mainActivityViewModel.uploadFaultyTokenToEcloud("From " + this::class.java.name) mainActivityViewModel.displayTimeoutAlertDialog(requireActivity(), { showLoadingShimmer() mainActivityViewModel.retryFetchingTokenAfterTimeout()