From 19d08fa69271ae5dcc7ad4be21aeaecec5024b68 Mon Sep 17 00:00:00 2001 From: Julian Raufelder Date: Wed, 12 May 2021 11:34:41 +0200 Subject: [PATCH] User needs to always provide the endpoint in S3 cloud --- .../data/cloud/s3/S3ClientFactory.java | 16 +++---- .../presenter/S3AddOrChangePresenter.kt | 6 +-- .../ui/fragment/S3AddOrChangeFragment.kt | 38 ++++----------- .../src/main/res/layout/fragment_setup_s3.xml | 48 ++++++------------- presentation/src/main/res/values/strings.xml | 3 +- 5 files changed, 32 insertions(+), 79 deletions(-) diff --git a/data/src/main/java/org/cryptomator/data/cloud/s3/S3ClientFactory.java b/data/src/main/java/org/cryptomator/data/cloud/s3/S3ClientFactory.java index 4765af68..e46659a3 100644 --- a/data/src/main/java/org/cryptomator/data/cloud/s3/S3ClientFactory.java +++ b/data/src/main/java/org/cryptomator/data/cloud/s3/S3ClientFactory.java @@ -45,15 +45,8 @@ class S3ClientFactory { MinioClient.Builder minioClientBuilder = MinioClient.builder(); - if (cloud.s3Endpoint() != null) { - minioClientBuilder.endpoint(cloud.s3Endpoint()); - } else { - minioClientBuilder.endpoint("https://s3.amazonaws.com"); - } - - if (cloud.s3Region() != null) { - minioClientBuilder.region(cloud.s3Region()); - } + minioClientBuilder.endpoint(cloud.s3Endpoint()); + minioClientBuilder.region(cloud.s3Region()); OkHttpClient.Builder httpClientBuilder = new OkHttpClient() // .newBuilder() // @@ -67,7 +60,10 @@ class S3ClientFactory { httpClientBuilder.cache(cache).addInterceptor(provideOfflineCacheInterceptor(context)); } - return minioClientBuilder.credentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)).httpClient(httpClientBuilder.build()).build(); + return minioClientBuilder // + .credentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)) // + .httpClient(httpClientBuilder.build()) // + .build(); } private static Interceptor provideOfflineCacheInterceptor(final Context context) { diff --git a/presentation/src/main/java/org/cryptomator/presentation/presenter/S3AddOrChangePresenter.kt b/presentation/src/main/java/org/cryptomator/presentation/presenter/S3AddOrChangePresenter.kt index fc94ce3f..e066851d 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/presenter/S3AddOrChangePresenter.kt +++ b/presentation/src/main/java/org/cryptomator/presentation/presenter/S3AddOrChangePresenter.kt @@ -35,14 +35,10 @@ class S3AddOrChangePresenter @Inject internal constructor( // if (displayName.isEmpty()) { statusMessage = getString(R.string.screen_s3_settings_msg_display_name_not_empty) } - if (endpoint.isNullOrEmpty() && region.isNullOrEmpty()) { + if (endpoint.isNullOrEmpty() || region.isNullOrEmpty()) { statusMessage = getString(R.string.screen_s3_settings_msg_endpoint_and_region_not_empty) } - if (!endpoint.isNullOrEmpty() && region.isNullOrEmpty()) { - statusMessage = getString(R.string.screen_s3_settings_msg_endpoint_set_and_region_empty) - } - if (statusMessage != null) { Toast.makeText(context(), statusMessage, Toast.LENGTH_SHORT).show() } else { diff --git a/presentation/src/main/java/org/cryptomator/presentation/ui/fragment/S3AddOrChangeFragment.kt b/presentation/src/main/java/org/cryptomator/presentation/ui/fragment/S3AddOrChangeFragment.kt index 8438ce78..8805a072 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/ui/fragment/S3AddOrChangeFragment.kt +++ b/presentation/src/main/java/org/cryptomator/presentation/ui/fragment/S3AddOrChangeFragment.kt @@ -1,9 +1,7 @@ package org.cryptomator.presentation.ui.fragment import android.os.Bundle -import android.view.View import android.view.inputmethod.EditorInfo -import com.google.android.material.switchmaterial.SwitchMaterial import org.cryptomator.generator.Fragment import org.cryptomator.presentation.R import org.cryptomator.presentation.model.S3CloudModel @@ -15,10 +13,8 @@ import kotlinx.android.synthetic.main.fragment_setup_s3.bucketEditText import kotlinx.android.synthetic.main.fragment_setup_s3.createCloudButton import kotlinx.android.synthetic.main.fragment_setup_s3.displayNameEditText import kotlinx.android.synthetic.main.fragment_setup_s3.endpointEditText -import kotlinx.android.synthetic.main.fragment_setup_s3.ll_custom_s3 import kotlinx.android.synthetic.main.fragment_setup_s3.regionEditText import kotlinx.android.synthetic.main.fragment_setup_s3.secretKeyEditText -import kotlinx.android.synthetic.main.fragment_setup_s3.toggleCustomS3 import timber.log.Timber @Fragment(R.layout.fragment_setup_s3) @@ -42,16 +38,6 @@ class S3AddOrChangeFragment : BaseFragment() { } showEditableCloudContent(s3CloudModel) - - toggleCustomS3.setOnClickListener { switch -> - toggleUseAmazonS3((switch as SwitchMaterial).isChecked) - } - } - - private fun toggleUseAmazonS3(checked: Boolean) = if (checked) { - ll_custom_s3.visibility = View.GONE - } else { - ll_custom_s3.visibility = View.VISIBLE } private fun showEditableCloudContent(s3CloudModel: S3CloudModel?) { @@ -61,17 +47,8 @@ class S3AddOrChangeFragment : BaseFragment() { accessKeyEditText.setText(decrypt(s3CloudModel.accessKey())) secretKeyEditText.setText(decrypt(s3CloudModel.secretKey())) bucketEditText.setText(s3CloudModel.s3Bucket()) - + endpointEditText.setText(s3CloudModel.s3Endpoint()) regionEditText.setText(s3CloudModel.s3Region()) - - if (it.s3Endpoint().isNotEmpty()) { - toggleCustomS3.isChecked = false - ll_custom_s3.visibility = View.VISIBLE - endpointEditText.setText(s3CloudModel.s3Endpoint()) - } else { - toggleCustomS3.isChecked = false - ll_custom_s3.visibility = View.VISIBLE - } } } @@ -94,11 +71,14 @@ class S3AddOrChangeFragment : BaseFragment() { val bucket = bucketEditText.text.toString().trim() val displayName = displayNameEditText.text.toString().trim() - if (toggleCustomS3.isChecked) { - s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, null, regionEditText.text.toString().trim(), cloudId, displayName) - } else { - s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, endpointEditText.text.toString().trim(), regionEditText.text.toString().trim(), cloudId, displayName) - } + s3AddOrChangePresenter.checkUserInput( // + accessKey, // + secretKey, // + bucket, // + endpointEditText.text.toString().trim(), // + regionEditText.text.toString().trim(), // + cloudId, // + displayName) } fun hideKeyboard() { diff --git a/presentation/src/main/res/layout/fragment_setup_s3.xml b/presentation/src/main/res/layout/fragment_setup_s3.xml index 15e6c1f2..9fd9cc1d 100644 --- a/presentation/src/main/res/layout/fragment_setup_s3.xml +++ b/presentation/src/main/res/layout/fragment_setup_s3.xml @@ -78,6 +78,21 @@ + + + + + + @@ -93,39 +108,6 @@ - - - - - - - - - - - -