Use endpoint or region in S3
This commit is contained in:
parent
ac46aa6a57
commit
862596114b
@ -23,16 +23,21 @@ class S3ClientFactory {
|
||||
}
|
||||
|
||||
private AmazonS3 createApiClient(S3Cloud cloud, Context context) {
|
||||
Region region = Region.getRegion(cloud.s3Region());
|
||||
Region region = Region.getRegion(Regions.DEFAULT_REGION);
|
||||
String endpoint = null;
|
||||
|
||||
if (region == null) {
|
||||
region = Region.getRegion(Regions.DEFAULT_REGION);
|
||||
if (cloud.s3Region() != null) {
|
||||
region = Region.getRegion(cloud.s3Region());
|
||||
} else if (cloud.s3Endpoint() != null) {
|
||||
endpoint = cloud.s3Endpoint();
|
||||
}
|
||||
|
||||
AmazonS3Client client = new AmazonS3Client(new BasicAWSCredentials(decrypt(cloud.accessKey(), context), decrypt(cloud.secretKey(), context)), region);
|
||||
if (cloud.s3Endpoint() != null) {
|
||||
|
||||
if (endpoint != null) {
|
||||
client.setEndpoint(cloud.s3Endpoint());
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.cryptomator.presentation.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial
|
||||
import org.cryptomator.generator.Fragment
|
||||
import org.cryptomator.presentation.R
|
||||
@ -15,9 +13,8 @@ import kotlinx.android.synthetic.main.fragment_setup_s3.accessKeyEditText
|
||||
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.regionOrEndpointEditText
|
||||
import kotlinx.android.synthetic.main.fragment_setup_s3.regionOrEndpointEditTextLayout
|
||||
import kotlinx.android.synthetic.main.fragment_setup_s3.secretKeyEditText
|
||||
import kotlinx.android.synthetic.main.fragment_setup_s3.toggleCustomS3
|
||||
import timber.log.Timber
|
||||
@ -42,24 +39,17 @@ class S3AddOrChangeFragment : BaseFragment() {
|
||||
false
|
||||
}
|
||||
|
||||
s3CloudModel?.let {
|
||||
if(it.s3Endpoint().isNotEmpty()) {
|
||||
toggleCustomS3.isChecked = false
|
||||
ll_custom_s3.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
showEditableCloudContent(s3CloudModel)
|
||||
|
||||
toggleCustomS3.setOnClickListener { switch ->
|
||||
toggleCustomS3Changed((switch as SwitchMaterial).isChecked)
|
||||
toggleUseAmazonS3((switch as SwitchMaterial).isChecked)
|
||||
}
|
||||
|
||||
showEditableCloudContent(s3CloudModel)
|
||||
}
|
||||
|
||||
private fun toggleCustomS3Changed(checked: Boolean) = if(checked) {
|
||||
ll_custom_s3.visibility = View.GONE
|
||||
private fun toggleUseAmazonS3(checked: Boolean) = if (checked) {
|
||||
regionOrEndpointEditTextLayout.setHint(R.string.screen_s3_settings_region_label)
|
||||
} else {
|
||||
ll_custom_s3.visibility = View.VISIBLE
|
||||
regionOrEndpointEditTextLayout.setHint(R.string.screen_s3_settings_endpoint_label)
|
||||
}
|
||||
|
||||
private fun showEditableCloudContent(s3CloudModel: S3CloudModel?) {
|
||||
@ -69,9 +59,16 @@ 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
|
||||
regionOrEndpointEditText.setText(s3CloudModel.s3Endpoint())
|
||||
regionOrEndpointEditTextLayout.setHint(R.string.screen_s3_settings_endpoint_label)
|
||||
} else {
|
||||
regionOrEndpointEditText.setText(s3CloudModel.s3Region())
|
||||
regionOrEndpointEditTextLayout.setHint(R.string.screen_s3_settings_region_label)
|
||||
}
|
||||
} ?: regionOrEndpointEditTextLayout.setHint(R.string.screen_s3_settings_region_label)
|
||||
}
|
||||
|
||||
private fun decrypt(text: String?): String {
|
||||
@ -93,14 +90,11 @@ class S3AddOrChangeFragment : BaseFragment() {
|
||||
val bucket = bucketEditText.text.toString().trim()
|
||||
val displayName = displayNameEditText.text.toString().trim()
|
||||
|
||||
var endpoint: String? = null
|
||||
var region: String? = null
|
||||
if(ll_custom_s3.isVisible) {
|
||||
endpoint = endpointEditText.text.toString().trim()
|
||||
region = regionEditText.text.toString().trim()
|
||||
if (toggleCustomS3.isChecked) {
|
||||
s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, null, regionOrEndpointEditText.text.toString().trim(), cloudId, displayName)
|
||||
} else {
|
||||
s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, regionOrEndpointEditText.text.toString().trim(), null, cloudId, displayName)
|
||||
}
|
||||
|
||||
s3AddOrChangePresenter.checkUserInput(accessKey, secretKey, bucket, endpoint, region, cloudId, displayName)
|
||||
}
|
||||
|
||||
fun hideKeyboard() {
|
||||
|
@ -79,14 +79,14 @@
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/regionOrEndpointEditTextLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/regionEditText"
|
||||
android:id="@+id/regionOrEndpointEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/screen_s3_settings_region_label"
|
||||
android:imeOptions="flagNoPersonalizedLearning"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true" />
|
||||
@ -101,31 +101,6 @@
|
||||
android:checked="true"
|
||||
android:text="@string/screen_s3_settings_amazon_s3_text" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/ll_custom_s3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/endpointEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/screen_s3_settings_endpoint_label"
|
||||
android:imeOptions="flagNoPersonalizedLearning"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:id="@+id/createCloudButton"
|
||||
style="?android:textAppearanceSmall"
|
||||
|
@ -178,7 +178,7 @@
|
||||
<string name="screen_s3_settings_display_name_label">Display Name</string>
|
||||
<string name="screen_s3_settings_access_key_label">Access Key</string>
|
||||
<string name="screen_s3_settings_secret_key_label">Secret Key</string>
|
||||
<string name="screen_s3_settings_bucket_label">Bucket</string>
|
||||
<string name="screen_s3_settings_bucket_label">Existing Bucket</string>
|
||||
<string name="screen_s3_settings_endpoint_label">Endpoint</string>
|
||||
<string name="screen_s3_settings_region_label">Region</string>
|
||||
<string name="screen_s3_settings_amazon_s3_text" translatable="false">Amazon S3</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user