chore: simplify check if account was already registered
This commit is contained in:
parent
bd2bfa9724
commit
4fd187e697
@ -204,9 +204,6 @@ class CloudConnectionListPresenter @Inject constructor( //
|
|||||||
prepareForSavingPCloudCloud(PCloudCloud.aCopyOf(pCloudSkeleton).withUsername(username).build())
|
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.
|
AuthorizationResult.ACCESS_DENIED -> //TODO: Add proper handling for denied grants.
|
||||||
Log.d("pCloud", "Account access denied")
|
Log.d("pCloud", "Account access denied")
|
||||||
@ -226,20 +223,14 @@ class CloudConnectionListPresenter @Inject constructor( //
|
|||||||
.withCloudType(CloudTypeModel.valueOf(selectedCloudType.get())) //
|
.withCloudType(CloudTypeModel.valueOf(selectedCloudType.get())) //
|
||||||
.run(object : DefaultResultHandler<List<Cloud>>() {
|
.run(object : DefaultResultHandler<List<Cloud>>() {
|
||||||
override fun onSuccess(clouds: List<Cloud>) {
|
override fun onSuccess(clouds: List<Cloud>) {
|
||||||
// here check if a cloud with the same mail adress already exists,
|
clouds.firstOrNull {
|
||||||
// if so update (in case of the token changed) else create a new one
|
|
||||||
val existingPCloudCloud: PCloudCloud? = clouds.firstOrNull {
|
|
||||||
(it as PCloudCloud).username() == cloud.username()
|
(it as PCloudCloud).username() == cloud.username()
|
||||||
} as PCloudCloud?
|
}?.let { it as PCloudCloud
|
||||||
|
saveCloud(PCloudCloud.aCopyOf(it) //
|
||||||
if (existingPCloudCloud != null && existingPCloudCloud.accessToken() != cloud.accessToken()) {
|
|
||||||
saveCloud(PCloudCloud.aCopyOf(existingPCloudCloud) //
|
|
||||||
.withUrl(cloud.url())
|
.withUrl(cloud.url())
|
||||||
.withAccessToken(cloud.accessToken())
|
.withAccessToken(it.accessToken())
|
||||||
.build())
|
.build())
|
||||||
} else if (existingPCloudCloud == null) {
|
} ?: saveCloud(cloud)
|
||||||
saveCloud(cloud);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user