diff --git a/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt b/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt index f5c5cdd50a9099331500746b5aa7f51ba3e1757e..5b13f55916a7e14764235f19d845d66adb695315 100644 --- a/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt +++ b/app/src/main/java/foundation/e/apps/data/NetworkHandler.kt @@ -18,9 +18,9 @@ package foundation.e.apps.data +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.data.playstore.utils.GPlayHttpClient import foundation.e.apps.data.playstore.utils.GplayHttpRequestException -import foundation.e.apps.data.login.exceptions.GPlayException import kotlinx.coroutines.delay import timber.log.Timber import java.net.SocketTimeoutException @@ -55,9 +55,15 @@ private fun handleSocketTimeoutException(e: SocketTimeoutException): ResultS private fun resultSupremeGplayHttpRequestException(e: GplayHttpRequestException): ResultSupreme { val message = extractErrorMessage(e) - val exception = GPlayException(e.status == GPlayHttpClient.STATUS_CODE_TIMEOUT, message) + val error = if (e.status == GPlayHttpClient.STATUS_CODE_TIMEOUT) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + val exception = CustomException(error, message) - return if (exception.isTimeout) { + return if (error == CustomException.Error.TIMEOUT_ERROR) { ResultSupreme.Timeout(exception = exception) } else { ResultSupreme.Error(message, exception) diff --git a/app/src/main/java/foundation/e/apps/data/ResultSupreme.kt b/app/src/main/java/foundation/e/apps/data/ResultSupreme.kt index a7a773f60ae33131d12c9ec6f68cae8adda48356..70eb4ff6ec0ff8909285879c967bf88c794d00a2 100644 --- a/app/src/main/java/foundation/e/apps/data/ResultSupreme.kt +++ b/app/src/main/java/foundation/e/apps/data/ResultSupreme.kt @@ -18,6 +18,7 @@ package foundation.e.apps.data import foundation.e.apps.data.enums.ResultStatus +import foundation.e.apps.data.login.exceptions.CustomException import java.util.concurrent.TimeoutException private const val UNKNOWN_ERROR = "Unknown error!" @@ -60,7 +61,7 @@ sealed class ResultSupreme { data?.let { setData(it) } - this.exception = exception + this.exception?.encapsulatedException = exception } } @@ -76,7 +77,7 @@ sealed class ResultSupreme { */ constructor(message: String, exception: Exception? = null) : this() { this.message = message - this.exception = exception + this.exception?.encapsulatedException = exception } /** @@ -111,7 +112,7 @@ sealed class ResultSupreme { /** * Exception from try-catch block for error cases. */ - var exception: Exception? = null + var exception: CustomException? = null fun isValidData() = data != null @@ -155,7 +156,7 @@ sealed class ResultSupreme { this.data = data } else { this.message = message.ifBlank { status.message } - this.exception = exception + this.exception?.encapsulatedException = exception } } return resultObject diff --git a/app/src/main/java/foundation/e/apps/data/login/AuthObject.kt b/app/src/main/java/foundation/e/apps/data/login/AuthObject.kt index e63f051de5d8438b1bd1ed2b3845ed4c5aeafb21..7d2eb7cf7944374bc5872d12dbff9f9d736d0947 100644 --- a/app/src/main/java/foundation/e/apps/data/login/AuthObject.kt +++ b/app/src/main/java/foundation/e/apps/data/login/AuthObject.kt @@ -21,8 +21,7 @@ import com.aurora.gplayapi.data.models.AuthData import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.enums.User import foundation.e.apps.data.login.AuthObject.GPlayAuth -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayValidationException +import foundation.e.apps.data.login.exceptions.CustomException /** * Auth objects define which sources data is to be loaded from, for each source, also provides @@ -48,10 +47,12 @@ sealed class AuthObject { return GPlayAuth( ResultSupreme.Error( message = message, - exception = GPlayValidationException( + exception = CustomException( + CustomException.Error.AUTHENTICATION_ERROR, message, this.user, 401, + CustomException.Type.GOOGLE_PLAY ) ).apply { otherPayload = this@GPlayAuth.result.otherPayload @@ -66,14 +67,15 @@ sealed class AuthObject { return CleanApk( ResultSupreme.Error( message = "Unauthorized", - exception = CleanApkException( - isTimeout = false, - message = "Unauthorized", + exception = CustomException( + CustomException.Error.AUTHENTICATION_ERROR, + "Unauthorized", + this.user ) ), this.user, ) } } - // Add more auth types here + } diff --git a/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt b/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt index fccc0b15aec13f192dbe1d174224294152080b07..1533dd49838e822e91f567ba7ef50eeec37a49c3 100644 --- a/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/login/AuthenticatorRepository.kt @@ -20,7 +20,7 @@ package foundation.e.apps.data.login import com.aurora.gplayapi.data.models.AuthData import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.enums.User -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import javax.inject.Inject import javax.inject.Singleton @@ -34,7 +34,12 @@ class AuthenticatorRepository @Inject constructor( private var gPlayAuth: AuthData? = null fun getGPlayAuthOrThrow(): AuthData { - return gPlayAuth ?: throw GPlayLoginException(false, "AuthData is not available!", getUserType()) + return gPlayAuth ?: throw CustomException( + CustomException.Error.AUTHENTICATION_ERROR, + "AuthData is not available!", + getUserType(), + type = CustomException.Type.GOOGLE_PLAY + ) } fun setGPlayAuth(auth: AuthData) { diff --git a/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt b/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt index 4d013b2f058457ef1b0d7617826c8c586fa3367d..c1604c3a48539f3534a9e1125e972a1079896aa7 100644 --- a/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt +++ b/app/src/main/java/foundation/e/apps/data/login/api/PlayStoreLoginWrapper.kt @@ -23,7 +23,7 @@ import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.enums.User import foundation.e.apps.data.playstore.utils.AC2DMUtil import foundation.e.apps.data.handleNetworkResult -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.utils.eventBus.AppEvent import foundation.e.apps.utils.eventBus.EventBus import java.util.Locale @@ -52,8 +52,20 @@ class PlayStoreLoginWrapper constructor( return result.apply { this.data?.locale = locale this.exception = when (result) { - is ResultSupreme.Timeout -> GPlayLoginException(true, "GPlay API timeout", user) - is ResultSupreme.Error -> GPlayLoginException(false, result.message, user) + is ResultSupreme.Timeout -> + CustomException( + CustomException.Error.TIMEOUT_ERROR, + "GPlay API timeout", + user, + type = CustomException.Type.GOOGLE_PLAY + ) + is ResultSupreme.Error -> + CustomException( + CustomException.Error.AUTHENTICATION_ERROR, + result.message, + user, + type = CustomException.Type.GOOGLE_PLAY + ) else -> { EventBus.invokeEvent(AppEvent.SuccessfulLogin(user)) null @@ -82,8 +94,19 @@ class PlayStoreLoginWrapper constructor( } return ResultSupreme.replicate(result, response).apply { this.exception = when (result) { - is ResultSupreme.Timeout -> GPlayLoginException(true, "GPlay API timeout", user) - is ResultSupreme.Error -> GPlayLoginException(false, result.message, user) + is ResultSupreme.Timeout -> + CustomException( + CustomException.Error.TIMEOUT_ERROR, + "GPlay API timeout", + user, + type = CustomException.Type.GOOGLE_PLAY + ) + is ResultSupreme.Error -> CustomException( + CustomException.Error.AUTHENTICATION_ERROR, + result.message, + user, + type = CustomException.Type.GOOGLE_PLAY + ) else -> null } } @@ -129,8 +152,17 @@ class PlayStoreLoginWrapper constructor( } return result.apply { this.exception = when (result) { - is ResultSupreme.Timeout -> GPlayLoginException(true, "GPlay API timeout", User.GOOGLE) - is ResultSupreme.Error -> GPlayLoginException(false, result.message, User.GOOGLE) + is ResultSupreme.Timeout -> CustomException( + CustomException.Error.TIMEOUT_ERROR, + "GPlay API timeout", + User.GOOGLE, + type = CustomException.Type.GOOGLE_PLAY + ) + is ResultSupreme.Error -> CustomException( + CustomException.Error.AUTHENTICATION_ERROR, + result.message, + User.GOOGLE, + type = CustomException.Type.GOOGLE_PLAY) else -> null } } diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/CleanApkException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/CleanApkException.kt deleted file mode 100644 index 293819914aac64751e60c5da12cf5b94caa2a5c2..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/CleanApkException.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019-2022 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 . - */ - -package foundation.e.apps.data.login.exceptions - -/** - * This exception is for all CleanApk data loading exceptions. - */ -class CleanApkException( - val isTimeout: Boolean, - message: String? = null, -) : LoginException(message) diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayValidationException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/CustomException.kt similarity index 63% rename from app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayValidationException.kt rename to app/src/main/java/foundation/e/apps/data/login/exceptions/CustomException.kt index 5b4322a4cc955487b91ee65578af872f7be67876..271a29bce74735cd75be79dfd1f3ced5b633b1e7 100644 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayValidationException.kt +++ b/app/src/main/java/foundation/e/apps/data/login/exceptions/CustomException.kt @@ -19,14 +19,23 @@ package foundation.e.apps.data.login.exceptions import foundation.e.apps.data.enums.User -/** - * This exception is specifically used when a GPlay auth data could not be validated. - * This is not the case as timeout, this exception usually means the server informed that the - * current auth data is not valid. - * Use [networkCode] to be sure that the server call was successful (should be 200). - */ -class GPlayValidationException( - message: String, - user: User, - val networkCode: Int, -) : GPlayLoginException(false, message, user) +class CustomException( + val error: Error? = null, + override val message: String? = null, + val user: User? = null, + val networkCode: Int = -1, + val type: Type? = null, + var encapsulatedException: Exception? = null +) : Exception(message) { + + enum class Error { + TIMEOUT_ERROR, + AUTHENTICATION_ERROR, + UNKNOWN_ERROR + } + + enum class Type { + GOOGLE_PLAY, + CLEAN_PK + } +} diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayException.kt deleted file mode 100644 index 345208778528b1d12c330fe7477111c98c7e7501..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayException.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2019-2022 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 . - */ - -package foundation.e.apps.data.login.exceptions - -/** - * This exception is for all Google Play network calls or other GPlay related exceptions. - */ -open class GPlayException( - val isTimeout: Boolean, - message: String? = null, -) : LoginException(message) diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayLoginException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayLoginException.kt deleted file mode 100644 index d6a64a7bb3d20c52243c9f30434122b431642716..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/GPlayLoginException.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 . - */ - -package foundation.e.apps.data.login.exceptions - -import foundation.e.apps.data.enums.User - -/** - * Parent class for all GPlay login related errors. - * Examples: - * unable to get anonymous token, AuthData validation failed, aasToken error etc. - */ -open class GPlayLoginException( - isTimeout: Boolean, - message: String? = null, - val user: User, -) : GPlayException(isTimeout, message) diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/LoginException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/LoginException.kt deleted file mode 100644 index e69cb47b51b084af03f8bc0414779598fe56e317..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/LoginException.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2019-2022 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 . - */ - -package foundation.e.apps.data.login.exceptions - -/** - * Super class for all Login related exceptions. - * https://gitlab.e.foundation/e/backlog/-/issues/5680 - */ -open class LoginException(message: String?) : Exception(message) diff --git a/app/src/main/java/foundation/e/apps/data/login/exceptions/UnknownSourceException.kt b/app/src/main/java/foundation/e/apps/data/login/exceptions/UnknownSourceException.kt deleted file mode 100644 index 3c881d9f6ac9cb31b253ea6a3829a8fb2410d4fc..0000000000000000000000000000000000000000 --- a/app/src/main/java/foundation/e/apps/data/login/exceptions/UnknownSourceException.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2019-2022 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 . - */ - -package foundation.e.apps.data.login.exceptions - -/** - * Generic exception class - used to define unknown errors. - */ -class UnknownSourceException : LoginException("") diff --git a/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt b/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt index a3e0c76842ee4749e548469b7bf66982cdb582b2..6d61487dc0706ea3b62cb24caa1f71a375b7085b 100644 --- a/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt +++ b/app/src/main/java/foundation/e/apps/install/splitinstall/SplitInstallBinder.kt @@ -26,7 +26,6 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.pm.PackageManager -import android.os.Build import androidx.core.app.ActivityCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat @@ -37,7 +36,7 @@ import foundation.e.apps.R import foundation.e.apps.data.DownloadManager import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.login.AuthenticatorRepository -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -73,7 +72,7 @@ class SplitInstallBinder( authenticatorRepository.getValidatedAuthData() authenticatorRepository.getGPlayAuthOrThrow() downloadModule(packageName, moduleName) - } catch (exception: GPlayLoginException) { + } catch (exception: CustomException) { Timber.w("$AUTH_DATA_ERROR_MESSAGE $exception") handleError(packageName) } diff --git a/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt b/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt index 0ed06df83d601b6acf738b76bc78e2b020aa88d8..0a72459d0ac7fe0b6f8b55e58f7d395f7f3a29ea 100644 --- a/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt +++ b/app/src/main/java/foundation/e/apps/provider/AgeRatingProvider.kt @@ -26,7 +26,6 @@ import android.content.UriMatcher import android.database.Cursor import android.database.MatrixCursor import android.net.Uri -import android.os.Build import androidx.core.app.NotificationCompat import dagger.hilt.EntryPoint import dagger.hilt.InstallIn @@ -44,7 +43,7 @@ import foundation.e.apps.data.blockedApps.BlockedAppRepository import foundation.e.apps.data.enums.Origin import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthenticatorRepository -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.data.parentalcontrol.ContentRatingDao import foundation.e.apps.data.parentalcontrol.ContentRatingEntity import foundation.e.apps.data.parentalcontrol.fdroid.FDroidAntiFeatureRepository @@ -288,7 +287,7 @@ class AgeRatingProvider : ContentProvider() { return try { authenticatorRepository.getGPlayAuthOrThrow() true - } catch (e: GPlayLoginException) { + } catch (e: CustomException) { Timber.e("No AuthData to check content rating") false } diff --git a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt index b897133a0e843325c1561710389ca1d108f12265..b3d40fdaa5e275220459e6e5167278eb848eaa0e 100644 --- a/app/src/main/java/foundation/e/apps/ui/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/ui/MainActivity.kt @@ -50,7 +50,7 @@ import foundation.e.apps.data.enums.User import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.PlayStoreAuthenticator -import foundation.e.apps.data.login.exceptions.GPlayValidationException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.ActivityMainBinding import foundation.e.apps.install.updates.UpdatesNotifier import foundation.e.apps.ui.application.subFrags.ApplicationDialogFragment @@ -356,7 +356,7 @@ class MainActivity : AppCompatActivity() { gPlayAuthObject?.result?.run { if (isSuccess()) { viewModel.gPlayAuthData = data as AuthData - } else if (exception is GPlayValidationException) { + } else if (exception?.type == CustomException.Type.GOOGLE_PLAY) { val email = otherPayload.toString() viewModel.uploadFaultyTokenToEcloud( email, diff --git a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt index c4bde026cb236c9f42b91deebeee464b6dffdb49..4f473396742cd2f6a3bf022ec8110ea83807dfa4 100644 --- a/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/application/ApplicationFragment.kt @@ -61,7 +61,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.enums.User import foundation.e.apps.data.enums.isInitialized import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentApplicationBinding import foundation.e.apps.di.CommonUtilsModule.LIST_OF_NULL import foundation.e.apps.domain.ValidateAppAgeLimitUseCase.Companion.KEY_ANTI_FEATURES_NSFW @@ -621,23 +621,23 @@ class ApplicationFragment : TimeoutFragment(R.layout.fragment_application) { } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder - ): AlertDialog.Builder? { + ): AlertDialog.Builder { return predefinedDialog } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder - ): AlertDialog.Builder? { + ): AlertDialog.Builder { return predefinedDialog } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder - ): AlertDialog.Builder? { + ): AlertDialog.Builder { return predefinedDialog } diff --git a/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt b/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt index 3631984268053a4273c9cdadc5130a43ee5ba19d..19c2df2db58b519f04e86e5f847a203bdb00c29d 100644 --- a/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/application/ApplicationViewModel.kt @@ -34,8 +34,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.install.AppManagerWrapper import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.data.parentalcontrol.fdroid.FDroidAntiFeatureRepository import foundation.e.apps.data.playstore.PlayStoreRepository import foundation.e.apps.install.download.data.DownloadProgress @@ -148,18 +147,20 @@ class ApplicationViewModel @Inject constructor( updateAppContentRatingState(packageName, appData.first.contentRating) val status = appData.second + val hasTimedOut = appData.second == ResultStatus.TIMEOUT + val error = if (hasTimedOut) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } if (appData.second != ResultStatus.OK) { val exception = - if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) - GPlayException( - appData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) - else CleanApkException( - appData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) + if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) { + CustomException(error, status.message.ifBlank { "Data load error" }, type = CustomException.Type.GOOGLE_PLAY) + } else { + CustomException(error, status.message.ifBlank { "Data load error" }) + } exceptionsList.add(exception) exceptionsLiveData.postValue(exceptionsList) diff --git a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt index ef7aa73a697017cbc49b84990e62dbb39f3277f1..a3050985d8573e3c82c27f33a12f5753d4841405 100644 --- a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListFragment.kt @@ -36,7 +36,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.application.ApplicationInstaller import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentApplicationListBinding import foundation.e.apps.install.download.data.DownloadProgress import foundation.e.apps.install.pkg.PwaManager @@ -270,21 +270,21 @@ class ApplicationListFragment : } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog diff --git a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListViewModel.kt b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListViewModel.kt index bf4272a17563055deaa5833684382af66772ddc6..dad65ee63eda340f977501100e3693b5c2a21be2 100644 --- a/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/applicationlist/ApplicationListViewModel.kt @@ -28,8 +28,7 @@ import foundation.e.apps.data.enums.Source import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -112,16 +111,21 @@ class ApplicationListViewModel @Inject constructor( private fun getException( authData: AuthData, result: ResultSupreme, String>> - ) = if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) { - GPlayException( - result.isTimeout(), - result.message.ifBlank { "Data load error" } - ) - } else { - CleanApkException( - result.isTimeout(), - result.message.ifBlank { "Data load error" } - ) + ) : CustomException { + val error = if (result.isTimeout()) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) { + return CustomException(error, + result.message.ifBlank { "Data load error" }, type = CustomException.Type.GOOGLE_PLAY + ) + } else { + return CustomException(error, result.message.ifBlank { "Data load error" } + ) + } } private fun updateNextPageUrl(nextPageUrl: String?) { diff --git a/app/src/main/java/foundation/e/apps/ui/categories/AppsFragment.kt b/app/src/main/java/foundation/e/apps/ui/categories/AppsFragment.kt index fadb8dd123421944ea4061f6d85a3a8cd96528c4..5842321bb0edd541d78b22d491475d187dd7b365 100644 --- a/app/src/main/java/foundation/e/apps/ui/categories/AppsFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/categories/AppsFragment.kt @@ -28,7 +28,7 @@ import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.R import foundation.e.apps.data.application.utils.CategoryType import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentAppsBinding import foundation.e.apps.ui.MainActivityViewModel import foundation.e.apps.ui.categories.model.CategoriesRVAdapter @@ -80,21 +80,21 @@ class AppsFragment : TimeoutFragment(R.layout.fragment_apps) { } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog diff --git a/app/src/main/java/foundation/e/apps/ui/categories/CategoriesViewModel.kt b/app/src/main/java/foundation/e/apps/ui/categories/CategoriesViewModel.kt index 163562d95fefa79ca1f03537dc7d53be5f9eb4b1..228252f0114720620c0d037e3f885599f8067305 100644 --- a/app/src/main/java/foundation/e/apps/ui/categories/CategoriesViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/categories/CategoriesViewModel.kt @@ -27,8 +27,7 @@ import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.data.Category import foundation.e.apps.data.application.utils.CategoryType import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch import javax.inject.Inject @@ -67,17 +66,15 @@ class CategoriesViewModel @Inject constructor( val status = categoriesData.second + val error = if (categoriesData.second == ResultStatus.TIMEOUT) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + if (status != ResultStatus.OK) { val exception = - if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) - GPlayException( - categoriesData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) - else CleanApkException( - categoriesData.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) + CustomException(error, status.message.ifBlank { "Data load error" }) exceptionsList.add(exception) exceptionsLiveData.postValue(exceptionsList) diff --git a/app/src/main/java/foundation/e/apps/ui/categories/GamesFragment.kt b/app/src/main/java/foundation/e/apps/ui/categories/GamesFragment.kt index dbbf2ad7aa98c15c5c0294085e3362c51d36ced2..f245eec8cbc12abb68c7c003d080c6e53e06460f 100644 --- a/app/src/main/java/foundation/e/apps/ui/categories/GamesFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/categories/GamesFragment.kt @@ -28,7 +28,7 @@ import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.R import foundation.e.apps.data.application.utils.CategoryType import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentGamesBinding import foundation.e.apps.ui.MainActivityViewModel import foundation.e.apps.ui.categories.model.CategoriesRVAdapter @@ -80,21 +80,21 @@ class GamesFragment : TimeoutFragment(R.layout.fragment_games) { } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt index 7c5e7c9fc4cb233c1b841545508dfc4c6375c3f3..8ada3f9cb2d8fbdf431229dd4472e9917de30876 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeFragment.kt @@ -33,8 +33,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.application.ApplicationInstaller import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayException -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentHomeBinding import foundation.e.apps.di.CommonUtilsModule.safeNavigate import foundation.e.apps.install.download.data.DownloadProgress @@ -145,24 +144,20 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder - ): AlertDialog.Builder? { + ): AlertDialog.Builder { return predefinedDialog.apply { - if (exception is GPlayException) { - setMessage(R.string.timeout_desc_gplay) - setNegativeButton(R.string.open_settings) { _, _ -> - openSettings() - } - } else { - setMessage(R.string.timeout_desc_cleanapk) + setMessage(R.string.timeout_desc_gplay) + setNegativeButton(R.string.open_settings) { _, _ -> + openSettings() } setCancelable(false) } } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog.apply { @@ -173,14 +168,12 @@ class HomeFragment : TimeoutFragment(R.layout.fragment_home), ApplicationInstall } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder - ): AlertDialog.Builder? { + ): AlertDialog.Builder { return predefinedDialog.apply { - if (exception is GPlayException) { - setNegativeButton(R.string.open_settings) { _, _ -> - openSettings() - } + setNegativeButton(R.string.open_settings) { _, _ -> + openSettings() } } } diff --git a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt index afd4f8cd2dfb6224109c08fda60540f41fe97799..74b43a2264bc736b09a823fe755c862f90722e04 100644 --- a/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/home/HomeViewModel.kt @@ -28,8 +28,7 @@ import foundation.e.apps.data.ResultSupreme import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.data.Home import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.ui.applicationlist.ApplicationDiffUtil import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.launch @@ -83,16 +82,13 @@ class HomeViewModel @Inject constructor( return@observe } - val exception = - if (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) - GPlayException( - it.isTimeout(), - it.message.ifBlank { "Data load error" } - ) - else CleanApkException( - it.isTimeout(), - it.message.ifBlank { "Data load error" } - ) + val error = if (it.isTimeout()) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + val exception = CustomException(error, it.message.ifBlank { "Data load error" }) exceptionsList.add(exception) exceptionsLiveData.postValue(exceptionsList) diff --git a/app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt b/app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt index a59e502ca0bc1aa937f4afe847ac73102c5ae07f..ac62485aca57ea168d05cd4bc517bab94164c086 100644 --- a/app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/parentFragment/LoadingViewModel.kt @@ -20,8 +20,7 @@ package foundation.e.apps.ui.parentFragment import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayValidationException -import foundation.e.apps.data.login.exceptions.UnknownSourceException +import foundation.e.apps.data.login.exceptions.CustomException abstract class LoadingViewModel : ViewModel() { @@ -29,8 +28,8 @@ abstract class LoadingViewModel : ViewModel() { private var autoRetried = false } - val exceptionsLiveData: MutableLiveData> = MutableLiveData() - val exceptionsList = ArrayList() + val exceptionsLiveData: MutableLiveData> = MutableLiveData() + val exceptionsList = ArrayList() /** * Call this method from ViewModel. @@ -53,11 +52,11 @@ abstract class LoadingViewModel : ViewModel() { val failedAuthList = authObjectList.filter { !it.result.isSuccess() } failedAuthList.forEach { - exceptionsList.add(it.result.exception ?: UnknownSourceException()) + exceptionsList.add(it.result.exception ?: CustomException()) } exceptionsList.find { - it is GPlayValidationException + it.type == CustomException.Type.GOOGLE_PLAY }?.run { if (!autoRetried && retryBlock(failedAuthList)) { autoRetried = true diff --git a/app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt b/app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt index 6d3d162b8f2e58896832a8560047033049972e28..30e160d6e48e073a3326bdc1a9d05b00d00cafaf 100644 --- a/app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/parentFragment/TimeoutFragment.kt @@ -35,11 +35,7 @@ import foundation.e.apps.data.enums.User import foundation.e.apps.data.login.AuthObject import foundation.e.apps.data.login.PlayStoreAuthenticator import foundation.e.apps.ui.LoginViewModel -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException -import foundation.e.apps.data.login.exceptions.GPlayLoginException -import foundation.e.apps.data.login.exceptions.GPlayValidationException -import foundation.e.apps.data.login.exceptions.UnknownSourceException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.DialogErrorLogBinding import foundation.e.apps.ui.MainActivityViewModel import timber.log.Timber @@ -138,7 +134,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * or null to not show anything. */ abstract fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? @@ -162,7 +158,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * or null to not show anything. */ abstract fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? @@ -181,7 +177,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * 6. Dialog is cancellable. */ abstract fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder, ): AlertDialog.Builder? @@ -248,7 +244,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * instance if it deems fit. Else it may return null, in which case no timeout dialog * is shown to the user. */ - fun showTimeout(exception: Exception) { + private fun showTimeout(exception: CustomException) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { @@ -296,7 +292,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * instance if it deems fit. Else it may return null, at which case no error dialog * is shown to the user. */ - fun showSignInError(exception: GPlayLoginException) { + fun showSignInError(exception: CustomException) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { @@ -329,9 +325,10 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { setPositiveButton(R.string.retry) { _, _ -> showLoadingUI() - when (exception) { - is GPlayValidationException -> clearAndRestartGPlayLogin() - else -> loginViewModel.startLoginFlow() + if (exception.networkCode == 401) { + clearAndRestartGPlayLogin() + } else { + loginViewModel.startLoginFlow() } } setNegativeButton(R.string.logout) { _, _ -> @@ -356,7 +353,7 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * instance if it deems fit. Else it may return null, at which case no error dialog * is shown to the user. */ - fun showDataLoadError(exception: Exception) { + fun showDataLoadError(exception: CustomException) { val dialogView = DialogErrorLogBinding.inflate(requireActivity().layoutInflater) dialogView.apply { moreInfo.setOnClickListener { @@ -400,42 +397,27 @@ abstract class TimeoutFragment(@LayoutRes layoutId: Int) : Fragment(layoutId) { * Common code to handle exceptions / errors during data loading. * Can be overridden in child fragments. */ - open fun handleExceptionsCommon(exceptions: List) { - val cleanApkException = exceptions.find { it is CleanApkException }?.run { - this as CleanApkException - } - val gPlayException = exceptions.find { it is GPlayException }?.run { - this as GPlayException - } - val unknownSourceException = exceptions.find { it is UnknownSourceException } + open fun handleExceptionsCommon(exceptions: List) { - if (gPlayException?.message?.contains(STATUS_TOO_MANY_REQUESTS) == true) { - return - } + exceptions.forEach { + when { + it.type == CustomException.Type.GOOGLE_PLAY -> { + if (it.message?.contains(STATUS_TOO_MANY_REQUESTS) == true) { + return + } - /* - * Take caution altering the cases. - * Cases to be defined from most restrictive to least restrictive. - */ - when { - // Handle timeouts - cleanApkException?.isTimeout == true -> showTimeout(cleanApkException) - gPlayException?.isTimeout == true -> showTimeout(gPlayException) - - // Handle sign-in error - gPlayException is GPlayLoginException -> showSignInError(gPlayException) - - // Other errors - data loading error - gPlayException != null -> showDataLoadError(gPlayException) - cleanApkException != null -> showDataLoadError(cleanApkException) - - // Unknown exception - unknownSourceException != null -> { - showAndSetDialog( + if (it.error == CustomException.Error.AUTHENTICATION_ERROR) { + showSignInError(it) + } + } + + it.error == CustomException.Error.TIMEOUT_ERROR -> showTimeout(it) + + else -> showAndSetDialog( AlertDialog.Builder(requireActivity()) .setTitle(R.string.unknown_error) - .setPositiveButton(R.string.close, null) - ) + .setPositiveButton(R.string.close, null)) + } } } diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt index c84b019d8050b474cba08c1ca4e836a7ecdca9ce..0ae80fa78910b5190150db12691b2e6919257006 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchFragment.kt @@ -49,7 +49,7 @@ import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.enums.Status import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentSearchBinding import foundation.e.apps.install.download.data.DownloadProgress import foundation.e.apps.install.pkg.PwaManager @@ -344,21 +344,21 @@ class SearchFragment : } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog diff --git a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt index 9d89d8f31ae6f51d828cf8944ea1dbac5b991ac6..61eb29a7c328e1fe635f66beca38a8e8b0e39f82 100644 --- a/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/search/SearchViewModel.kt @@ -34,9 +34,7 @@ import foundation.e.apps.data.enums.Origin import foundation.e.apps.data.exodus.repositories.IAppPrivacyInfoRepository import foundation.e.apps.data.exodus.repositories.PrivacyScoreRepository import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException -import foundation.e.apps.data.login.exceptions.UnknownSourceException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.di.CommonUtilsModule.LIST_OF_NULL import foundation.e.apps.ui.parentFragment.LoadingViewModel import kotlinx.coroutines.Dispatchers @@ -151,20 +149,16 @@ class SearchViewModel @Inject constructor( hasGPlayBeenFetched = false emitFilteredResults(searchResultSupreme) + if (!searchResultSupreme.isSuccess()) { - val exception = - if (authData != null) { - GPlayException( - searchResultSupreme.isTimeout(), - searchResultSupreme.message.ifBlank { DATA_LOAD_ERROR } - ) - } else { - CleanApkException( - searchResultSupreme.isTimeout(), - searchResultSupreme.message.ifBlank { DATA_LOAD_ERROR } - ) - } + val error = if (searchResultSupreme.isTimeout()) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + val exception = CustomException(error, searchResultSupreme.message.ifBlank { DATA_LOAD_ERROR }) handleException(exception) } @@ -196,7 +190,7 @@ class SearchViewModel @Inject constructor( val gplaySearchResult = applicationRepository.getGplaySearchResults(query, nextSubBundle) if (!gplaySearchResult.isSuccess()) { - handleException(gplaySearchResult.exception ?: UnknownSourceException()) + handleException(gplaySearchResult.exception ?: CustomException()) } nextSubBundle = gplaySearchResult.data?.second @@ -219,7 +213,7 @@ class SearchViewModel @Inject constructor( return currentAppList.distinctBy { it.package_name } } - private fun handleException(exception: Exception) { + private fun handleException(exception: CustomException) { exceptionsList.add(exception) exceptionsLiveData.postValue(exceptionsList) } diff --git a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt index 941ec2f11fc29976b39037ddbb4776ff03225040..f1629f5c887d138ae3890e485e8470a3ad8427cb 100644 --- a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt +++ b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesFragment.kt @@ -42,8 +42,7 @@ import foundation.e.apps.data.application.ApplicationInstaller import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.install.models.AppInstall import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.GPlayException -import foundation.e.apps.data.login.exceptions.GPlayLoginException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.databinding.FragmentUpdatesBinding import foundation.e.apps.di.CommonUtilsModule.safeNavigate import foundation.e.apps.install.download.data.DownloadProgress @@ -153,7 +152,14 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI Timber.d("===>> observeupdate list called") if (resultStatus != ResultStatus.OK) { - val exception = GPlayException(resultStatus == ResultStatus.TIMEOUT) + val error = if (resultStatus == ResultStatus.TIMEOUT) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + val exception = CustomException(error, "exception") + val alertDialogBuilder = AlertDialog.Builder(requireContext()) onTimeout(exception, alertDialogBuilder) } @@ -238,11 +244,11 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI } override fun onTimeout( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog.apply { - if (exception is GPlayException) { + if (exception.type == CustomException.Type.GOOGLE_PLAY) { setMessage(R.string.timeout_desc_gplay) setNegativeButton(R.string.open_settings) { _, _ -> openSettings() @@ -254,7 +260,7 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI } override fun onSignInError( - exception: GPlayLoginException, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog.apply { @@ -265,11 +271,11 @@ class UpdatesFragment : TimeoutFragment(R.layout.fragment_updates), ApplicationI } override fun onDataLoadError( - exception: Exception, + exception: CustomException, predefinedDialog: AlertDialog.Builder ): AlertDialog.Builder? { return predefinedDialog.apply { - if (exception is GPlayException) { + if (exception.type == CustomException.Type.GOOGLE_PLAY) { setNegativeButton(R.string.open_settings) { _, _ -> openSettings() } diff --git a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesViewModel.kt b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesViewModel.kt index 77214dc202ba5ba409265800f313295f2fe0b858..41f8d6871b255fca7385e838b1e7fc48732fc179 100644 --- a/app/src/main/java/foundation/e/apps/ui/updates/UpdatesViewModel.kt +++ b/app/src/main/java/foundation/e/apps/ui/updates/UpdatesViewModel.kt @@ -28,8 +28,7 @@ import foundation.e.apps.data.enums.Status import foundation.e.apps.data.application.ApplicationRepository import foundation.e.apps.data.application.data.Application import foundation.e.apps.data.login.AuthObject -import foundation.e.apps.data.login.exceptions.CleanApkException -import foundation.e.apps.data.login.exceptions.GPlayException +import foundation.e.apps.data.login.exceptions.CustomException import foundation.e.apps.data.preference.AppLoungePreference import foundation.e.apps.data.updates.UpdatesManagerRepository import foundation.e.apps.ui.parentFragment.LoadingViewModel @@ -73,18 +72,14 @@ class UpdatesViewModel @Inject constructor( val status = updatesResult.second if (status != ResultStatus.OK) { - val exception = - if (authData != null && - (authData.aasToken.isNotBlank() || authData.authToken.isNotBlank()) - ) { - GPlayException( - updatesResult.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) - } else CleanApkException( - updatesResult.second == ResultStatus.TIMEOUT, - status.message.ifBlank { "Data load error" } - ) + + val error = if (updatesResult.second == ResultStatus.TIMEOUT) { + CustomException.Error.TIMEOUT_ERROR + } else { + CustomException.Error.UNKNOWN_ERROR + } + + val exception = CustomException(error, status.message.ifBlank { "Data load error" }) exceptionsList.add(exception) exceptionsLiveData.postValue(exceptionsList)