From 4fd187e697bfb8616732b3230518877e13beab9f Mon Sep 17 00:00:00 2001 From: Manuel Jenny Date: Tue, 16 Mar 2021 15:07:00 +0100 Subject: [PATCH] chore: simplify check if account was already registered --- .../presenter/CloudConnectionListPresenter.kt | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/presentation/src/main/java/org/cryptomator/presentation/presenter/CloudConnectionListPresenter.kt b/presentation/src/main/java/org/cryptomator/presentation/presenter/CloudConnectionListPresenter.kt index da62bc5c..96799a22 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/presenter/CloudConnectionListPresenter.kt +++ b/presentation/src/main/java/org/cryptomator/presentation/presenter/CloudConnectionListPresenter.kt @@ -204,9 +204,6 @@ class CloudConnectionListPresenter @Inject constructor( // prepareForSavingPCloudCloud(PCloudCloud.aCopyOf(pCloudSkeleton).withUsername(username).build()) } }) - - Log.d("pCloud", "Account access granted, authData:\n$authData") - } AuthorizationResult.ACCESS_DENIED -> //TODO: Add proper handling for denied grants. Log.d("pCloud", "Account access denied") @@ -226,20 +223,14 @@ class CloudConnectionListPresenter @Inject constructor( // .withCloudType(CloudTypeModel.valueOf(selectedCloudType.get())) // .run(object : DefaultResultHandler>() { override fun onSuccess(clouds: List) { - // here check if a cloud with the same mail adress already exists, - // if so update (in case of the token changed) else create a new one - val existingPCloudCloud: PCloudCloud? = clouds.firstOrNull { + clouds.firstOrNull { (it as PCloudCloud).username() == cloud.username() - } as PCloudCloud? - - if (existingPCloudCloud != null && existingPCloudCloud.accessToken() != cloud.accessToken()) { - saveCloud(PCloudCloud.aCopyOf(existingPCloudCloud) // + }?.let { it as PCloudCloud + saveCloud(PCloudCloud.aCopyOf(it) // .withUrl(cloud.url()) - .withAccessToken(cloud.accessToken()) + .withAccessToken(it.accessToken()) .build()) - } else if (existingPCloudCloud == null) { - saveCloud(cloud); - } + } ?: saveCloud(cloud) } }) }