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