From 1854ee8e2127b6759b2e240fa1018fac907f94f5 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 15:47:13 +0530 Subject: [PATCH 1/7] App lounge: (issue_300) Create Ecloud API. --- .../e/apps/api/cleanapk/RetrofitModule.kt | 12 +++++++ .../e/apps/api/ecloud/EcloudApiInterface.kt | 36 +++++++++++++++++++ .../e/apps/api/ecloud/EcloudRepository.kt | 31 ++++++++++++++++ .../e/apps/api/ecloud/modules/FaultyToken.kt | 3 ++ 4 files changed, 82 insertions(+) create mode 100644 app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt create mode 100644 app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt create mode 100644 app/src/main/java/foundation/e/apps/api/ecloud/modules/FaultyToken.kt 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 cd2594dac..2672b48f0 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 000000000..93e2a67db --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt @@ -0,0 +1,36 @@ +/* + * 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.Field +import retrofit2.http.POST + +interface EcloudApiInterface { + + companion object { + val BASE_URL = "https://eu.gtoken.ecloud.global/" + } + + @POST("report/") + suspend fun uploadFaultyEmail( + @Body faultyToken: FaultyToken, + ) + +} \ 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 000000000..5b5cd45bc --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt @@ -0,0 +1,31 @@ +/* + * 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) { + ecloudApi.uploadFaultyEmail(FaultyToken( email, description)) + } +} \ 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 000000000..9d55722dc --- /dev/null +++ b/app/src/main/java/foundation/e/apps/api/ecloud/modules/FaultyToken.kt @@ -0,0 +1,3 @@ +package foundation.e.apps.api.ecloud.modules + +data class FaultyToken(val email: String, val description: String) \ No newline at end of file -- GitLab From c1a2285adeac6d7ddc12e539309eea8f89fcf1c3 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 15:47:53 +0530 Subject: [PATCH 2/7] App lounge: (issue_300) create uploadFaultyTokenToEcloud() from MainActivityViewModel.kt --- .../foundation/e/apps/MainActivityViewModel.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index e27f9471c..a0d604d6c 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -41,6 +41,7 @@ import com.aurora.gplayapi.data.models.AuthData import com.aurora.gplayapi.exceptions.ApiException import com.google.gson.Gson import dagger.hilt.android.lifecycle.HiltViewModel +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 @@ -67,7 +68,8 @@ class MainActivityViewModel @Inject constructor( private val dataStoreModule: DataStoreModule, private val fusedAPIRepository: FusedAPIRepository, private val fusedManagerRepository: FusedManagerRepository, - private val pkgManagerModule: PkgManagerModule + private val pkgManagerModule: PkgManagerModule, + private val ecloudRepository: EcloudRepository, ) : ViewModel() { val authDataJson: LiveData = dataStoreModule.authData.asLiveData() @@ -229,6 +231,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 -- GitLab From d59a5e4140a4152a90c82b02724882f907044743 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 15:51:51 +0530 Subject: [PATCH 3/7] App lounge: (issue_300) add license --- .../e/apps/api/ecloud/modules/FaultyToken.kt | 17 +++++++++++++++++ .../java/foundation/e/apps/home/HomeFragment.kt | 2 ++ 2 files changed, 19 insertions(+) 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 index 9d55722dc..9e1efa0ec 100644 --- 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 @@ -1,3 +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 4ece61dde..ed1696bca 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -109,6 +109,8 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { } homeViewModel.homeScreenData.observe(viewLifecycleOwner) { + System.out.println("Testingggg: email: " + mainActivityViewModel.authData.value?.email); + mainActivityViewModel.uploadFaultyTokenToEcloud("From " + this::class.java.name) binding.shimmerLayout.visibility = View.GONE binding.parentRV.visibility = View.VISIBLE if (!homeViewModel.isFusedHomesEmpty(it.first)) { -- GitLab From fa410f8a1ed81d51b33cfe2a4a9c1ee50b42c458 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 16:22:04 +0530 Subject: [PATCH 4/7] App lounge: (issue_300) fix errors --- .../java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt | 5 +++-- .../java/foundation/e/apps/api/ecloud/EcloudRepository.kt | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) 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 index 93e2a67db..46694e07c 100644 --- a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt @@ -19,7 +19,7 @@ package foundation.e.apps.api.ecloud import foundation.e.apps.api.ecloud.modules.FaultyToken import retrofit2.http.Body -import retrofit2.http.Field +import retrofit2.http.Header import retrofit2.http.POST interface EcloudApiInterface { @@ -28,8 +28,9 @@ interface EcloudApiInterface { val BASE_URL = "https://eu.gtoken.ecloud.global/" } - @POST("report/") + @POST("report") suspend fun uploadFaultyEmail( + @Header("Content-Type") contentType: String, @Body faultyToken: FaultyToken, ) 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 index 5b5cd45bc..e4b0ae690 100644 --- a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt @@ -26,6 +26,9 @@ class EcloudRepository @Inject constructor( private val ecloudApi: EcloudApiInterface, ) { suspend fun uploadFaultyEmail(email: String, description: String) { - ecloudApi.uploadFaultyEmail(FaultyToken( email, description)) + ecloudApi.uploadFaultyEmail( + "application/json", + FaultyToken(email, description) + ) } } \ No newline at end of file -- GitLab From c37a32decf5ba8c1c2640c8fbc55e030e289e39e Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 16:23:17 +0530 Subject: [PATCH 5/7] App lounge: (issue_300) remove unnecessary log, send to ecloud only when timeout dialog is shown --- app/src/main/java/foundation/e/apps/home/HomeFragment.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 ed1696bca..0516c3469 100644 --- a/app/src/main/java/foundation/e/apps/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/home/HomeFragment.kt @@ -109,13 +109,12 @@ class HomeFragment : Fragment(R.layout.fragment_home), FusedAPIInterface { } homeViewModel.homeScreenData.observe(viewLifecycleOwner) { - System.out.println("Testingggg: email: " + mainActivityViewModel.authData.value?.email); - mainActivityViewModel.uploadFaultyTokenToEcloud("From " + this::class.java.name) binding.shimmerLayout.visibility = View.GONE binding.parentRV.visibility = View.VISIBLE 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() -- GitLab From 35b8255587de00bdc286d2ee4076c4738ea9acd6 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 16:34:26 +0530 Subject: [PATCH 6/7] App lounge: (issue_300) surround with try catch --- .../foundation/e/apps/api/ecloud/EcloudRepository.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 index e4b0ae690..674a6bb10 100644 --- a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt @@ -26,9 +26,13 @@ class EcloudRepository @Inject constructor( private val ecloudApi: EcloudApiInterface, ) { suspend fun uploadFaultyEmail(email: String, description: String) { - ecloudApi.uploadFaultyEmail( - "application/json", - FaultyToken(email, description) - ) + try { + ecloudApi.uploadFaultyEmail( + "application/json", + FaultyToken(email, description) + ) + } catch (e: Exception) { + e.printStackTrace() + } } } \ No newline at end of file -- GitLab From eeca08f89e1c8db5da50988b2d3f8cfd949ec282 Mon Sep 17 00:00:00 2001 From: SayantanRC Date: Wed, 18 May 2022 16:51:01 +0530 Subject: [PATCH 7/7] App lounge: (issue_300) remove header from repository --- .../java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt | 2 +- .../main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) 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 index 46694e07c..9b02ef35c 100644 --- a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudApiInterface.kt @@ -30,8 +30,8 @@ interface EcloudApiInterface { @POST("report") suspend fun uploadFaultyEmail( - @Header("Content-Type") contentType: String, @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 index 674a6bb10..a0dbd939e 100644 --- a/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt +++ b/app/src/main/java/foundation/e/apps/api/ecloud/EcloudRepository.kt @@ -28,7 +28,6 @@ class EcloudRepository @Inject constructor( suspend fun uploadFaultyEmail(email: String, description: String) { try { ecloudApi.uploadFaultyEmail( - "application/json", FaultyToken(email, description) ) } catch (e: Exception) { -- GitLab