From 5b7609241df270fc9775bbb3d39acc97d04e913d Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 22 Jun 2023 20:08:08 +0530 Subject: [PATCH 1/2] prevent calling source.getAuthObject() two times --- .../e/apps/data/login/LoginSourceRepository.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt b/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt index 6cbf99998..cb0cf14dd 100644 --- a/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt +++ b/app/src/main/java/foundation/e/apps/data/login/LoginSourceRepository.kt @@ -40,10 +40,13 @@ class LoginSourceRepository @Inject constructor( if (source::class.java.simpleName in clearAuthTypes) { source.clearSavedAuth() } - if (source is LoginSourceGPlay) { - gplayAuth = source.getAuthObject().result.data + + source.getAuthObject().run { + if (source is LoginSourceGPlay) { + gplayAuth = this.result.data as AuthData? + } + authObjectsLocal.add(this) } - authObjectsLocal.add(source.getAuthObject()) } return authObjectsLocal -- GitLab From 6bfbd26e9f8951627eb1b7338116db3ba5c26ce3 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Thu, 22 Jun 2023 20:09:17 +0530 Subject: [PATCH 2/2] rewrite validateAuthData() to use getAuthObject() --- .../e/apps/data/login/LoginSourceGPlay.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/data/login/LoginSourceGPlay.kt b/app/src/main/java/foundation/e/apps/data/login/LoginSourceGPlay.kt index d5cf5e45b..9a8f06a76 100644 --- a/app/src/main/java/foundation/e/apps/data/login/LoginSourceGPlay.kt +++ b/app/src/main/java/foundation/e/apps/data/login/LoginSourceGPlay.kt @@ -213,18 +213,18 @@ class LoginSourceGPlay @Inject constructor( } override suspend fun validateAuthData(): ResultSupreme { - val savedAuth = getSavedAuthData() - if (!isAuthDataValid(savedAuth)) { - Timber.i("Validating AuthData...") - val authData = generateAuthData() - authData.data?.let { - saveAuthData(it) - return authData - } - return ResultSupreme.create(ResultStatus.UNKNOWN) + val authObject = getAuthObject() + val authData = authObject.result.data + + Timber.i("Validating AuthData...") + if (isAuthDataValid(authData)) { + return ResultSupreme.Success(authData) } - return ResultSupreme.create(ResultStatus.OK, savedAuth) + clearSavedAuth() + + val newAuthObjectResult = getAuthObject().result + return ResultSupreme.replicate(newAuthObjectResult, newAuthObjectResult.data) } private suspend fun isAuthDataValid(savedAuth: AuthData?) = -- GitLab